mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 17:38:35 +00:00
review(providers): tighten comments in reasoning_effort normalize path
Made-with: Cursor
This commit is contained in:
parent
28c42628b0
commit
88c619901e
@ -387,16 +387,9 @@ class OpenAICompatProvider(LLMProvider):
|
|||||||
kwargs.update(overrides)
|
kwargs.update(overrides)
|
||||||
break
|
break
|
||||||
|
|
||||||
# Semantic vs. wire distinction for reasoning_effort.
|
# Normalize reasoning_effort into a semantic form (OpenAI vocab)
|
||||||
# - semantic_effort is nanobot's internal canonical form (OpenAI's
|
# used for internal decisions, and a wire form actually sent out.
|
||||||
# vocabulary: "minimal" / "low" / "medium" / "high"). It drives
|
# "minimum" is accepted as a DashScope-native alias for "minimal".
|
||||||
# decisions like whether to disable provider thinking modes.
|
|
||||||
# - wire_effort is what we actually serialize to the provider; some
|
|
||||||
# providers (notably DashScope) reject "minimal" and require
|
|
||||||
# "minimum" instead. We accept either spelling on input and
|
|
||||||
# always compare on the semantic form so a user who configured
|
|
||||||
# "minimum" (DashScope's native spelling) still gets thinking
|
|
||||||
# disabled instead of accidentally enabled.
|
|
||||||
semantic_effort: str | None = None
|
semantic_effort: str | None = None
|
||||||
if isinstance(reasoning_effort, str):
|
if isinstance(reasoning_effort, str):
|
||||||
semantic_effort = reasoning_effort.lower()
|
semantic_effort = reasoning_effort.lower()
|
||||||
@ -405,9 +398,7 @@ class OpenAICompatProvider(LLMProvider):
|
|||||||
|
|
||||||
wire_effort = reasoning_effort
|
wire_effort = reasoning_effort
|
||||||
if spec and spec.name == "dashscope" and semantic_effort == "minimal":
|
if spec and spec.name == "dashscope" and semantic_effort == "minimal":
|
||||||
# DashScope's reasoning_effort.effort enum accepts: none /
|
# DashScope accepts none/minimum/low/medium/high/xhigh; "minimal" 400s.
|
||||||
# minimum / low / medium / high / xhigh. Literal "minimal"
|
|
||||||
# returns 400 invalid_value; translate on the outbound side.
|
|
||||||
wire_effort = "minimum"
|
wire_effort = "minimum"
|
||||||
|
|
||||||
if wire_effort:
|
if wire_effort:
|
||||||
|
|||||||
@ -731,28 +731,21 @@ def test_dashscope_thinking_enabled_with_reasoning_effort() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_dashscope_thinking_disabled_for_minimal() -> None:
|
def test_dashscope_thinking_disabled_for_minimal() -> None:
|
||||||
"""OpenAI-style 'minimal' → DashScope wire value 'minimum' + thinking off.
|
"""'minimal' → wire 'minimum' + thinking off on DashScope."""
|
||||||
DashScope rejects the literal string 'minimal' (invalid_value), so we
|
|
||||||
must translate on the outbound side while still honouring the 'no
|
|
||||||
thinking' intent via extra_body."""
|
|
||||||
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="minimal")
|
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="minimal")
|
||||||
assert kw["reasoning_effort"] == "minimum"
|
assert kw["reasoning_effort"] == "minimum"
|
||||||
assert kw["extra_body"] == {"enable_thinking": False}
|
assert kw["extra_body"] == {"enable_thinking": False}
|
||||||
|
|
||||||
|
|
||||||
def test_dashscope_thinking_disabled_for_minimum_alias() -> None:
|
def test_dashscope_thinking_disabled_for_minimum_alias() -> None:
|
||||||
"""Users who read DashScope docs may configure the native 'minimum'
|
"""Native 'minimum' spelling must also disable thinking, not enable it."""
|
||||||
spelling. Internally it's the same semantic as 'minimal' → thinking
|
|
||||||
must still be disabled (not enabled just because the string isn't
|
|
||||||
literally 'minimal')."""
|
|
||||||
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="minimum")
|
kw = _build_kwargs_for("dashscope", "qwen3-plus", reasoning_effort="minimum")
|
||||||
assert kw["reasoning_effort"] == "minimum"
|
assert kw["reasoning_effort"] == "minimum"
|
||||||
assert kw["extra_body"] == {"enable_thinking": False}
|
assert kw["extra_body"] == {"enable_thinking": False}
|
||||||
|
|
||||||
|
|
||||||
def test_non_dashscope_minimal_not_retranslated() -> None:
|
def test_non_dashscope_minimal_not_retranslated() -> None:
|
||||||
"""The DashScope-specific translation must not leak to other providers;
|
"""DashScope-specific translation must not leak to other providers."""
|
||||||
OpenAI / Anthropic / etc. speak 'minimal' natively."""
|
|
||||||
kw = _build_kwargs_for("openai", "gpt-5", reasoning_effort="minimal")
|
kw = _build_kwargs_for("openai", "gpt-5", reasoning_effort="minimal")
|
||||||
assert kw["reasoning_effort"] == "minimal"
|
assert kw["reasoning_effort"] == "minimal"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user