fixxxeeess
This commit is contained in:
parent
643203b8a5
commit
c4d9ca19ce
8 changed files with 142 additions and 54 deletions
19
src/tools.rs
19
src/tools.rs
|
|
@ -44,7 +44,6 @@ pub async fn handle_tool_call(
|
|||
tool_call: &ToolCall,
|
||||
tavily_api_key: &Option<String>,
|
||||
) -> Result<(Message, bool, Option<String>), Box<dyn std::error::Error>> {
|
||||
let mut file_written = false;
|
||||
let mut answer = None;
|
||||
let name = &tool_call.function.name;
|
||||
|
||||
|
|
@ -66,30 +65,14 @@ pub async fn handle_tool_call(
|
|||
"Error: TAVILY_API_KEY is not set. Cannot perform real search.".to_string()
|
||||
};
|
||||
(search_result, false)
|
||||
} else if name == "write_file" {
|
||||
let args: HashMap<String, String> = serde_json::from_str(&tool_call.function.arguments)?;
|
||||
let path = args.get("path").ok_or("Missing path argument")?;
|
||||
let content = args.get("content").ok_or("Missing content argument")?;
|
||||
|
||||
println!("--- Executing tool: write_file(path: \"{}\") ---", path);
|
||||
|
||||
let write_result = match std::fs::write(path, content) {
|
||||
Ok(_) => {
|
||||
file_written = true;
|
||||
format!("Successfully wrote content to {}", path)
|
||||
}
|
||||
Err(e) => format!("Error writing to {}: {}", path, e),
|
||||
};
|
||||
(write_result, file_written)
|
||||
} else if name == "finish" {
|
||||
let args: HashMap<String, String> = serde_json::from_str(&tool_call.function.arguments)?;
|
||||
let result = args.get("result").ok_or("Missing result argument")?;
|
||||
|
||||
println!("--- Finishing task: {}", result);
|
||||
|
||||
file_written = true;
|
||||
answer = Some(result.clone());
|
||||
(result.clone(), file_written)
|
||||
(result.clone(), true)
|
||||
} else {
|
||||
(format!("Error: Unknown tool {}", name), false)
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue