ai_lib/
lib.rs

1//! AI-lib: A Unified AI SDK for Rust
2//! 
3//! This library provides a single, consistent interface for interacting with multiple AI model providers.
4//! 
5//! # Quick Start
6//! 
7//! ```rust
8//! use ai_lib::{AiClient, Provider, ChatCompletionRequest, Message, Role};
9//! 
10//! #[tokio::main]
11//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
12//!     // 切换模型提供商,只需更改 Provider 的值
13//!     let client = AiClient::new(Provider::Groq)?;
14//!     
15//!     let request = ChatCompletionRequest::new(
16//!         "llama3-8b-8192".to_string(),
17//!         vec![Message {
18//!             role: Role::User,
19//!             content: "Hello, how are you?".to_string(),
20//!         }],
21//!     );
22//!     
23//!     // 注意:这里需要设置GROQ_API_KEY环境变量才能实际调用API
24//!     // let response = client.chat_completion(request).await?;
25//!     // println!("Response: {}", response.choices[0].message.content);
26//!     
27//!     println!("Client created successfully with provider: {:?}", client.current_provider());
28//!     println!("Request prepared for model: {}", request.model);
29//!     
30//!     Ok(())
31//! }
32//! ```
33//! 
34//! # 代理服务器支持
35//! 
36//! AI-lib 支持通过环境变量配置代理服务器:
37//! 
38//! ```bash
39//! # 设置代理服务器
40//! export AI_PROXY_URL=http://proxy.example.com:8080
41//! 
42//! # 带认证的代理
43//! export AI_PROXY_URL=http://username:password@proxy.example.com:8080
44//! 
45//! # HTTPS代理
46//! export AI_PROXY_URL=https://proxy.example.com:8080
47//! ```
48//! 
49//! 设置后,所有AI提供商的请求都会自动通过指定的代理服务器。
50
51pub mod api;
52pub mod types;
53pub mod provider;
54pub mod client;
55pub mod transport;
56
57// 重新导出主要类型,方便用户使用
58pub use api::ChatApi;
59pub use types::{ChatCompletionRequest, ChatCompletionResponse, Message, Role, Choice, Usage, AiLibError};
60pub use client::{AiClient, Provider};