fix(providers): omit Kimi K2.5/K2.6 temperature

This commit is contained in:
bingqilinweimaotai 2026-07-17 17:10:40 +08:00 committed by chengyongru
parent b4adb29c2b
commit 8a48af7c74
3 changed files with 24 additions and 7 deletions

View File

@ -71,6 +71,10 @@ _KIMI_ALWAYS_THINKING_MODELS: frozenset[str] = frozenset({
"kimi-k2.7-code", "kimi-k2.7-code",
"kimi-k2.7-code-highspeed", "kimi-k2.7-code-highspeed",
}) })
_KIMI_SERVER_MANAGED_TEMPERATURE_MODELS: frozenset[str] = frozenset({
"kimi-k2.5",
"kimi-k2.6",
})
_TEXT_TOOL_CALL_RE = re.compile(r"<tool_call>\s*(.*?)\s*</tool_call>", re.DOTALL) _TEXT_TOOL_CALL_RE = re.compile(r"<tool_call>\s*(.*?)\s*</tool_call>", re.DOTALL)
# Thinking-capable MiMo models per Xiaomi docs (see # Thinking-capable MiMo models per Xiaomi docs (see
# tests/providers/test_xiaomi_mimo_thinking.py). mimo-v2-flash is omitted # tests/providers/test_xiaomi_mimo_thinking.py). mimo-v2-flash is omitted
@ -764,6 +768,16 @@ class OpenAICompatProvider(LLMProvider):
kwargs.update(overrides) kwargs.update(overrides)
break break
# Moonshot selects the only valid temperature from the K2.5/K2.6 thinking mode:
# 1.0 when enabled and 0.6 when disabled. Omitting the parameter lets the API
# apply the matching value for both its default and explicit thinking controls.
if (
spec
and spec.name == "moonshot"
and _model_slug(model_name) in _KIMI_SERVER_MANAGED_TEMPERATURE_MODELS
):
kwargs.pop("temperature", None)
# Normalize reasoning_effort into a semantic form (OpenAI vocab) # Normalize reasoning_effort into a semantic form (OpenAI vocab)
# used for internal decisions, and a wire form actually sent out. # used for internal decisions, and a wire form actually sent out.
# "minimum" is accepted as a DashScope-native alias for "minimal". # "minimum" is accepted as a DashScope-native alias for "minimal".

View File

@ -471,7 +471,8 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
default_api_base="https://dashscope.aliyuncs.com/compatible-mode/v1", default_api_base="https://dashscope.aliyuncs.com/compatible-mode/v1",
thinking_style="enable_thinking", thinking_style="enable_thinking",
), ),
# Moonshot (月之暗面): Kimi K2.5+ enforce temperature >= 1.0. # Moonshot (月之暗面): Kimi K2.5/K2.6 choose temperature from thinking mode;
# the OpenAI-compatible provider omits it. K2.7 models require 1.0.
ProviderSpec( ProviderSpec(
name="moonshot", name="moonshot",
keywords=("moonshot", "kimi"), keywords=("moonshot", "kimi"),
@ -480,8 +481,6 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
backend="openai_compat", backend="openai_compat",
default_api_base="https://api.moonshot.ai/v1", default_api_base="https://api.moonshot.ai/v1",
model_overrides=( model_overrides=(
("kimi-k2.5", {"temperature": 1.0}),
("kimi-k2.6", {"temperature": 1.0}),
("kimi-k2.7", {"temperature": 1.0}), ("kimi-k2.7", {"temperature": 1.0}),
("kimi-k2.7-code", {"temperature": 1.0}), ("kimi-k2.7-code", {"temperature": 1.0}),
("kimi-k2.7-code-highspeed", {"temperature": 1.0}), ("kimi-k2.7-code-highspeed", {"temperature": 1.0}),

View File

@ -1604,10 +1604,14 @@ def test_kimi_k27_code_thinking_none_with_openrouter_prefix_omits_disabled() ->
assert "reasoning_effort" not in kw assert "reasoning_effort" not in kw
def test_moonshot_kimi_k26_temperature_override() -> None: @pytest.mark.parametrize("model", ["kimi-k2.5", "kimi-k2.6"])
"""Moonshot registry forces temperature 1.0 for kimi-k2.6 (API requirement).""" @pytest.mark.parametrize("reasoning_effort", [None, "none", "minimal", "medium", "high"])
kw = _build_kwargs_for("moonshot", "kimi-k2.6", reasoning_effort=None) def test_moonshot_kimi_k25_k26_omit_temperature(
assert kw["temperature"] == 1.0 model: str, reasoning_effort: str | None,
) -> None:
"""Moonshot chooses the valid temperature from the K2.5/K2.6 thinking mode."""
kw = _build_kwargs_for("moonshot", model, reasoning_effort=reasoning_effort)
assert "temperature" not in kw
def test_moonshot_kimi_k27_code_temperature_override() -> None: def test_moonshot_kimi_k27_code_temperature_override() -> None: