MCPcopy Create free account
hub / github.com/AI45Lab/Code / create_client_with_config

Function create_client_with_config

core/src/llm/factory.rs:127–214  ·  view source on GitHub ↗

Create LLM client with full configuration (supports custom base_url)

(config: LlmConfig)

Source from the content-addressed store, hash-verified

125
126/// Create LLM client with full configuration (supports custom base_url)
127pub 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);

Calls 12

exposeMethod · 0.80
resolved_headersMethod · 0.80
cloneMethod · 0.45
as_strMethod · 0.45
with_retry_configMethod · 0.45
with_provider_nameMethod · 0.45
with_base_urlMethod · 0.45
with_temperatureMethod · 0.45
with_max_tokensMethod · 0.45
with_thinking_budgetMethod · 0.45
is_emptyMethod · 0.45
with_headersMethod · 0.45