fix(providers): inject OpenRouter reasoning.effort for thinking models
Follow-up to #3851: that PR added `extra_body.thinking={type: disabled}` for MiMo via OpenRouter, but OR doesn't forward provider-specific thinking shapes to upstream — it strips unknown extra_body fields and uses its own unified `reasoning` parameter. So MiMo via OR kept thinking despite the injection (reproduced by @ClearPlume on #3851 with identical kwargs but provider switched from openrouter → xiaomi_mimo). For known thinking-capable models (Kimi, MiMo) routed via the openrouter spec, also inject `extra_body.reasoning = {effort: <effort>}` in OR's documented enum ("none"|"minimal"|"low"|"medium"|"high"|"xhigh"). OR translates this to the upstream model's native shape. Existing tests updated to expect both fields on the OR path. The direct xiaomi_mimo and moonshot paths are unchanged (the new branch is gated on spec.name == "openrouter"). Flash and non-MiMo models on OR continue to receive no injection.
This commit is contained in:
@@ -615,6 +615,27 @@ class OpenAICompatProvider(LLMProvider):
|
||||
{"thinking": {"type": "enabled" if thinking_enabled else "disabled"}}
|
||||
)
|
||||
|
||||
# OpenRouter uses its own unified `reasoning` field and does not
|
||||
# forward provider-specific thinking shapes (the Kimi/MiMo
|
||||
# extra_body.thinking above) to upstream. Reported as the follow-up
|
||||
# to #3845/#3851: MiMo via OR kept thinking despite our injection.
|
||||
# For known thinking-capable models routed via OR, mirror the
|
||||
# effort signal into reasoning.effort (OR's documented enum:
|
||||
# "none"|"minimal"|"low"|"medium"|"high"|"xhigh"), which OR
|
||||
# translates to the upstream model's native shape.
|
||||
if (
|
||||
spec
|
||||
and spec.name == "openrouter"
|
||||
and reasoning_effort is not None
|
||||
and (
|
||||
_is_kimi_thinking_model(model_name)
|
||||
or _is_mimo_thinking_model(model_name)
|
||||
)
|
||||
):
|
||||
kwargs.setdefault("extra_body", {}).update(
|
||||
{"reasoning": {"effort": semantic_effort}}
|
||||
)
|
||||
|
||||
if tools:
|
||||
kwargs["tools"] = tools
|
||||
kwargs["tool_choice"] = tool_choice or "auto"
|
||||
|
||||
Reference in New Issue
Block a user