1use ai_lib::types::common::Content;
3use ai_lib::{AiClient, AiClientBuilder, ChatCompletionRequest, Message, Provider, Role};
4
5#[tokio::main]
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 println!("🚀 AI-lib Quickstart Example");
8 println!("============================");
9
10 println!("\n📋 Simplest usage:");
12 let client = AiClient::new(Provider::Groq)?;
13 println!("✅ Client created successfully!");
14
15 println!("\n📋 Custom configuration:");
17 let client = AiClientBuilder::new(Provider::Groq)
18 .with_base_url("https://custom.groq.com") .with_proxy(Some("http://proxy.example.com:8080")) .build()?;
21 println!("✅ Custom client created successfully!");
22
23 println!("\n📋 Create chat request:");
25 let request = ChatCompletionRequest::new(
26 "llama3-8b-8192".to_string(), vec![Message {
28 role: Role::User,
29 content: Content::Text("Hello! How are you?".to_string()),
30 function_call: None,
31 }],
32 );
33 println!("✅ Request created successfully!");
34
35 println!("\n📋 Send request:");
37 println!(" Note: Set GROQ_API_KEY environment variable for actual API calls");
38 println!(" Usage: export GROQ_API_KEY=your_api_key_here");
39
40 match std::env::var("GROQ_API_KEY") {
42 Ok(_) => {
43 println!("✅ GROQ_API_KEY detected, ready to send actual requests");
44 }
48 Err(_) => {
49 println!("ℹ️ GROQ_API_KEY not set, skipping actual request");
50 println!(" This is a demo showing how to build requests");
51 }
52 }
53
54 println!("\n📋 More customization options:");
56 let advanced_client = AiClientBuilder::new(Provider::Groq)
57 .with_timeout(std::time::Duration::from_secs(60)) .with_pool_config(16, std::time::Duration::from_secs(60)) .build()?;
60 println!("✅ Advanced configuration client created successfully!");
61
62 println!("\n📋 Switch to other providers:");
64 let deepseek_client = AiClient::new(Provider::DeepSeek)?;
65 println!("✅ DeepSeek client created successfully!");
66
67 let ollama_client = AiClient::new(Provider::Ollama)?;
68 println!("✅ Ollama client created successfully!");
69
70 println!("\n🎉 Quickstart completed!");
71 println!("\n💡 Key points:");
72 println!(" 1. AiClient::new() - Simplest usage with automatic environment detection");
73 println!(" 2. AiClientBuilder - Builder pattern with custom configuration support");
74 println!(
75 " 3. Environment variable priority: Explicit setting > Environment variable > Default"
76 );
77 println!(" 4. Support for all mainstream AI providers");
78 println!(" 5. Backward compatible, existing code requires no changes");
79
80 Ok(())
81}