First up: I'm sorry if this is a low quality PR, or if this feature
isn't wanted. I implemented this because I'd like to have this
behaviour. If you don't think that this is useful, feel free to close
the PR without comment. :)
My idea is this: I love to pull random models with Ollama to try them.
At the same time, not all of them are useful for coding, or some won't
work out of the box with the context_length set. So, I'd like to change
Zed's behaviour to not show me all models Ollama has, but to limit it to
the ones that I configure manually.
What I did is add an `auto_discover` field to the settings. The idea is
that you can write a config like this:
```json
"language_models": {
"ollama": {
"api_url": "http://localhost:11434",
"auto_discover": false,
"available_models": [
{
"name": "qwen3:4b",
"display_name": "Qwen3 4B 32K",
"max_tokens": 32768,
"supports_tools": true,
"supports_thinking": true,
"supports_images": true
}
]
}
}
```
The `auto_discover: false` means that Zed won't pick up or show the
language models that Ollama knows about, and will only show me the one I
manually configured in `available_models`. That way, I can pull random
models with Ollama, but in Zed I can only see the ones that I know work
(because I've configured them).
The default for `auto_discover` (when it is not explicitly set) is
`true`, meaning that the existing behaviour is preserved, and this is
not a breaking change for configurations.
Release Notes:
- ollama: Added `auto_discover` setting to optionally limit visible
models to only those manually configured in `available_models`
118 lines
5.0 KiB
Rust
118 lines
5.0 KiB
Rust
use std::sync::Arc;
|
|
|
|
use collections::HashMap;
|
|
use settings::RegisterSetting;
|
|
|
|
use crate::provider::{
|
|
anthropic::AnthropicSettings, bedrock::AmazonBedrockSettings, cloud::ZedDotDevSettings,
|
|
deepseek::DeepSeekSettings, google::GoogleSettings, lmstudio::LmStudioSettings,
|
|
mistral::MistralSettings, ollama::OllamaSettings, open_ai::OpenAiSettings,
|
|
open_ai_compatible::OpenAiCompatibleSettings, open_router::OpenRouterSettings,
|
|
vercel::VercelSettings, x_ai::XAiSettings,
|
|
};
|
|
|
|
#[derive(Debug, RegisterSetting)]
|
|
pub struct AllLanguageModelSettings {
|
|
pub anthropic: AnthropicSettings,
|
|
pub bedrock: AmazonBedrockSettings,
|
|
pub deepseek: DeepSeekSettings,
|
|
pub google: GoogleSettings,
|
|
pub lmstudio: LmStudioSettings,
|
|
pub mistral: MistralSettings,
|
|
pub ollama: OllamaSettings,
|
|
pub open_router: OpenRouterSettings,
|
|
pub openai: OpenAiSettings,
|
|
pub openai_compatible: HashMap<Arc<str>, OpenAiCompatibleSettings>,
|
|
pub vercel: VercelSettings,
|
|
pub x_ai: XAiSettings,
|
|
pub zed_dot_dev: ZedDotDevSettings,
|
|
}
|
|
|
|
impl settings::Settings for AllLanguageModelSettings {
|
|
const PRESERVED_KEYS: Option<&'static [&'static str]> = Some(&["version"]);
|
|
|
|
fn from_settings(content: &settings::SettingsContent) -> Self {
|
|
let language_models = content.language_models.clone().unwrap();
|
|
let anthropic = language_models.anthropic.unwrap();
|
|
let bedrock = language_models.bedrock.unwrap();
|
|
let deepseek = language_models.deepseek.unwrap();
|
|
let google = language_models.google.unwrap();
|
|
let lmstudio = language_models.lmstudio.unwrap();
|
|
let mistral = language_models.mistral.unwrap();
|
|
let ollama = language_models.ollama.unwrap();
|
|
let open_router = language_models.open_router.unwrap();
|
|
let openai = language_models.openai.unwrap();
|
|
let openai_compatible = language_models.openai_compatible.unwrap();
|
|
let vercel = language_models.vercel.unwrap();
|
|
let x_ai = language_models.x_ai.unwrap();
|
|
let zed_dot_dev = language_models.zed_dot_dev.unwrap();
|
|
Self {
|
|
anthropic: AnthropicSettings {
|
|
api_url: anthropic.api_url.unwrap(),
|
|
available_models: anthropic.available_models.unwrap_or_default(),
|
|
},
|
|
bedrock: AmazonBedrockSettings {
|
|
available_models: bedrock.available_models.unwrap_or_default(),
|
|
region: bedrock.region,
|
|
endpoint: bedrock.endpoint_url, // todo(should be api_url)
|
|
profile_name: bedrock.profile,
|
|
role_arn: None, // todo(was never a setting for this...)
|
|
authentication_method: bedrock.authentication_method.map(Into::into),
|
|
allow_global: bedrock.allow_global,
|
|
},
|
|
deepseek: DeepSeekSettings {
|
|
api_url: deepseek.api_url.unwrap(),
|
|
available_models: deepseek.available_models.unwrap_or_default(),
|
|
},
|
|
google: GoogleSettings {
|
|
api_url: google.api_url.unwrap(),
|
|
available_models: google.available_models.unwrap_or_default(),
|
|
},
|
|
lmstudio: LmStudioSettings {
|
|
api_url: lmstudio.api_url.unwrap(),
|
|
available_models: lmstudio.available_models.unwrap_or_default(),
|
|
},
|
|
mistral: MistralSettings {
|
|
api_url: mistral.api_url.unwrap(),
|
|
available_models: mistral.available_models.unwrap_or_default(),
|
|
},
|
|
ollama: OllamaSettings {
|
|
api_url: ollama.api_url.unwrap(),
|
|
auto_discover: ollama.auto_discover.unwrap_or(true),
|
|
available_models: ollama.available_models.unwrap_or_default(),
|
|
},
|
|
open_router: OpenRouterSettings {
|
|
api_url: open_router.api_url.unwrap(),
|
|
available_models: open_router.available_models.unwrap_or_default(),
|
|
},
|
|
openai: OpenAiSettings {
|
|
api_url: openai.api_url.unwrap(),
|
|
available_models: openai.available_models.unwrap_or_default(),
|
|
},
|
|
openai_compatible: openai_compatible
|
|
.into_iter()
|
|
.map(|(key, value)| {
|
|
(
|
|
key,
|
|
OpenAiCompatibleSettings {
|
|
api_url: value.api_url,
|
|
available_models: value.available_models,
|
|
},
|
|
)
|
|
})
|
|
.collect(),
|
|
vercel: VercelSettings {
|
|
api_url: vercel.api_url.unwrap(),
|
|
available_models: vercel.available_models.unwrap_or_default(),
|
|
},
|
|
x_ai: XAiSettings {
|
|
api_url: x_ai.api_url.unwrap(),
|
|
available_models: x_ai.available_models.unwrap_or_default(),
|
|
},
|
|
zed_dot_dev: ZedDotDevSettings {
|
|
available_models: zed_dot_dev.available_models.unwrap_or_default(),
|
|
},
|
|
}
|
|
}
|
|
}
|