Files
MineNasAI/src/minenasai/llm/clients/zhipu.py

52 lines
1.3 KiB
Python

"""智谱 GLM 客户端
智谱 AI 使用 OpenAI 兼容接口
"""
from __future__ import annotations
from minenasai.llm.base import Provider
from minenasai.llm.clients.openai_compat import OpenAICompatClient
class ZhipuClient(OpenAICompatClient):
"""智谱 GLM 客户端
智谱 API 兼容 OpenAI 接口格式
官方文档: https://open.bigmodel.cn/dev/api
"""
provider = Provider.ZHIPU
default_model = "glm-4-plus"
MODELS = [
"glm-4-plus", # 最新旗舰
"glm-4-0520", # GLM-4
"glm-4-air", # 高性价比
"glm-4-airx", # 极速版
"glm-4-long", # 长文本
"glm-4-flash", # 免费版
"glm-4v-plus", # 多模态
"codegeex-4", # 代码模型
]
def __init__(
self,
api_key: str,
base_url: str | None = None,
proxy: str | None = None,
timeout: float = 60.0,
max_retries: int = 3,
) -> None:
super().__init__(
api_key=api_key,
base_url=base_url or "https://open.bigmodel.cn/api/paas/v4",
proxy=proxy,
timeout=timeout,
max_retries=max_retries,
provider=Provider.ZHIPU,
)
def get_available_models(self) -> list[str]:
return self.MODELS