zcbot/core/llm_params.py

31 lines
1.0 KiB
Python

"""跨 provider 的可选 LLM 请求参数构造。"""
from __future__ import annotations
from typing import Any
THINKING_TRANSPORTS = {"none", "extra_body"}
def build_thinking_kwargs(
*, enabled: bool, transport: str, reasoning_effort: str | None
) -> dict[str, Any]:
"""把统一的 thinking 配置转换为 LiteLLM 调用参数。
``none`` 表示该模型没有经过验证的显式控制协议,不猜 provider 默认值。
``extra_body`` 对应当前 DeepSeek、GLM 与方舟 ChatCompletions 的共同协议;
effort 仅在开启且档案提供非空值时发送。
"""
if transport == "none":
return {}
if transport != "extra_body":
raise ValueError(
f"不支持的 thinking_transport={transport!r};可选: {sorted(THINKING_TRANSPORTS)}"
)
body: dict[str, Any] = {
"thinking": {"type": "enabled" if enabled else "disabled"}
}
if enabled and reasoning_effort:
body["reasoning_effort"] = reasoning_effort
return {"extra_body": body}