mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-09 08:21:50 +00:00
fix(opencode-go): gate thinking when reasoning_effort set to avoid HTTP 400
Salvaged from #40429; re-verified on main, tightened, tested. Co-authored-by: jimjsong <jimjsong@users.noreply.github.com>
This commit is contained in:
parent
fe0b3f2338
commit
03392b67d6
2 changed files with 19 additions and 10 deletions
|
|
@ -64,9 +64,8 @@ class OpenCodeGoProfile(ProviderProfile):
|
|||
return extra_body, top_level
|
||||
|
||||
enabled = reasoning_config.get("enabled") is not False
|
||||
extra_body["thinking"] = {"type": "enabled" if enabled else "disabled"}
|
||||
|
||||
if not enabled:
|
||||
extra_body["thinking"] = {"type": "disabled"}
|
||||
return extra_body, top_level
|
||||
|
||||
effort = (reasoning_config.get("effort") or "").strip().lower()
|
||||
|
|
@ -74,6 +73,11 @@ class OpenCodeGoProfile(ProviderProfile):
|
|||
top_level["reasoning_effort"] = "high"
|
||||
elif effort in {"low", "medium", "high"}:
|
||||
top_level["reasoning_effort"] = effort
|
||||
|
||||
# Avoid "cannot specify both 'thinking' and 'reasoning_effort'" HTTP 400:
|
||||
# only send extra_body["thinking"] when no reasoning_effort is set.
|
||||
if "reasoning_effort" not in top_level:
|
||||
extra_body["thinking"] = {"type": "enabled"}
|
||||
return extra_body, top_level
|
||||
|
||||
if not _is_deepseek_thinking_model(model):
|
||||
|
|
@ -82,9 +86,9 @@ class OpenCodeGoProfile(ProviderProfile):
|
|||
enabled = True
|
||||
if isinstance(reasoning_config, dict) and reasoning_config.get("enabled") is False:
|
||||
enabled = False
|
||||
extra_body["thinking"] = {"type": "enabled" if enabled else "disabled"}
|
||||
|
||||
if not enabled:
|
||||
extra_body["thinking"] = {"type": "disabled"}
|
||||
return extra_body, top_level
|
||||
|
||||
if isinstance(reasoning_config, dict):
|
||||
|
|
@ -94,6 +98,11 @@ class OpenCodeGoProfile(ProviderProfile):
|
|||
elif effort in {"low", "medium", "high"}:
|
||||
top_level["reasoning_effort"] = effort
|
||||
|
||||
# Avoid "cannot specify both 'thinking' and 'reasoning_effort'" HTTP 400:
|
||||
# only send extra_body["thinking"] when no reasoning_effort is set.
|
||||
if "reasoning_effort" not in top_level:
|
||||
extra_body["thinking"] = {"type": "enabled"}
|
||||
|
||||
return extra_body, top_level
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class TestOpenCodeGoKimiReasoning:
|
|||
reasoning_config={"enabled": True, "effort": "high"},
|
||||
model="kimi-k2.6",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": "high"}
|
||||
|
||||
def test_disabled_emits_thinking_disabled_without_effort(self, opencode_go_profile):
|
||||
|
|
@ -56,7 +56,7 @@ class TestOpenCodeGoKimiReasoning:
|
|||
reasoning_config={"enabled": True, "effort": effort},
|
||||
model="moonshotai/kimi-k2.6",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": "high"}
|
||||
|
||||
def test_low_and_medium_pass_through(self, opencode_go_profile):
|
||||
|
|
@ -65,7 +65,7 @@ class TestOpenCodeGoKimiReasoning:
|
|||
reasoning_config={"enabled": True, "effort": effort},
|
||||
model="kimi-k2.5",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": effort}
|
||||
|
||||
def test_no_config_preserves_server_default(self, opencode_go_profile):
|
||||
|
|
@ -85,7 +85,7 @@ class TestOpenCodeGoDeepSeekThinking:
|
|||
reasoning_config={"enabled": True, "effort": "high"},
|
||||
model="deepseek-v4-pro",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": "high"}
|
||||
|
||||
def test_disabled_emits_thinking_disabled_without_effort(self, opencode_go_profile):
|
||||
|
|
@ -118,7 +118,7 @@ class TestOpenCodeGoDeepSeekThinking:
|
|||
reasoning_config={"enabled": True, "effort": effort},
|
||||
model="deepseek/deepseek-v4-pro",
|
||||
)
|
||||
assert extra_body == {"thinking": {"type": "enabled"}}
|
||||
assert extra_body == {}
|
||||
assert top_level == {"reasoning_effort": "max"}
|
||||
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ class TestOpenCodeGoFullKwargsIntegration:
|
|||
reasoning_config={"enabled": True, "effort": "high"},
|
||||
base_url="https://opencode.ai/zen/go/v1",
|
||||
)
|
||||
assert kwargs["extra_body"] == {"thinking": {"type": "enabled"}}
|
||||
assert "extra_body" not in kwargs
|
||||
assert kwargs["reasoning_effort"] == "high"
|
||||
|
||||
def test_deepseek_thinking_reaches_extra_body_and_top_level(
|
||||
|
|
@ -176,5 +176,5 @@ class TestOpenCodeGoFullKwargsIntegration:
|
|||
reasoning_config={"enabled": True, "effort": "high"},
|
||||
base_url="https://opencode.ai/zen/go/v1",
|
||||
)
|
||||
assert kwargs["extra_body"] == {"thinking": {"type": "enabled"}}
|
||||
assert "extra_body" not in kwargs
|
||||
assert kwargs["reasoning_effort"] == "high"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue