use ai_lib::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("đ AI-lib Quickstart Example");
println!("============================");
println!("\nđ Simplest usage:");
let _client = AiClient::new(Provider::Groq)?;
println!("â
Client created successfully!");
println!("\nđ Custom configuration:");
let client = AiClientBuilder::new(Provider::Groq)
.with_base_url("https://custom.groq.com") .with_proxy(Some("http://proxy.example.com:8080")) .build()?;
println!("â
Custom client created successfully!");
println!("\nđ Create chat request:");
let _request = ChatCompletionRequest::new(
"llama3-8b-8192".to_string(), vec![Message {
role: Role::User,
content: Content::new_text("Hello! How are you?"),
function_call: None,
}],
);
println!("â
Request created successfully!");
println!("\nđ Send request:");
println!(" Note: Set GROQ_API_KEY environment variable for actual API calls");
println!(" Usage: export GROQ_API_KEY=your_api_key_here");
match std::env::var("GROQ_API_KEY") {
Ok(_) => {
println!("â
GROQ_API_KEY detected, ready to send actual requests");
}
Err(_) => {
println!("âšī¸ GROQ_API_KEY not set, skipping actual request");
println!(" This is a demo showing how to build requests");
}
}
println!("\nđ More customization options:");
let _advanced_client = AiClientBuilder::new(Provider::Groq)
.with_timeout(std::time::Duration::from_secs(60)) .with_pool_config(16, std::time::Duration::from_secs(60)) .build()?;
println!("â
Advanced configuration client created successfully!");
println!("\nđ Switch to other providers:");
let _deepseek_client = AiClient::new(Provider::DeepSeek)?;
println!("â
DeepSeek client created successfully!");
let _ollama_client = AiClient::new(Provider::Ollama)?;
println!("â
Ollama client created successfully!");
println!("\nđ Quickstart completed!");
println!("\nđĄ Key points:");
println!(" 1. AiClient::new() - Simplest usage with automatic environment detection");
println!(" 2. AiClientBuilder - Builder pattern with custom configuration support");
println!(
" 3. Environment variable priority: Explicit setting > Environment variable > Default"
);
println!(" 4. Support for all mainstream AI providers");
println!(" 5. Backward compatible, existing code requires no changes");
Ok(())
}