fix(ai): use configured provider's default model when no model set

When a user configures only Ollama (or any single provider) via the
multi-provider UI without explicitly selecting a model, GetModel() now
returns that provider's default model instead of falling back to the
legacy Provider field which defaults to "anthropic".

This fixes "API key is required for anthropic" errors when enabling AI
with only Ollama configured.

Related to #847
This commit is contained in:
rcourtman 2025-12-15 11:18:05 +00:00
parent 609aa98030
commit b6cc57590a

View file

@ -286,6 +286,24 @@ func (c *AIConfig) GetModel() string {
if c.Model != "" {
return c.Model
}
// If only one provider is configured, use its default model
// This handles the case where user configures Ollama but doesn't explicitly select a model
configured := c.GetConfiguredProviders()
if len(configured) == 1 {
switch configured[0] {
case AIProviderAnthropic:
return DefaultAIModelAnthropic
case AIProviderOpenAI:
return DefaultAIModelOpenAI
case AIProviderOllama:
return DefaultAIModelOllama
case AIProviderDeepSeek:
return DefaultAIModelDeepSeek
}
}
// Fall back to legacy Provider field for backwards compatibility
switch c.Provider {
case AIProviderAnthropic:
return DefaultAIModelAnthropic