improved error handling

introduced toml config
This commit is contained in:
milan
2026-04-06 13:24:37 +01:00
parent 6bfadfeba7
commit 2dbac8a91a
7 changed files with 352 additions and 92 deletions
+36 -65
View File
@@ -1,76 +1,46 @@
pub mod mcp;
mod config;
mod model;
use std::collections::HashMap;
use chrono::Datelike;
use ollama_rs::Ollama;
use ollama_rs::generation::chat::ChatMessage;
use ollama_rs::generation::chat::request::ChatMessageRequest;
use rmcp::model::{Implementation, InitializedNotificationMethod};
/// Get the current local datetime as an iso string
///
/// # Arguments
///
/// returns: Result<String, Box<dyn Error+Sync+Send, Global>>
///
/// # Examples
///
/// ```
///
/// ```
#[ollama_rs::function]
async fn get_current_iso_datetime() -> Result<String, Box<dyn std::error::Error + Sync + Send>> {
use chrono::prelude::*;
let datetime_iso = Local::now().format("%+").to_string();
println!("iso time requested: {datetime_iso}");
Ok(datetime_iso)
}
/// Get the current weekday as a string in english
///
/// # Arguments
///
/// returns: Result<String, Box<dyn Error+Sync+Send, Global>>
#[ollama_rs::function]
async fn get_current_weekday() -> Result<String, Box<dyn std::error::Error + Sync + Send>> {
let weekday = chrono::offset::Local::now().weekday().to_string();
println!("Weekday requested: {weekday}");
Ok(weekday)
}
/// creates a new task to be completed at given timestamp
///
/// # Arguments
///
/// * `name`: a short name of the task
/// * `description`: optional description, keep empty if not needed
/// * `iso_datetime`: must be in ISO 8601, specifies when user should be reminded of task. choose 15:00 if time not specified
///
/// returns: Empty String
///
/// # Examples
///
/// ```
/// create_task("Müll rausbringen".to_string(), None, "2026-11-08T16:23:47.947244200+02:00")
/// ```
#[ollama_rs::function]
async fn create_task(
name: String,
description: Option<String>,
iso_datetime: String,
) -> Result<String, Box<dyn std::error::Error + Sync + Send>> {
println!("lol, {name}, {description:?}, {iso_datetime}");
Ok(String::new())
}
use reqwest::header::{HeaderMap, HeaderValue};
use rmcp::model::{Implementation};
use url::Url;
use crate::config::Config;
use crate::mcp::chat::MCPServerData;
use crate::mcp::guaranteed_mcp_server_name;
use crate::model::create_model_from_config;
#[tokio::main]
async fn main() {
env_logger::init();
let config = Config::from_file().await.inspect_err(|e|{
log::error!("error loading assist.toml {}", e);
std::process::exit(1);
}).unwrap();
let ollama = config.ollama_instance();
let mcp_clients = config.mcp_clients().await;
let model_name = &config.ollama_config().model.name;
create_model_from_config(&ollama, &config.ollama_config().model).await.inspect_err(|e|{
log::error!("failed creating ollama model {model_name}: {e}")
}).unwrap();
let mut agent_chat = mcp::chat::AgentChat::new(ollama, model_name.clone(), mcp_clients).await.inspect_err(
|e| {
log::error!("error creating agent: {}", e);
}
);
log::debug!("chat: {:#?}", agent_chat);
/*
let ollama = Ollama::default();
let fetch_client = mcp::get_client(
@@ -83,9 +53,10 @@ async fn main() {
("fetch".to_string(), fetch_client),
]);
let mut agent_chat = mcp::chat::AgentChat::new(ollama, mcp_clients).await.unwrap();
let mut agent_chat = mcp::chat::AgentChat::new(ollama, "ollama:e2b".to_string(), mcp_clients).await.unwrap();
log::debug!("chat: {:#?}", agent_chat);
agent_chat.message(String::from("Was ist auf der Website https://uno.mboemer.com zu finden?")).await.unwrap();
*/
/*let ollama = Ollama::default();
let mut history = vec![