Fix: prioritize explicit provider prefixes and update max_tokens schema

This commit is contained in:
Only_Xianzo
2026-02-11 19:20:34 +05:30
committed by lxowalle
parent 4f51441a3b
commit 6ccd9d0a99

View File

@@ -50,8 +50,13 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too
} }
if maxTokens, ok := options["max_tokens"].(int); ok { if maxTokens, ok := options["max_tokens"].(int); ok {
lowerModel := strings.ToLower(model)
if strings.Contains(lowerModel, "glm") || strings.Contains(lowerModel, "o1") {
requestBody["max_completion_tokens"] = maxTokens
} else {
requestBody["max_tokens"] = maxTokens requestBody["max_tokens"] = maxTokens
} }
}
if temperature, ok := options["temperature"].(float64); ok { if temperature, ok := options["temperature"].(float64); ok {
requestBody["temperature"] = temperature requestBody["temperature"] = temperature
@@ -181,35 +186,35 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
apiBase = "https://openrouter.ai/api/v1" apiBase = "https://openrouter.ai/api/v1"
} }
case strings.Contains(lowerModel, "claude") || strings.HasPrefix(model, "anthropic/"): case (strings.Contains(lowerModel, "claude") || strings.HasPrefix(model, "anthropic/")) && cfg.Providers.Anthropic.APIKey != "":
apiKey = cfg.Providers.Anthropic.APIKey apiKey = cfg.Providers.Anthropic.APIKey
apiBase = cfg.Providers.Anthropic.APIBase apiBase = cfg.Providers.Anthropic.APIBase
if apiBase == "" { if apiBase == "" {
apiBase = "https://api.anthropic.com/v1" apiBase = "https://api.anthropic.com/v1"
} }
case strings.Contains(lowerModel, "gpt") || strings.HasPrefix(model, "openai/"): case (strings.Contains(lowerModel, "gpt") || strings.HasPrefix(model, "openai/")) && cfg.Providers.OpenAI.APIKey != "":
apiKey = cfg.Providers.OpenAI.APIKey apiKey = cfg.Providers.OpenAI.APIKey
apiBase = cfg.Providers.OpenAI.APIBase apiBase = cfg.Providers.OpenAI.APIBase
if apiBase == "" { if apiBase == "" {
apiBase = "https://api.openai.com/v1" apiBase = "https://api.openai.com/v1"
} }
case strings.Contains(lowerModel, "gemini") || strings.HasPrefix(model, "google/"): case (strings.Contains(lowerModel, "gemini") || strings.HasPrefix(model, "google/")) && cfg.Providers.Gemini.APIKey != "":
apiKey = cfg.Providers.Gemini.APIKey apiKey = cfg.Providers.Gemini.APIKey
apiBase = cfg.Providers.Gemini.APIBase apiBase = cfg.Providers.Gemini.APIBase
if apiBase == "" { if apiBase == "" {
apiBase = "https://generativelanguage.googleapis.com/v1beta" apiBase = "https://generativelanguage.googleapis.com/v1beta"
} }
case strings.Contains(lowerModel, "glm") || strings.Contains(lowerModel, "zhipu") || strings.Contains(lowerModel, "zai"): case (strings.Contains(lowerModel, "glm") || strings.Contains(lowerModel, "zhipu") || strings.Contains(lowerModel, "zai")) && cfg.Providers.Zhipu.APIKey != "":
apiKey = cfg.Providers.Zhipu.APIKey apiKey = cfg.Providers.Zhipu.APIKey
apiBase = cfg.Providers.Zhipu.APIBase apiBase = cfg.Providers.Zhipu.APIBase
if apiBase == "" { if apiBase == "" {
apiBase = "https://open.bigmodel.cn/api/paas/v4" apiBase = "https://open.bigmodel.cn/api/paas/v4"
} }
case strings.Contains(lowerModel, "groq") || strings.HasPrefix(model, "groq/"): case (strings.Contains(lowerModel, "groq") || strings.HasPrefix(model, "groq/")) && cfg.Providers.Groq.APIKey != "":
apiKey = cfg.Providers.Groq.APIKey apiKey = cfg.Providers.Groq.APIKey
apiBase = cfg.Providers.Groq.APIBase apiBase = cfg.Providers.Groq.APIBase
if apiBase == "" { if apiBase == "" {