fix(ai): allow enabling AI when any provider is configured
The enable validation was using the legacy single-provider model which checked settings.Provider and settings.APIKey. Users configuring Ollama via the new multi-provider UI (setting ollama_base_url) couldn't enable AI because settings.Provider defaulted to "anthropic" which required an API key. Now checks GetConfiguredProviders() first - if any provider is configured (Anthropic, OpenAI, DeepSeek, or Ollama), AI can be enabled. Related to #847
This commit is contained in:
parent
4bd9c3cf69
commit
eac510bb5e
1 changed files with 18 additions and 10 deletions
|
|
@ -360,20 +360,28 @@ func (h *AISettingsHandler) HandleUpdateAISettings(w http.ResponseWriter, r *htt
|
|||
}
|
||||
|
||||
if req.Enabled != nil {
|
||||
// Only allow enabling if properly configured
|
||||
// Only allow enabling if at least one provider is configured
|
||||
if *req.Enabled {
|
||||
switch settings.Provider {
|
||||
case config.AIProviderAnthropic, config.AIProviderOpenAI, config.AIProviderDeepSeek:
|
||||
if settings.APIKey == "" {
|
||||
http.Error(w, "Cannot enable AI: API key is required for "+settings.Provider, http.StatusBadRequest)
|
||||
configuredProviders := settings.GetConfiguredProviders()
|
||||
if len(configuredProviders) == 0 {
|
||||
// Fall back to legacy validation for backwards compatibility
|
||||
switch settings.Provider {
|
||||
case config.AIProviderAnthropic, config.AIProviderOpenAI, config.AIProviderDeepSeek:
|
||||
if settings.APIKey == "" {
|
||||
http.Error(w, "Cannot enable AI: configure at least one AI provider first", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
case config.AIProviderOllama:
|
||||
// Ollama doesn't need API key, but needs base URL (or will use default)
|
||||
if settings.BaseURL == "" {
|
||||
settings.BaseURL = config.DefaultOllamaBaseURL
|
||||
}
|
||||
default:
|
||||
http.Error(w, "Cannot enable AI: configure at least one AI provider first", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
case config.AIProviderOllama:
|
||||
// Ollama doesn't need API key, but needs base URL (or will use default)
|
||||
if settings.BaseURL == "" {
|
||||
settings.BaseURL = config.DefaultOllamaBaseURL
|
||||
}
|
||||
}
|
||||
// If we have configured providers, we're good to enable
|
||||
}
|
||||
settings.Enabled = *req.Enabled
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue