Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
"api_key": "YOUR_ZHIPU_API_KEY",
"api_base": ""
},
"zai": {
"api_key": "YOUR_ZAI_API_KEY",
"api_base": ""
},
"gemini": {
"api_key": "",
"api_base": ""
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ type ProvidersConfig struct {
OpenRouter ProviderConfig `json:"openrouter"`
Groq ProviderConfig `json:"groq"`
Zhipu ProviderConfig `json:"zhipu"`
ZAI ProviderConfig `json:"zai"`
VLLM ProviderConfig `json:"vllm"`
Gemini ProviderConfig `json:"gemini"`
Nvidia ProviderConfig `json:"nvidia"`
Expand Down Expand Up @@ -299,6 +300,7 @@ func DefaultConfig() *Config {
OpenRouter: ProviderConfig{},
Groq: ProviderConfig{},
Zhipu: ProviderConfig{},
ZAI: ProviderConfig{},
VLLM: ProviderConfig{},
Gemini: ProviderConfig{},
Nvidia: ProviderConfig{},
Expand Down Expand Up @@ -396,6 +398,9 @@ func (c *Config) GetAPIKey() string {
if c.Providers.Zhipu.APIKey != "" {
return c.Providers.Zhipu.APIKey
}
if c.Providers.ZAI.APIKey != "" {
return c.Providers.ZAI.APIKey
}
if c.Providers.Groq.APIKey != "" {
return c.Providers.Groq.APIKey
}
Expand Down
29 changes: 27 additions & 2 deletions pkg/providers/http_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *HTTPProvider) Chat(ctx context.Context, messages []Message, tools []Too
// Strip provider prefix from model name (e.g., moonshot/kimi-k2.5 -> kimi-k2.5)
if idx := strings.Index(model, "/"); idx != -1 {
prefix := model[:idx]
if prefix == "moonshot" || prefix == "nvidia" {
if prefix == "moonshot" || prefix == "nvidia" || prefix == "zai" {
model = model[idx+1:]
}
}
Expand Down Expand Up @@ -277,6 +277,19 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
apiBase = "https://open.bigmodel.cn/api/paas/v4"
}
}
case "zai", "z.ai":
if cfg.Providers.ZAI.APIKey != "" {
apiKey = cfg.Providers.ZAI.APIKey
apiBase = cfg.Providers.ZAI.APIBase
proxy = cfg.Providers.ZAI.Proxy
if apiBase == "" {
if strings.Contains(lowerModel, "coding") {
apiBase = "https://api.z.ai/api/coding/paas/v4"
} else {
apiBase = "https://api.z.ai/api/paas/v4"
}
}
}
case "gemini", "google":
if cfg.Providers.Gemini.APIKey != "" {
apiKey = cfg.Providers.Gemini.APIKey
Expand Down Expand Up @@ -377,7 +390,19 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
apiBase = "https://generativelanguage.googleapis.com/v1beta"
}

case (strings.Contains(lowerModel, "glm") || strings.Contains(lowerModel, "zhipu") || strings.Contains(lowerModel, "zai")) && cfg.Providers.Zhipu.APIKey != "":
case (strings.Contains(lowerModel, "glm") || strings.Contains(lowerModel, "cogview") || strings.Contains(lowerModel, "cogvideo") || strings.Contains(lowerModel, "autoglm") || strings.Contains(lowerModel, "vidu")) && cfg.Providers.ZAI.APIKey != "":
apiKey = cfg.Providers.ZAI.APIKey
apiBase = cfg.Providers.ZAI.APIBase
proxy = cfg.Providers.ZAI.Proxy
if apiBase == "" {
if strings.Contains(lowerModel, "coding") {
apiBase = "https://api.z.ai/api/coding/paas/v4"
} else {
apiBase = "https://api.z.ai/api/paas/v4"
}
}

case (strings.Contains(lowerModel, "glm") || strings.Contains(lowerModel, "zhipu")) && cfg.Providers.Zhipu.APIKey != "":
apiKey = cfg.Providers.Zhipu.APIKey
apiBase = cfg.Providers.Zhipu.APIBase
proxy = cfg.Providers.Zhipu.Proxy
Expand Down