1use collections::HashMap;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4use settings_macros::{MergeFrom, with_fallible_options};
5
6use std::sync::Arc;
7
8#[with_fallible_options]
9#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
10pub struct AllLanguageModelSettingsContent {
11 pub anthropic: Option<AnthropicSettingsContent>,
12 pub bedrock: Option<AmazonBedrockSettingsContent>,
13 pub deepseek: Option<DeepseekSettingsContent>,
14 pub google: Option<GoogleSettingsContent>,
15 pub lmstudio: Option<LmStudioSettingsContent>,
16 pub mistral: Option<MistralSettingsContent>,
17 pub ollama: Option<OllamaSettingsContent>,
18 pub open_router: Option<OpenRouterSettingsContent>,
19 pub openai: Option<OpenAiSettingsContent>,
20 pub openai_compatible: Option<HashMap<Arc<str>, OpenAiCompatibleSettingsContent>>,
21 pub vercel: Option<VercelSettingsContent>,
22 pub x_ai: Option<XAiSettingsContent>,
23 #[serde(rename = "zed.dev")]
24 pub zed_dot_dev: Option<ZedDotDevSettingsContent>,
25}
26
27#[with_fallible_options]
28#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
29pub struct AnthropicSettingsContent {
30 pub api_url: Option<String>,
31 pub available_models: Option<Vec<AnthropicAvailableModel>>,
32}
33
34#[with_fallible_options]
35#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
36pub struct AnthropicAvailableModel {
37 /// The model's name in the Anthropic API. e.g. claude-3-5-sonnet-latest, claude-3-opus-20240229, etc
38 pub name: String,
39 /// The model's name in Zed's UI, such as in the model selector dropdown menu in the assistant panel.
40 pub display_name: Option<String>,
41 /// The model's context window size.
42 pub max_tokens: u64,
43 /// A model `name` to substitute when calling tools, in case the primary model doesn't support tool calling.
44 pub tool_override: Option<String>,
45 /// Configuration of Anthropic's caching API.
46 pub cache_configuration: Option<LanguageModelCacheConfiguration>,
47 pub max_output_tokens: Option<u64>,
48 #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
49 pub default_temperature: Option<f32>,
50 #[serde(default)]
51 pub extra_beta_headers: Vec<String>,
52 /// The model's mode (e.g. thinking)
53 pub mode: Option<ModelMode>,
54}
55
56#[with_fallible_options]
57#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
58pub struct AmazonBedrockSettingsContent {
59 pub available_models: Option<Vec<BedrockAvailableModel>>,
60 pub endpoint_url: Option<String>,
61 pub region: Option<String>,
62 pub profile: Option<String>,
63 pub authentication_method: Option<BedrockAuthMethodContent>,
64 pub allow_global: Option<bool>,
65}
66
67#[with_fallible_options]
68#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
69pub struct BedrockAvailableModel {
70 pub name: String,
71 pub display_name: Option<String>,
72 pub max_tokens: u64,
73 pub cache_configuration: Option<LanguageModelCacheConfiguration>,
74 pub max_output_tokens: Option<u64>,
75 #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
76 pub default_temperature: Option<f32>,
77 pub mode: Option<ModelMode>,
78}
79
80#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
81pub enum BedrockAuthMethodContent {
82 #[serde(rename = "named_profile")]
83 NamedProfile,
84 #[serde(rename = "sso")]
85 SingleSignOn,
86 /// IMDSv2, PodIdentity, env vars, etc.
87 #[serde(rename = "default")]
88 Automatic,
89}
90
91#[with_fallible_options]
92#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
93pub struct OllamaSettingsContent {
94 pub api_url: Option<String>,
95 pub auto_discover: Option<bool>,
96 pub available_models: Option<Vec<OllamaAvailableModel>>,
97}
98
99#[with_fallible_options]
100#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
101pub struct OllamaAvailableModel {
102 /// The model name in the Ollama API (e.g. "llama3.2:latest")
103 pub name: String,
104 /// The model's name in Zed's UI, such as in the model selector dropdown menu in the assistant panel.
105 pub display_name: Option<String>,
106 /// The Context Length parameter to the model (aka num_ctx or n_ctx)
107 pub max_tokens: u64,
108 /// The number of seconds to keep the connection open after the last request
109 pub keep_alive: Option<KeepAlive>,
110 /// Whether the model supports tools
111 pub supports_tools: Option<bool>,
112 /// Whether the model supports vision
113 pub supports_images: Option<bool>,
114 /// Whether to enable think mode
115 pub supports_thinking: Option<bool>,
116}
117
118#[derive(Clone, Serialize, Deserialize, Debug, Eq, PartialEq, JsonSchema, MergeFrom)]
119#[serde(untagged)]
120pub enum KeepAlive {
121 /// Keep model alive for N seconds
122 Seconds(isize),
123 /// Keep model alive for a fixed duration. Accepts durations like "5m", "10m", "1h", "1d", etc.
124 Duration(String),
125}
126
127impl KeepAlive {
128 /// Keep model alive until a new model is loaded or until Ollama shuts down
129 pub fn indefinite() -> Self {
130 Self::Seconds(-1)
131 }
132}
133
134impl Default for KeepAlive {
135 fn default() -> Self {
136 Self::indefinite()
137 }
138}
139
140#[with_fallible_options]
141#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
142pub struct LmStudioSettingsContent {
143 pub api_url: Option<String>,
144 pub available_models: Option<Vec<LmStudioAvailableModel>>,
145}
146
147#[with_fallible_options]
148#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
149pub struct LmStudioAvailableModel {
150 pub name: String,
151 pub display_name: Option<String>,
152 pub max_tokens: u64,
153 pub supports_tool_calls: bool,
154 pub supports_images: bool,
155}
156
157#[with_fallible_options]
158#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
159pub struct DeepseekSettingsContent {
160 pub api_url: Option<String>,
161 pub available_models: Option<Vec<DeepseekAvailableModel>>,
162}
163
164#[with_fallible_options]
165#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
166pub struct DeepseekAvailableModel {
167 pub name: String,
168 pub display_name: Option<String>,
169 pub max_tokens: u64,
170 pub max_output_tokens: Option<u64>,
171}
172
173#[with_fallible_options]
174#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
175pub struct MistralSettingsContent {
176 pub api_url: Option<String>,
177 pub available_models: Option<Vec<MistralAvailableModel>>,
178}
179
180#[with_fallible_options]
181#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
182pub struct MistralAvailableModel {
183 pub name: String,
184 pub display_name: Option<String>,
185 pub max_tokens: u64,
186 pub max_output_tokens: Option<u64>,
187 pub max_completion_tokens: Option<u64>,
188 pub supports_tools: Option<bool>,
189 pub supports_images: Option<bool>,
190 pub supports_thinking: Option<bool>,
191}
192
193#[with_fallible_options]
194#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
195pub struct OpenAiSettingsContent {
196 pub api_url: Option<String>,
197 pub available_models: Option<Vec<OpenAiAvailableModel>>,
198}
199
200#[with_fallible_options]
201#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
202pub struct OpenAiAvailableModel {
203 pub name: String,
204 pub display_name: Option<String>,
205 pub max_tokens: u64,
206 pub max_output_tokens: Option<u64>,
207 pub max_completion_tokens: Option<u64>,
208 pub reasoning_effort: Option<OpenAiReasoningEffort>,
209}
210
211#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, JsonSchema, MergeFrom)]
212#[serde(rename_all = "lowercase")]
213pub enum OpenAiReasoningEffort {
214 Minimal,
215 Low,
216 Medium,
217 High,
218}
219
220#[with_fallible_options]
221#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
222pub struct OpenAiCompatibleSettingsContent {
223 pub api_url: String,
224 pub available_models: Vec<OpenAiCompatibleAvailableModel>,
225}
226
227#[with_fallible_options]
228#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
229pub struct OpenAiCompatibleAvailableModel {
230 pub name: String,
231 pub display_name: Option<String>,
232 pub max_tokens: u64,
233 pub max_output_tokens: Option<u64>,
234 pub max_completion_tokens: Option<u64>,
235 #[serde(default)]
236 pub capabilities: OpenAiCompatibleModelCapabilities,
237}
238
239#[with_fallible_options]
240#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
241pub struct OpenAiCompatibleModelCapabilities {
242 pub tools: bool,
243 pub images: bool,
244 pub parallel_tool_calls: bool,
245 pub prompt_cache_key: bool,
246}
247
248impl Default for OpenAiCompatibleModelCapabilities {
249 fn default() -> Self {
250 Self {
251 tools: true,
252 images: false,
253 parallel_tool_calls: false,
254 prompt_cache_key: false,
255 }
256 }
257}
258
259#[with_fallible_options]
260#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
261pub struct VercelSettingsContent {
262 pub api_url: Option<String>,
263 pub available_models: Option<Vec<VercelAvailableModel>>,
264}
265
266#[with_fallible_options]
267#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
268pub struct VercelAvailableModel {
269 pub name: String,
270 pub display_name: Option<String>,
271 pub max_tokens: u64,
272 pub max_output_tokens: Option<u64>,
273 pub max_completion_tokens: Option<u64>,
274}
275
276#[with_fallible_options]
277#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
278pub struct GoogleSettingsContent {
279 pub api_url: Option<String>,
280 pub available_models: Option<Vec<GoogleAvailableModel>>,
281}
282
283#[with_fallible_options]
284#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
285pub struct GoogleAvailableModel {
286 pub name: String,
287 pub display_name: Option<String>,
288 pub max_tokens: u64,
289 pub mode: Option<ModelMode>,
290}
291
292#[with_fallible_options]
293#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
294pub struct XAiSettingsContent {
295 pub api_url: Option<String>,
296 pub available_models: Option<Vec<XaiAvailableModel>>,
297}
298
299#[with_fallible_options]
300#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
301pub struct XaiAvailableModel {
302 pub name: String,
303 pub display_name: Option<String>,
304 pub max_tokens: u64,
305 pub max_output_tokens: Option<u64>,
306 pub max_completion_tokens: Option<u64>,
307 pub supports_images: Option<bool>,
308 pub supports_tools: Option<bool>,
309 pub parallel_tool_calls: Option<bool>,
310}
311
312#[with_fallible_options]
313#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
314pub struct ZedDotDevSettingsContent {
315 pub available_models: Option<Vec<ZedDotDevAvailableModel>>,
316}
317
318#[with_fallible_options]
319#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
320pub struct ZedDotDevAvailableModel {
321 /// The provider of the language model.
322 pub provider: ZedDotDevAvailableProvider,
323 /// The model's name in the provider's API. e.g. claude-3-5-sonnet-20240620
324 pub name: String,
325 /// The name displayed in the UI, such as in the assistant panel model dropdown menu.
326 pub display_name: Option<String>,
327 /// The size of the context window, indicating the maximum number of tokens the model can process.
328 pub max_tokens: usize,
329 /// The maximum number of output tokens allowed by the model.
330 pub max_output_tokens: Option<u64>,
331 /// The maximum number of completion tokens allowed by the model (o1-* only)
332 pub max_completion_tokens: Option<u64>,
333 /// Override this model with a different Anthropic model for tool calls.
334 pub tool_override: Option<String>,
335 /// Indicates whether this custom model supports caching.
336 pub cache_configuration: Option<LanguageModelCacheConfiguration>,
337 /// The default temperature to use for this model.
338 #[serde(serialize_with = "crate::serialize_optional_f32_with_two_decimal_places")]
339 pub default_temperature: Option<f32>,
340 /// Any extra beta headers to provide when using the model.
341 #[serde(default)]
342 pub extra_beta_headers: Vec<String>,
343 /// The model's mode (e.g. thinking)
344 pub mode: Option<ModelMode>,
345}
346
347#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
348#[serde(rename_all = "lowercase")]
349pub enum ZedDotDevAvailableProvider {
350 Anthropic,
351 OpenAi,
352 Google,
353}
354
355#[with_fallible_options]
356#[derive(Default, Clone, Debug, Serialize, Deserialize, PartialEq, JsonSchema, MergeFrom)]
357pub struct OpenRouterSettingsContent {
358 pub api_url: Option<String>,
359 pub available_models: Option<Vec<OpenRouterAvailableModel>>,
360}
361
362#[with_fallible_options]
363#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
364pub struct OpenRouterAvailableModel {
365 pub name: String,
366 pub display_name: Option<String>,
367 pub max_tokens: u64,
368 pub max_output_tokens: Option<u64>,
369 pub max_completion_tokens: Option<u64>,
370 pub supports_tools: Option<bool>,
371 pub supports_images: Option<bool>,
372 pub mode: Option<ModelMode>,
373 pub provider: Option<OpenRouterProvider>,
374}
375
376#[with_fallible_options]
377#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
378pub struct OpenRouterProvider {
379 order: Option<Vec<String>>,
380 #[serde(default = "default_true")]
381 allow_fallbacks: bool,
382 #[serde(default)]
383 require_parameters: bool,
384 #[serde(default)]
385 data_collection: DataCollection,
386 only: Option<Vec<String>>,
387 ignore: Option<Vec<String>>,
388 quantizations: Option<Vec<String>>,
389 sort: Option<String>,
390}
391
392#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
393#[serde(rename_all = "lowercase")]
394pub enum DataCollection {
395 #[default]
396 Allow,
397 Disallow,
398}
399
400fn default_true() -> bool {
401 true
402}
403
404/// Configuration for caching language model messages.
405#[with_fallible_options]
406#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
407pub struct LanguageModelCacheConfiguration {
408 pub max_cache_anchors: usize,
409 pub should_speculate: bool,
410 pub min_total_token: u64,
411}
412
413#[derive(
414 Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, MergeFrom,
415)]
416#[serde(tag = "type", rename_all = "lowercase")]
417pub enum ModelMode {
418 #[default]
419 Default,
420 Thinking {
421 /// The maximum number of tokens to use for reasoning. Must be lower than the model's `max_output_tokens`.
422 budget_tokens: Option<u32>,
423 },
424}