Select the first available model when none configured for Ollama (#13048)

Selects the first available model for Ollama if a model is not
configured.

Release Notes:

- N/A
This commit is contained in:
Kyle Kelley 2024-06-14 09:35:13 -07:00 committed by GitHub
parent d9c21b4eb1
commit 1413b5af93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,7 +40,12 @@ impl OllamaCompletionProvider {
let client = http_client.clone();
let model = model.name.clone();
|_| async move { preload_model(client.as_ref(), &api_url, &model).await }
|_| async move {
if model.is_empty() {
return Ok(());
}
preload_model(client.as_ref(), &api_url, &model).await
}
})
.detach_and_log_err(cx);
@ -71,7 +76,12 @@ impl OllamaCompletionProvider {
})
.detach_and_log_err(cx);
self.model = model;
if model.name.is_empty() {
self.select_first_available_model()
} else {
self.model = model;
}
self.api_url = api_url;
self.low_speed_timeout = low_speed_timeout;
self.settings_version = settings_version;
@ -81,6 +91,12 @@ impl OllamaCompletionProvider {
self.available_models.iter()
}
pub fn select_first_available_model(&mut self) {
if let Some(model) = self.available_models.first() {
self.model = model.clone();
}
}
pub fn settings_version(&self) -> usize {
self.settings_version
}
@ -123,6 +139,10 @@ impl OllamaCompletionProvider {
cx.update_global::<CompletionProvider, _>(|provider, _cx| {
if let CompletionProvider::Ollama(provider) = provider {
provider.available_models = models;
if !provider.available_models.is_empty() && provider.model.name.is_empty() {
provider.select_first_available_model()
}
}
})
})