Remove model default and add placeholder configuration link
This commit is contained in:
parent
b95f4d0818
commit
2e45d30741
2 changed files with 56 additions and 27 deletions
|
@ -906,8 +906,12 @@ impl InlineCompletionButton {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
menu.separator()
|
menu.separator()
|
||||||
.entry("No Models Available", None, |_window, _cx| {
|
.header("No Models Configured")
|
||||||
// Display only
|
.entry("Configure Models", None, {
|
||||||
|
let fs = fs.clone();
|
||||||
|
move |window, cx| {
|
||||||
|
Self::open_ollama_settings(fs.clone(), window, cx);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -916,7 +920,7 @@ impl InlineCompletionButton {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Opens Zed settings and navigates directly to the Ollama API URL configuration.
|
/// Opens Zed settings and navigates directly to the Ollama models configuration.
|
||||||
/// Uses improved regex patterns to locate the exact setting in the JSON structure.
|
/// Uses improved regex patterns to locate the exact setting in the JSON structure.
|
||||||
fn open_ollama_settings(_fs: Arc<dyn Fs>, window: &mut Window, cx: &mut App) {
|
fn open_ollama_settings(_fs: Arc<dyn Fs>, window: &mut Window, cx: &mut App) {
|
||||||
if let Some(workspace) = window.root::<Workspace>().flatten() {
|
if let Some(workspace) = window.root::<Workspace>().flatten() {
|
||||||
|
@ -938,24 +942,25 @@ impl InlineCompletionButton {
|
||||||
.update_in(cx, |item, window, cx| {
|
.update_in(cx, |item, window, cx| {
|
||||||
let text = item.buffer().read(cx).snapshot(cx).text();
|
let text = item.buffer().read(cx).snapshot(cx).text();
|
||||||
|
|
||||||
// Look for language_models.ollama.api_url setting with precise pattern
|
// Look for language_models.ollama section with precise pattern
|
||||||
// This matches the full nested structure to avoid false matches
|
// This matches the full nested structure to avoid false matches
|
||||||
let api_url_pattern = r#""language_models"\s*:\s*\{[\s\S]*?"ollama"\s*:\s*\{[\s\S]*?"api_url"\s*:\s*"([^"]*)"#;
|
let ollama_pattern = r#""language_models"\s*:\s*\{[\s\S]*?"ollama"\s*:\s*\{[\s\S]*?"available_models"\s*:\s*\[\s*\]"#;
|
||||||
let regex = regex::Regex::new(api_url_pattern).unwrap();
|
let regex = regex::Regex::new(ollama_pattern).unwrap();
|
||||||
|
|
||||||
if let Some(captures) = regex.captures(&text) {
|
if let Some(captures) = regex.captures(&text) {
|
||||||
let _full_match = captures.get(0).unwrap();
|
let full_match = captures.get(0).unwrap();
|
||||||
let value_capture = captures.get(1).unwrap();
|
|
||||||
|
|
||||||
// Select the API URL value (excluding quotes)
|
// Position cursor after the opening bracket of available_models array
|
||||||
|
let bracket_pos = full_match.as_str().rfind('[').unwrap();
|
||||||
|
let cursor_pos = full_match.start() + bracket_pos + 1;
|
||||||
|
|
||||||
|
// Place cursor inside the available_models array
|
||||||
item.change_selections(
|
item.change_selections(
|
||||||
SelectionEffects::scroll(Autoscroll::newest()),
|
SelectionEffects::scroll(Autoscroll::newest()),
|
||||||
window,
|
window,
|
||||||
cx,
|
cx,
|
||||||
|selections| {
|
|selections| {
|
||||||
selections.select_ranges(vec![
|
selections.select_ranges(vec![cursor_pos..cursor_pos]);
|
||||||
value_capture.start()..value_capture.end(),
|
|
||||||
]);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return Ok::<(), anyhow::Error>(());
|
return Ok::<(), anyhow::Error>(());
|
||||||
|
@ -1475,6 +1480,27 @@ mod tests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_ollama_no_models_configured(cx: &mut TestAppContext) {
|
||||||
|
cx.update(|cx| {
|
||||||
|
let store = SettingsStore::test(cx);
|
||||||
|
cx.set_global(store);
|
||||||
|
AllLanguageModelSettings::register(cx);
|
||||||
|
language_model::LanguageModelRegistry::test(cx);
|
||||||
|
|
||||||
|
// Test menu behavior when no models are configured
|
||||||
|
let settings = AllLanguageModelSettings::get_global(cx);
|
||||||
|
let ollama_settings = &settings.ollama;
|
||||||
|
|
||||||
|
// Verify that available_models is empty by default
|
||||||
|
assert!(ollama_settings.available_models.is_empty());
|
||||||
|
|
||||||
|
// This simulates the condition that would trigger the "Configure Models" menu
|
||||||
|
let should_show_configure = ollama_settings.available_models.is_empty();
|
||||||
|
assert!(should_show_configure);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_ollama_eager_subtle_options_visibility(cx: &mut TestAppContext) {
|
async fn test_ollama_eager_subtle_options_visibility(cx: &mut TestAppContext) {
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
|
|
|
@ -333,24 +333,27 @@ fn assign_edit_prediction_provider(
|
||||||
}
|
}
|
||||||
EditPredictionProvider::Ollama => {
|
EditPredictionProvider::Ollama => {
|
||||||
let settings = &AllLanguageModelSettings::get_global(cx).ollama;
|
let settings = &AllLanguageModelSettings::get_global(cx).ollama;
|
||||||
let api_url = settings.api_url.clone();
|
|
||||||
|
|
||||||
// Use first available model or default to a FIM-capable model
|
// Only create provider if models are configured
|
||||||
// NOTE: codellama:7b and deepseek-coder:latest do NOT support FIM
|
// Note: Only FIM-capable models work with inline completion:
|
||||||
// Use qwen2.5-coder:3b or starcoder2:latest instead
|
// ✓ Supported: qwen2.5-coder:*, starcoder2:*, codeqwen:*
|
||||||
let model = settings
|
// ✗ Not supported: codellama:*, deepseek-coder:*, llama3:*
|
||||||
.available_models
|
if let Some(first_model) = settings.available_models.first() {
|
||||||
.first()
|
let api_url = settings.api_url.clone();
|
||||||
.map(|m| m.name.clone())
|
let model = first_model.name.clone();
|
||||||
.unwrap_or_else(|| "qwen2.5-coder:3b".to_string());
|
|
||||||
|
|
||||||
// Get API key from environment variable only (credentials would require async handling)
|
// Get API key from environment variable only (credentials would require async handling)
|
||||||
let api_key = std::env::var("OLLAMA_API_KEY").ok();
|
let api_key = std::env::var("OLLAMA_API_KEY").ok();
|
||||||
|
|
||||||
let provider = cx.new(|_| {
|
let provider = cx.new(|_| {
|
||||||
OllamaCompletionProvider::new(client.http_client(), api_url, model, api_key)
|
OllamaCompletionProvider::new(client.http_client(), api_url, model, api_key)
|
||||||
});
|
});
|
||||||
editor.set_edit_prediction_provider(Some(provider), window, cx);
|
editor.set_edit_prediction_provider(Some(provider), window, cx);
|
||||||
|
} else {
|
||||||
|
// No models configured - don't create a provider
|
||||||
|
// User will see "Configure Models" option in the completion menu
|
||||||
|
editor.set_edit_prediction_provider::<OllamaCompletionProvider>(None, window, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue