use anyhow::Result;
use async_openai::types::{ChatCompletionTool, ChatCompletionToolType, FunctionObject};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<()> {
println!("Parallel Tool Calls Demo");
println!("========================");
let _tool1 = ChatCompletionTool {
r#type: ChatCompletionToolType::Function,
function: FunctionObject {
name: "get_weather".to_string(),
description: Some("Get weather for a location".to_string()),
parameters: Some(json!({
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state"
}
},
"required": ["location"]
})),
strict: None
}
};
let _tool2 = ChatCompletionTool {
r#type: ChatCompletionToolType::Function,
function: FunctionObject {
name: "get_time".to_string(),
description: Some("Get current time for a timezone".to_string()),
parameters: Some(json!({
"type": "object",
"properties": {
"timezone": {
"type": "string",
"description": "The timezone"
}
},
"required": ["timezone"]
})),
strict: None
}
};
println!("Created tools:");
println!("- get_weather: Get weather for a location");
println!("- get_time: Get current time for a timezone");
println!();
println!("In the actual implementation:");
println!("1. When OpenAI returns multiple tool calls in response.choices[0].message.tool_calls");
println!("2. We create a future for each tool call");
println!("3. We execute all futures in parallel using futures::future::join_all");
println!("4. We collect and process all results");
println!();
println!("This allows for efficient parallel processing of multiple tool calls!");
Ok(())
}