initial commit

This commit is contained in:
milan
2026-04-03 22:09:40 +02:00
commit 6bfadfeba7
11 changed files with 3372 additions and 0 deletions
+105
View File
@@ -0,0 +1,105 @@
pub mod mcp;
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())
}
#[tokio::main]
async fn main() {
env_logger::init();
let ollama = Ollama::default();
let fetch_client = mcp::get_client(
"https://remote.mcpservers.org/fetch/mcp",
None::<String>,
Implementation::new("OwnAssist", "0.0.1"),
).await.unwrap();
let mcp_clients = HashMap::from([
("fetch".to_string(), fetch_client),
]);
let mut agent_chat = mcp::chat::AgentChat::new(ollama, 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![
ChatMessage::system("Du bist ein Assistent, der per Sprache bedient wird. Du erhälst die Transkription. \
Wichtiger als deine Antworten sind deine Aktionen.\
Nutze bitte die tools, falls du sie brauchst um Informationen zu bekommen (z.B: über das aktuelle Datum oder den aktuellen Wochentag).".to_string())
];
let user_message = vec![
ChatMessage::user("Welche Funktionen stehen dir zur Verfügung?".to_string()),
];
let response = ollama.send_chat_messages_with_history(&mut history, ChatMessageRequest::new("gemma4:e2b".to_string(), user_message).tools(vec![])).await.unwrap();
log::info!("response: {response:?}");
log::debug!("history: {history:?}");*/
}