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