Files
life-echo/api/app/adapters/llm/zhipu_eval_judge.py
Sully 53e0065e3e refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)
配置 SSOT(TOML + .env)
统一错误契约
Auth 与事务边界
Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client
可观测性(OpenTelemetry + LGTM)
2026-05-22 13:44:50 +08:00

39 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""智谱 GLM 评测台评审OpenAI 兼容端点 + ChatOpenAI 装配。"""
from __future__ import annotations
from langchain_openai import ChatOpenAI
from app.adapters.llm.openai_base_url import normalize_openai_compatible_base_url
from app.core.config import settings
from app.core.eval_judge_spec import EvalJudgeLlmSpec
from app.features.evaluation.constants import eval_cfg
def build_zhipu_eval_judge_spec(
judge_model: str | None,
) -> EvalJudgeLlmSpec | None:
"""密钥缺失时返回 None。"""
api_key = (settings.zhipu_api_key or "").strip()
if not api_key:
return None
want = (judge_model or "").strip()
base = normalize_openai_compatible_base_url(
eval_cfg.judge_base_url,
fallback="https://open.bigmodel.cn/api/paas/v4",
)
model = want or (eval_cfg.judge_model or "glm-5")
ctx = int(eval_cfg.judge_context_window_tokens)
llm_kw: dict = {
"api_key": api_key,
"base_url": base,
"model": model,
"temperature": eval_cfg.judge_temperature,
}
return EvalJudgeLlmSpec(
llm=ChatOpenAI(**llm_kw),
provider="zhipu",
resolved_model=model,
context_window_tokens=ctx,
)