1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//! # LLM Integration Layer
//!
//! This module provides a unified, modular interface for integrating multiple LLM providers
//! with VT Code, supporting Gemini, OpenAI, Anthropic, xAI, and DeepSeek.
//!
//! ## Architecture Overview
//!
//! The LLM layer is designed with several key principles:
//!
//! - **Unified Interface**: Single `AnyClient` trait for all providers
//! - **Provider Agnostic**: Easy switching between providers
//! - **Configuration Driven**: TOML-based provider configuration
//! - **Error Handling**: Comprehensive error types and recovery
//! - **Async Support**: Full async/await support for all operations
//!
//! ## Supported Providers
//!
//! | Provider | Status | Models |
//! |----------|--------|---------|
//! | Gemini | ✓ | gemini-3.1-pro-preview, gemini-3-flash-preview |
//! | OpenAI | ✓ | gpt-5, o3, o4-mini, gpt-5-mini, gpt-5-nano |
//! | Anthropic | ✓ | claude-4.1-opus, claude-4-sonnet |
//! | xAI | ✓ | grok-2-latest, grok-2-mini |
//! | DeepSeek | ✓ | deepseek-chat, deepseek-reasoner |
//! | Z.AI | ✓ | glm-5 |
//! | Ollama | ✓ | gpt-oss:20b (local) |
//!
//! ## Basic Usage
//!
//! ```rust,no_run
//! use vtcode_core::llm::{AnyClient, make_client};
//! use vtcode_core::utils::dot_config::ProviderConfigs;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Configure providers
//! let providers = ProviderConfigs {
//! gemini: Some(vtcode_core::utils::dot_config::ProviderConfig {
//! api_key: std::env::var("GEMINI_API_KEY")?,
//! model: "gemini-3-flash-preview".to_string(),
//! ..Default::default()
//! }),
//! ..Default::default()
//! };
//!
//! // Create client
//! let client = make_client(&providers, "gemini")?;
//!
//! // Make a request
//! let messages = vec![
//! vtcode_core::llm::types::Message {
//! role: "user".to_string(),
//! content: "Hello, how can you help me with coding?".to_string(),
//! }
//! ];
//!
//! let response = client.chat(&messages, None).await?;
//! println!("Response: {}", response.content);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Provider Configuration
//!
//! ```rust,no_run
//! use vtcode_core::utils::dot_config::{ProviderConfigs, ProviderConfig};
//!
//! let config = ProviderConfigs {
//! gemini: Some(ProviderConfig {
//! api_key: "your-api-key".to_string(),
//! model: "gemini-3-flash-preview".to_string(),
//! temperature: Some(0.7),
//! max_tokens: Some(4096),
//! ..Default::default()
//! }),
//! openai: Some(ProviderConfig {
//! api_key: "your-openai-key".to_string(),
//! model: "gpt-5".to_string(),
//! temperature: Some(0.3),
//! max_tokens: Some(8192),
//! ..Default::default()
//! }),
//! ..Default::default()
//! };
//! ```
//!
//! ## Advanced Features
//!
//! ### Streaming Responses
//! ```rust,no_run
//! use vtcode_core::llm::AnyClient;
//! use futures::StreamExt;
//!
//! let client = make_client(&providers, "gemini")?;
//!
//! let mut stream = client.chat_stream(&messages, None).await?;
//! while let Some(chunk) = stream.next().await {
//! match chunk {
//! Ok(response) => print!("{}", response.content),
//! Err(e) => eprintln!("Error: {}", e),
//! }
//! }
//! ```
//!
//! ### Function Calling
//! ```rust,no_run
//! use vtcode_core::llm::types::{FunctionDeclaration, FunctionCall};
//!
//! let functions = vec![
//! FunctionDeclaration {
//! name: "read_file".to_string(),
//! description: "Read a file from the filesystem".to_string(),
//! parameters: serde_json::json!({
//! "type": "object",
//! "properties": {
//! "path": {"type": "string", "description": "File path to read"}
//! },
//! "required": ["path"]
//! }),
//! }
//! ];
//!
//! let response = client.chat_with_functions(&messages, &functions, None).await?;
//!
//! if let Some(function_call) = response.function_call {
//! match function_call.name.as_str() {
//! "read_file" => {
//! // Handle function call
//! }
//! _ => {}
//! }
//! }
//! ```
//!
//! ## Error Handling
//!
//! The LLM layer provides comprehensive error handling:
//!
//! ```rust,no_run
//! use vtcode_core::llm::LLMError;
//!
//! match client.chat(&messages, None).await {
//! Ok(response) => println!("Success: {}", response.content),
//! Err(LLMError::Authentication) => eprintln!("Authentication failed"),
//! Err(LLMError::RateLimit { metadata: None }) => eprintln!("Rate limit exceeded"),
//! Err(LLMError::Network { message: e, metadata: None }) => eprintln!("Network error: {}", e),
//! Err(LLMError::Provider { message: e, metadata: None }) => eprintln!("Provider error: {}", e),
//! Err(e) => eprintln!("Other error: {}", e),
//! }
//! ```
//!
//! ## Performance Considerations
//!
//! - **Connection Pooling**: Efficient connection reuse
//! - **Request Batching**: Where supported by providers
//! - **Caching**: Built-in prompt caching for repeated requests
//! - **Timeout Handling**: Configurable timeouts and retries
//! - **Rate Limiting**: Automatic rate limit handling
//!
//! # LLM abstraction layer with modular architecture
//!
//! This module provides a unified interface for different LLM providers
//! with provider-specific implementations.
// Shared provider utilities to eliminate duplicate code
// Shared utilities for request/response processing // Centralized HTTP client factory
// Re-export main types for backward compatibility
pub use ProviderCapabilities;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use collect_single_response;
pub use ;
pub use ;