parent
d3cdcea0df
commit
9aca4cadf0
13 changed files with 483 additions and 21 deletions
|
|
@ -3,6 +3,7 @@ use sea_orm::{
|
|||
ColumnTrait, Condition, DatabaseConnection, EntityTrait, QueryFilter, QueryOrder, QuerySelect,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
@ -96,6 +97,47 @@ pub fn get_tools() -> Vec<Tool> {
|
|||
}),
|
||||
},
|
||||
},
|
||||
Tool {
|
||||
tool_type: "function".to_string(),
|
||||
function: FunctionDefinition {
|
||||
name: "calendar_list_events".to_string(),
|
||||
description: "List calendar events".to_string(),
|
||||
parameters: serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"upcoming": {
|
||||
"type": "boolean",
|
||||
"description": "If true, only upcoming events will be listed"
|
||||
}
|
||||
}
|
||||
}),
|
||||
},
|
||||
},
|
||||
Tool {
|
||||
tool_type: "function".to_string(),
|
||||
function: FunctionDefinition {
|
||||
name: "calendar_create_event".to_string(),
|
||||
description: "Create a new calendar event".to_string(),
|
||||
parameters: serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "Name of the event"
|
||||
},
|
||||
"from": {
|
||||
"type": "string",
|
||||
"description": "Start time in ISO 8601 format (e.g., 2023-10-27T10:00:00Z)"
|
||||
},
|
||||
"to": {
|
||||
"type": "string",
|
||||
"description": "End time in ISO 8601 format (e.g., 2023-10-27T11:00:00Z)"
|
||||
}
|
||||
},
|
||||
"required": ["name", "from", "to"]
|
||||
}),
|
||||
},
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -103,6 +145,8 @@ pub async fn handle_tool_call(
|
|||
tool_call: &ToolCall,
|
||||
tavily_api_key: &Option<String>,
|
||||
db: &DatabaseConnection,
|
||||
calendar: &Arc<crate::domain::calendar::CalendarClient>,
|
||||
user_sub: Option<&str>,
|
||||
) -> Result<(Message, bool, Option<String>), Box<dyn std::error::Error>> {
|
||||
let mut answer = None;
|
||||
let name = &tool_call.function.name;
|
||||
|
|
@ -198,6 +242,34 @@ pub async fn handle_tool_call(
|
|||
));
|
||||
}
|
||||
(out, false)
|
||||
} else if name == "calendar_list_events" {
|
||||
let args: serde_json::Value = serde_json::from_str(&tool_call.function.arguments)?;
|
||||
let upcoming = args["upcoming"].as_bool();
|
||||
match calendar
|
||||
.list_events(user_sub.map(|s| s.to_string()), upcoming)
|
||||
.await
|
||||
{
|
||||
Ok(events) => {
|
||||
tracing::info!("{:#?}", events);
|
||||
(serde_json::to_string(&events)?, false)
|
||||
}
|
||||
Err(e) => (format!("Error listing events: {}", e), false),
|
||||
}
|
||||
} else if name == "calendar_create_event" {
|
||||
let args: serde_json::Value = serde_json::from_str(&tool_call.function.arguments)?;
|
||||
let name_val = args["name"].as_str().unwrap_or_default();
|
||||
let from_val = args["from"].as_str().unwrap_or_default();
|
||||
let to_val = args["to"].as_str().unwrap_or_default();
|
||||
match calendar
|
||||
.create_event(user_sub.map(|s| s.to_string()), name_val, from_val, to_val)
|
||||
.await
|
||||
{
|
||||
Ok(event) => (
|
||||
format!("Event created: {}", serde_json::to_string(&event)?),
|
||||
false,
|
||||
),
|
||||
Err(e) => (format!("Error creating event: {}", e), false),
|
||||
}
|
||||
} else {
|
||||
(format!("Error: Unknown tool {}", name), false)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue