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("AZURE_OPENAI_API_KEY").unwrap_or("".into());
let api_version =
std::env::var("AZURE_OPENAI_API_VERSION").unwrap_or("2025-01-01-preview".into());
let endpoint = std::env::var("AZURE_OPENAI_API_ENDPOINT").unwrap_or("".into());
let llm = LLMBuilder::new()
.backend(LLMBackend::AzureOpenAI) .base_url(endpoint)
.api_key(api_key) .api_version(api_version) .deployment_id("gpt-4o-mini")
.model("gpt-4o-mini") .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(())
}