配置 SSOT(TOML + .env) 统一错误契约 Auth 与事务边界 Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client 可观测性(OpenTelemetry + LGTM)
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""智谱 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,
|
||
)
|