This commit is contained in:
Yudi Hertanto 2026-03-25 14:44:42 +07:00 committed by GitHub
commit ddafbee209
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 66 additions and 1 deletions

View File

@ -4,3 +4,4 @@ GOOGLE_API_KEY=
ANTHROPIC_API_KEY=
XAI_API_KEY=
OPENROUTER_API_KEY=
ZAI_API_KEY=

View File

@ -127,6 +127,7 @@ export GOOGLE_API_KEY=... # Google (Gemini)
export ANTHROPIC_API_KEY=... # Anthropic (Claude)
export XAI_API_KEY=... # xAI (Grok)
export OPENROUTER_API_KEY=... # OpenRouter
export ZAI_API_KEY=... # Z.AI (GLM)
export ALPHA_VANTAGE_API_KEY=... # Alpha Vantage
```

View File

@ -162,6 +162,9 @@ def select_shallow_thinking_agent(provider) -> str:
("Grok 4 Fast (Non-Reasoning) - Speed optimized", "grok-4-fast-non-reasoning"),
("Grok 4.1 Fast (Reasoning) - High-performance, 2M ctx", "grok-4-1-fast-reasoning"),
],
"zai": [
("GLM-5 - Balanced fast research model", "glm-5"),
],
"openrouter": [
("NVIDIA Nemotron 3 Nano 30B (free)", "nvidia/nemotron-3-nano-30b-a3b:free"),
("Z.AI GLM 4.5 Air (free)", "z-ai/glm-4.5-air:free"),
@ -229,6 +232,9 @@ def select_deep_thinking_agent(provider) -> str:
("Grok 4 Fast (Reasoning) - High-performance", "grok-4-fast-reasoning"),
("Grok 4.1 Fast (Non-Reasoning) - Speed optimized, 2M ctx", "grok-4-1-fast-non-reasoning"),
],
"zai": [
("GLM-5 - Flagship research model", "glm-5"),
],
"openrouter": [
("Z.AI GLM 4.5 Air (free)", "z-ai/glm-4.5-air:free"),
("NVIDIA Nemotron 3 Nano 30B (free)", "nvidia/nemotron-3-nano-30b-a3b:free"),
@ -270,6 +276,7 @@ def select_llm_provider() -> tuple[str, str]:
("Google", "https://generativelanguage.googleapis.com/v1"),
("Anthropic", "https://api.anthropic.com/"),
("xAI", "https://api.x.ai/v1"),
("Zai", "https://api.z.ai/api/coding/paas/v4"),
("Openrouter", "https://openrouter.ai/api/v1"),
("Ollama", "http://localhost:11434/v1"),
]

View File

@ -4,6 +4,7 @@ from .base_client import BaseLLMClient
from .openai_client import OpenAIClient
from .anthropic_client import AnthropicClient
from .google_client import GoogleClient
from .zai_client import ZAIClient
def create_llm_client(
@ -15,7 +16,7 @@ def create_llm_client(
"""Create an LLM client for the specified provider.
Args:
provider: LLM provider (openai, anthropic, google, xai, ollama, openrouter)
provider: LLM provider (openai, anthropic, google, xai, ollama, openrouter, zai)
model: Model name/identifier
base_url: Optional base URL for API endpoint
**kwargs: Additional provider-specific arguments
@ -46,4 +47,7 @@ def create_llm_client(
if provider_lower == "google":
return GoogleClient(model, base_url, **kwargs)
if provider_lower == "zai":
return ZAIClient(model, base_url, **kwargs)
raise ValueError(f"Unsupported LLM provider: {provider}")

View File

@ -48,6 +48,9 @@ VALID_MODELS = {
"grok-4-fast-reasoning",
"grok-4-fast-non-reasoning",
],
"zai": [
"glm-5",
],
}

View File

@ -0,0 +1,49 @@
import os
from typing import Any, Optional
from langchain_openai import ChatOpenAI
from .base_client import BaseLLMClient
from .validators import validate_model
class ZAIClient(BaseLLMClient):
"""Client for Z.AI GLM models over the OpenAI-compatible API."""
DEFAULT_BASE_URL = "https://api.z.ai/api/coding/paas/v4"
def __init__(self, model: str, base_url: Optional[str] = None, **kwargs):
super().__init__(model, base_url, **kwargs)
def get_llm(self) -> Any:
"""Return configured ChatOpenAI instance for Z.AI."""
llm_kwargs = {
"model": self.model,
"base_url": self.base_url or self.DEFAULT_BASE_URL,
}
api_key = self.kwargs.get("api_key")
if api_key is None:
api_key = os.environ.get("ZAI_API_KEY")
if api_key:
llm_kwargs["api_key"] = api_key
for key in (
"timeout",
"max_retries",
"callbacks",
"http_client",
"http_async_client",
"temperature",
"top_p",
"extra_body",
):
if key in self.kwargs:
llm_kwargs[key] = self.kwargs[key]
return ChatOpenAI(**llm_kwargs)
def validate_model(self) -> bool:
"""Validate model for Z.AI."""
return validate_model("zai", self.model)