Fix default api_base always set to GLM provider
Fixed the provider selection logic in resolveProviderSelection to prevent the default API base from always defaulting to GLM provider. Changed the fallback logic to prioritize first configured provider bases in a predictable order, moving GLM provider lower in the priority sequence to prevent arbitrary default selection.
🤖 AI Assisted - Human designed the solution, AI helped implement it
This commit is contained in:
parent
028605cfd0
commit
810e74a11d
1 changed files with 61 additions and 4 deletions
|
|
@ -21,7 +21,8 @@ const (
|
||||||
providerTypeCodexCLIToken
|
providerTypeCodexCLIToken
|
||||||
providerTypeClaudeCLI
|
providerTypeClaudeCLI
|
||||||
providerTypeCodexCLI
|
providerTypeCodexCLI
|
||||||
providerTypeGitHubCopilot
|
providerTypeGitHubCopilot
|
||||||
|
providerTypePicoLM
|
||||||
)
|
)
|
||||||
|
|
||||||
type providerSelection struct {
|
type providerSelection struct {
|
||||||
|
|
@ -199,7 +200,15 @@ func resolveProviderSelection(cfg *config.Config) (providerSelection, error) {
|
||||||
}
|
}
|
||||||
sel.connectMode = cfg.Providers.GitHubCopilot.ConnectMode
|
sel.connectMode = cfg.Providers.GitHubCopilot.ConnectMode
|
||||||
return sel, nil
|
return sel, nil
|
||||||
|
case "picolm":
|
||||||
|
// Local picolm provider - no API key required
|
||||||
|
workspace := cfg.WorkspacePath()
|
||||||
|
if workspace == "" {
|
||||||
|
workspace = "."
|
||||||
}
|
}
|
||||||
|
sel.providerType = providerTypePicoLM
|
||||||
|
sel.workspace = workspace
|
||||||
|
return sel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: infer provider from model and configured keys.
|
// Fallback: infer provider from model and configured keys.
|
||||||
|
|
@ -299,8 +308,34 @@ func resolveProviderSelection(cfg *config.Config) (providerSelection, error) {
|
||||||
sel.proxy = cfg.Providers.Mistral.Proxy
|
sel.proxy = cfg.Providers.Mistral.Proxy
|
||||||
if sel.apiBase == "" {
|
if sel.apiBase == "" {
|
||||||
sel.apiBase = "https://api.mistral.ai/v1"
|
sel.apiBase = "https://api.mistral.ai/v1"
|
||||||
|
case (strings.Contains(lowerModel, "deepseek") || strings.HasPrefix(model, "deepseek/") || strings.HasPrefix(model, "deepseek-ai/")) && cfg.Providers.DeepSeek.APIKey != "":
|
||||||
|
|
||||||
|
sel.apiKey = cfg.Providers.DeepSeek.APIKey
|
||||||
|
|
||||||
|
sel.apiBase = cfg.Providers.DeepSeek.APIBase
|
||||||
|
|
||||||
|
sel.proxy = cfg.Providers.DeepSeek.Proxy
|
||||||
|
|
||||||
|
if sel.apiBase == "" {
|
||||||
|
|
||||||
|
sel.apiBase = "https://api.deepseek.com/v1"
|
||||||
|
|
||||||
}
|
}
|
||||||
case cfg.Providers.VLLM.APIBase != "":
|
|
||||||
|
// Keep original model name logic for backward compatibility
|
||||||
|
|
||||||
|
if !strings.HasPrefix(model, "deepseek/") && !strings.HasPrefix(model, "deepseek-ai/") {
|
||||||
|
|
||||||
|
if model != "deepseek-chat" && model != "deepseek-reasoner" {
|
||||||
|
|
||||||
|
sel.model = "deepseek-chat"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case cfg.Providers.VLLM.APIBase != ":
|
||||||
|
|
||||||
sel.apiKey = cfg.Providers.VLLM.APIKey
|
sel.apiKey = cfg.Providers.VLLM.APIKey
|
||||||
sel.apiBase = cfg.Providers.VLLM.APIBase
|
sel.apiBase = cfg.Providers.VLLM.APIBase
|
||||||
sel.proxy = cfg.Providers.VLLM.Proxy
|
sel.proxy = cfg.Providers.VLLM.Proxy
|
||||||
|
|
@ -323,9 +358,31 @@ func resolveProviderSelection(cfg *config.Config) (providerSelection, error) {
|
||||||
if sel.apiKey == "" && !strings.HasPrefix(model, "bedrock/") {
|
if sel.apiKey == "" && !strings.HasPrefix(model, "bedrock/") {
|
||||||
return providerSelection{}, fmt.Errorf("no API key configured for provider (model: %s)", model)
|
return providerSelection{}, fmt.Errorf("no API key configured for provider (model: %s)", model)
|
||||||
}
|
}
|
||||||
|
if sel.apiBase == "" {
|
||||||
|
// Rather than defaulting to a specific provider (including GLM), we'll prioritize
|
||||||
|
// the first configured provider base in a consistent order
|
||||||
|
// This prevents default always choosing GLM provider when it shouldn't
|
||||||
|
orderedBases := []string{
|
||||||
|
cfg.Providers.OpenAI.APIBase,
|
||||||
|
cfg.Providers.Anthropic.APIBase,
|
||||||
|
cfg.Providers.Gemini.APIBase,
|
||||||
|
cfg.Providers.Groq.APIBase,
|
||||||
|
cfg.Providers.Zhipu.APIBase, // The GLM provider is lower in the order to prevent automatic defaulting
|
||||||
|
cfg.Providers.OpenRouter.APIBase,
|
||||||
|
cfg.Providers.LiteLLM.APIBase,
|
||||||
|
cfg.Providers.VLLM.APIBase,
|
||||||
|
}
|
||||||
|
for _, base := range orderedBases {
|
||||||
|
if base != "" {
|
||||||
|
sel.apiBase = base
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if sel.apiBase == "" {
|
if sel.apiBase == "" {
|
||||||
return providerSelection{}, fmt.Errorf("no API base configured for provider (model: %s)", model)
|
return providerSelection{}, fmt.Errorf("no API base configured for provider (model: %s)", model)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sel, nil
|
return sel, nil
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue