Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

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

Bingxi Zhao (Frank)b244a0c868cb
diff --git a/deeptutor/services/llm/reasoning_params.py b/deeptutor/services/llm/reasoning_params.py
index 936a72941..97fca9f3e 100644
--- a/deeptutor/services/llm/reasoning_params.py
+++ b/deeptutor/services/llm/reasoning_params.py
@@ -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):
diff --git a/tests/services/llm/test_reasoning_params.py b/tests/services/llm/test_reasoning_params.py
index 1cdd40ae1..8c70884fb 100644
--- a/tests/services/llm/test_reasoning_params.py
+++ b/tests/services/llm/test_reasoning_params.py
@@ -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"