zcbot/core/llm_params.py

38 lines
1.2 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,
clear_thinking: bool | None = 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)}"
)
thinking: dict[str, Any] = {
"type": "enabled" if enabled else "disabled"
}
if enabled and clear_thinking is not None:
thinking["clear_thinking"] = clear_thinking
body: dict[str, Any] = {"thinking": thinking}
if enabled and reasoning_effort:
body["reasoning_effort"] = reasoning_effort
return {"extra_body": body}