use llm::{
builder::{FunctionBuilder, LLMBackend, LLMBuilder, ParamBuilder},
chat::ChatMessage, };
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("OPENAI_API_KEY").unwrap_or("sk-TESTKEY".into());
let llm = LLMBuilder::new()
.backend(LLMBackend::OpenAI) .api_key(api_key) .model("gpt-3.5-turbo") .max_tokens(512) .temperature(0.7) .function(
FunctionBuilder::new("weather_function")
.description("Use this tool to get the weather in a specific city")
.param(
ParamBuilder::new("url")
.type_of("string")
.description("The url to get the weather from for the city"),
)
.required(vec!["url".to_string()]),
)
.build()
.expect("Failed to build LLM");
let messages = vec![ChatMessage::user().content("You are a weather assistant. What is the weather in Tokyo? Use the tools that you have available").build()];
match llm.chat_with_tools(&messages, llm.tools()).await {
Ok(text) => println!("Chat response:\n{text}"),
Err(e) => eprintln!("Chat error: {e}"),
}
Ok(())
}