fix(llm): clamp an explicit thinking-off request the same way an inferred one is

#1366 gave the book's reader-facing blocks a way to ask for no thinking
at all, and the merge in 4e2f0885 now carries that explicit effort into
the retry as well — so a family that answers HTTP 400 to
reasoning_effort="none" (#734: gemini-3, gemini-2.5-pro) would fail
twice per block instead of once.

The narrowing table already existed, but only inside
default_reasoning_effort_for, which is consulted when the caller says
nothing. A caller that names "none" itself skipped it. Names the rule as
thinking_off_effort_for and routes an explicit "none" through it too,
next to _MINIMAL_NOT_OFF_PATTERNS so extending one table still prompts a
look at the other.

Verified: gemini-3-pro / gemini-2.5-pro resolve to minimal;
gemini-2.5-flash and gpt-4o keep none.

Patch authored in the PR-review session.
This commit is contained in:
Bingxi Zhao (Frank)
2026-09-11 00:00:14 +08:00
parent 3d2648d01b
commit b244a0c868
2 changed files with 51 additions and 0 deletions

View File

@@ -117,6 +117,24 @@ def default_reasoning_effort_for(provider: str | None, model: str | None) -> str
return None
def thinking_off_effort_for(provider: str | None, model: str | None) -> str:
"""The lowest effort *model* actually accepts as "thinking off".
``"none"`` for almost everything, ``"minimal"`` for the families that
answer HTTP 400 to it (#734). The rule already existed inside
:func:`default_reasoning_effort_for`, but that function is consulted only
when the caller says nothing — so a caller that asks for ``"none"``
itself, as the reader-facing book blocks do, skipped the narrowing and got
the 400 the table exists to prevent. Naming it here keeps it beside
:data:`_MINIMAL_NOT_OFF_PATTERNS`, so adding a family to that table is
still an obvious prompt to check this one.
"""
provider_name = (provider or "").strip().lower()
if _matches(model or "", _MINIMAL_NOT_OFF_PATTERNS.get(provider_name, ())):
return "minimal"
return "none"
def build_openai_compatible_reasoning_kwargs(
*,
spec: Any,
@@ -156,6 +174,10 @@ def build_openai_compatible_reasoning_kwargs(
resolved_effort = "high"
else:
resolved_effort = default_reasoning_effort_for(provider_name, model_name)
elif str(resolved_effort).strip().lower() == "none":
# An explicit "off" is subject to the same vendor limit as an inferred
# one — see ``thinking_off_effort_for``.
resolved_effort = thinking_off_effort_for(provider_name, model_name)
semantic_effort: str | None = None
if isinstance(resolved_effort, str):

View File

@@ -93,3 +93,32 @@ class TestBuildOpenAICompatibleReasoningKwargsForGemini:
spec=None, binding="openai", model="gpt-4o", reasoning_effort=None
)
assert kwargs == {}
def test_an_explicitly_requested_off_is_narrowed_like_an_inferred_one() -> None:
"""A caller that names ``"none"`` gets the same vendor limit as one that
says nothing.
``default_reasoning_effort_for`` narrowed ``"none"`` to ``"minimal"`` for
the Gemini families that answer HTTP 400 to it (#734), but it only ran
when the caller passed nothing. The reader-facing Book blocks name
``"none"`` on purpose — so they bypassed the narrowing and shipped the
exact 400 the table exists to prevent.
"""
from deeptutor.services.llm.reasoning_params import (
build_openai_compatible_reasoning_kwargs,
thinking_off_effort_for,
)
def effort(model: str) -> str | None:
kwargs = build_openai_compatible_reasoning_kwargs(
spec=None, binding="gemini", model=model, reasoning_effort="none"
)
return kwargs.get("reasoning_effort")
assert effort("gemini-3-pro") == "minimal"
assert effort("gemini-2.5-pro") == "minimal"
# A sibling that does accept "none" keeps it, and so does everyone else.
assert effort("gemini-2.5-flash") == "none"
assert thinking_off_effort_for("openai", "gpt-4o") == "none"
assert thinking_off_effort_for(None, None) == "none"