Create LLM client with full configuration (supports custom base_url)
(config: LlmConfig)
| 125 | |
| 126 | /// Create LLM client with full configuration (supports custom base_url) |
| 127 | pub fn create_client_with_config(config: LlmConfig) -> Arc<dyn LlmClient> { |
| 128 | let retry = config.retry_config.clone().unwrap_or_default(); |
| 129 | let api_key = config.api_key.expose().to_string(); |
| 130 | let headers = config.resolved_headers(); |
| 131 | |
| 132 | match config.provider.as_str() { |
| 133 | "anthropic" | "claude" => { |
| 134 | let mut client = AnthropicClient::new(api_key, config.model) |
| 135 | .with_provider_name(config.provider.clone()) |
| 136 | .with_retry_config(retry); |
| 137 | if let Some(base_url) = config.base_url { |
| 138 | client = client.with_base_url(base_url); |
| 139 | } |
| 140 | if !config.disable_temperature { |
| 141 | if let Some(temp) = config.temperature { |
| 142 | client = client.with_temperature(temp); |
| 143 | } |
| 144 | } |
| 145 | if let Some(max) = config.max_tokens { |
| 146 | client = client.with_max_tokens(max); |
| 147 | } |
| 148 | if let Some(budget) = config.thinking_budget { |
| 149 | client = client.with_thinking_budget(budget); |
| 150 | } |
| 151 | Arc::new(client) |
| 152 | } |
| 153 | "openai" | "gpt" => { |
| 154 | let mut client = OpenAiClient::new(api_key, config.model) |
| 155 | .with_provider_name(config.provider.clone()) |
| 156 | .with_retry_config(retry); |
| 157 | if let Some(base_url) = config.base_url { |
| 158 | client = client.with_base_url(base_url); |
| 159 | } |
| 160 | if !headers.is_empty() { |
| 161 | client = client.with_headers(headers.clone()); |
| 162 | } |
| 163 | if !config.disable_temperature { |
| 164 | if let Some(temp) = config.temperature { |
| 165 | client = client.with_temperature(temp); |
| 166 | } |
| 167 | } |
| 168 | if let Some(max) = config.max_tokens { |
| 169 | client = client.with_max_tokens(max); |
| 170 | } |
| 171 | Arc::new(client) |
| 172 | } |
| 173 | "glm" | "zhipu" | "bigmodel" => { |
| 174 | let mut client = ZhipuClient::new(api_key, config.model).with_retry_config(retry); |
| 175 | if let Some(base_url) = config.base_url { |
| 176 | client = client.with_base_url(base_url); |
| 177 | } |
| 178 | if !config.disable_temperature { |
| 179 | if let Some(temp) = config.temperature { |
| 180 | client = client.with_temperature(temp); |
| 181 | } |
| 182 | } |
| 183 | if let Some(max) = config.max_tokens { |
| 184 | client = client.with_max_tokens(max); |