mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-30 06:45:55 +00:00
fix: include byteplus providers, guard None reasoning_effort, merge extra_body
- Add byteplus and byteplus_coding_plan to thinking param providers - Only send extra_body when reasoning_effort is explicitly set - Use setdefault().update() to avoid clobbering existing extra_body - Add 7 regression tests for thinking params Made-with: Cursor
This commit is contained in:
parent
bd94454b91
commit
ebf29d87ae
@ -297,22 +297,23 @@ class OpenAICompatProvider(LLMProvider):
|
|||||||
if reasoning_effort:
|
if reasoning_effort:
|
||||||
kwargs["reasoning_effort"] = reasoning_effort
|
kwargs["reasoning_effort"] = reasoning_effort
|
||||||
|
|
||||||
# Provider-specific thinking parameters
|
# Provider-specific thinking parameters.
|
||||||
if spec:
|
# Only sent when reasoning_effort is explicitly configured so that
|
||||||
# Refer: https://docs.byteplus.com/en/docs/ModelArk/1449737#adjust-reasoning-length
|
# the provider default is preserved otherwise.
|
||||||
# The agent will stop thinking if reasoning_effort is minimal or None. Otherwise, it will think.
|
if spec and reasoning_effort is not None:
|
||||||
thinking_enabled = (
|
thinking_enabled = reasoning_effort.lower() != "minimal"
|
||||||
reasoning_effort is not None and reasoning_effort.lower() != "minimal"
|
extra: dict[str, Any] | None = None
|
||||||
)
|
|
||||||
if spec.name == "dashscope":
|
if spec.name == "dashscope":
|
||||||
# Qwen: extra_body={"enable_thinking": True/False}
|
extra = {"enable_thinking": thinking_enabled}
|
||||||
kwargs["extra_body"] = {"enable_thinking": thinking_enabled}
|
elif spec.name in (
|
||||||
elif spec.name in ("volcengine", "volcengine_coding_plan"):
|
"volcengine", "volcengine_coding_plan",
|
||||||
# VolcEngine/Byteplus ModelArk: extra_body={"thinking": {"type": "enabled"/"disabled"}}
|
"byteplus", "byteplus_coding_plan",
|
||||||
kwargs["extra_body"] = {
|
):
|
||||||
|
extra = {
|
||||||
"thinking": {"type": "enabled" if thinking_enabled else "disabled"}
|
"thinking": {"type": "enabled" if thinking_enabled else "disabled"}
|
||||||
}
|
}
|
||||||
|
if extra:
|
||||||
|
kwargs.setdefault("extra_body", {}).update(extra)
|
||||||
|
|
||||||
if tools:
|
if tools:
|
||||||
kwargs["tools"] = tools
|
kwargs["tools"] = tools
|
||||||
|
|||||||
@ -307,3 +307,54 @@ async def test_openai_compat_stream_watchdog_returns_error_on_stall(monkeypatch)
|
|||||||
assert result.finish_reason == "error"
|
assert result.finish_reason == "error"
|
||||||
assert result.content is not None
|
assert result.content is not None
|
||||||
assert "stream stalled" in result.content
|
assert "stream stalled" in result.content
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Provider-specific thinking parameters (extra_body)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _build_kwargs_for(provider_name: str, model: str, reasoning_effort=None):
|
||||||
|
spec = find_by_name(provider_name)
|
||||||
|
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
|
||||||
|
p = OpenAICompatProvider(api_key="k", default_model=model, spec=spec)
|
||||||
|
return p._build_kwargs(
|
||||||
|
messages=[{"role": "user", "content": "hi"}],
|
||||||
|
tools=None, model=model, max_tokens=1024, temperature=0.7,
|
||||||
|
reasoning_effort=reasoning_effort, tool_choice=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dashscope_thinking_enabled_with_reasoning_effort() -> None:
|
||||||
|
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="medium")
|
||||||
|
assert kw["extra_body"] == {"enable_thinking": True}
|
||||||
|
|
||||||
|
|
||||||
|
def test_dashscope_thinking_disabled_for_minimal() -> None:
|
||||||
|
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="minimal")
|
||||||
|
assert kw["extra_body"] == {"enable_thinking": False}
|
||||||
|
|
||||||
|
|
||||||
|
def test_dashscope_no_extra_body_when_reasoning_effort_none() -> None:
|
||||||
|
kw = _build_kwargs_for("dashscope", "qwen-turbo", reasoning_effort=None)
|
||||||
|
assert "extra_body" not in kw
|
||||||
|
|
||||||
|
|
||||||
|
def test_volcengine_thinking_enabled() -> None:
|
||||||
|
kw = _build_kwargs_for("volcengine", "doubao-seed-2-0-pro", reasoning_effort="high")
|
||||||
|
assert kw["extra_body"] == {"thinking": {"type": "enabled"}}
|
||||||
|
|
||||||
|
|
||||||
|
def test_byteplus_thinking_disabled_for_minimal() -> None:
|
||||||
|
kw = _build_kwargs_for("byteplus", "doubao-seed-2-0-pro", reasoning_effort="minimal")
|
||||||
|
assert kw["extra_body"] == {"thinking": {"type": "disabled"}}
|
||||||
|
|
||||||
|
|
||||||
|
def test_byteplus_no_extra_body_when_reasoning_effort_none() -> None:
|
||||||
|
kw = _build_kwargs_for("byteplus", "doubao-seed-2-0-pro", reasoning_effort=None)
|
||||||
|
assert "extra_body" not in kw
|
||||||
|
|
||||||
|
|
||||||
|
def test_openai_no_thinking_extra_body() -> None:
|
||||||
|
"""Non-thinking providers should never get extra_body for thinking."""
|
||||||
|
kw = _build_kwargs_for("openai", "gpt-4o", reasoning_effort="medium")
|
||||||
|
assert "extra_body" not in kw
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user