mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-07 04:38:18 +08:00
fix(llm): stop sending reasoning_effort=minimal as top-level param to providers that reject it
DeepSeek only accepts high / max / low / medium / xhigh for reasoning_effort, but the code unconditionally forwarded the configured value as a top-level parameter. When LLM_REASONING_EFFORT=minimal (DeepTutor convention for "disable thinking"), DeepSeek rejects the request with: unknown variant minimal, expected one of high, low, medium, max, xhigh Fix across three provider layers: - provider_core: skip top-level reasoning_effort when the provider spec has thinking_style and the semantic effort is "minimal" — the thinking control is already expressed via extra_body - tutorbot: same logic + add deepseek & minimax to the extra_body chain (they were missing, so thinking disable was silently ignored) - cloud_provider: skip reasoning_effort=minimal for providers that handle thinking through extra_body Other providers (OpenAI, Anthropic, Gemini, Mistral, etc.) are unaffected because they either don't have thinking_style or accept minimal natively.
This commit is contained in:
@@ -83,6 +83,19 @@ def _coerce_int(value: object, default: int | None) -> int | None:
|
||||
# Use lowercase to avoid constant redefinition warning
|
||||
_ssl_warning_logged = False
|
||||
|
||||
# Providers that handle thinking mode through extra_body (rather than
|
||||
# top-level reasoning_effort). "minimal" means disable thinking — these
|
||||
# providers reject the literal "minimal" value and expect extra_body instead.
|
||||
_BINDINGS_WITH_EXTRA_BODY_THINKING = frozenset({
|
||||
"deepseek",
|
||||
"dashscope",
|
||||
"volcengine",
|
||||
"volcengine_coding_plan",
|
||||
"byteplus",
|
||||
"byteplus_coding_plan",
|
||||
"minimax",
|
||||
})
|
||||
|
||||
|
||||
def _looks_like_unsupported_response_format(error_text: str) -> bool:
|
||||
"""Detect whether a 400 error body indicates ``response_format`` is unsupported.
|
||||
@@ -328,7 +341,12 @@ async def _openai_complete(
|
||||
data["response_format"] = response_format
|
||||
reasoning_effort = kwargs.get("reasoning_effort")
|
||||
if isinstance(reasoning_effort, str) and reasoning_effort.strip():
|
||||
data["reasoning_effort"] = reasoning_effort.strip()
|
||||
effort = reasoning_effort.strip()
|
||||
if not (
|
||||
effort.lower() == "minimal"
|
||||
and binding.lower() in _BINDINGS_WITH_EXTRA_BODY_THINKING
|
||||
):
|
||||
data["reasoning_effort"] = effort
|
||||
|
||||
timeout = aiohttp.ClientTimeout(total=120)
|
||||
connector = _get_aiohttp_connector()
|
||||
@@ -493,7 +511,12 @@ async def _openai_stream(
|
||||
data["response_format"] = response_format
|
||||
reasoning_effort = kwargs.get("reasoning_effort")
|
||||
if isinstance(reasoning_effort, str) and reasoning_effort.strip():
|
||||
data["reasoning_effort"] = reasoning_effort.strip()
|
||||
effort = reasoning_effort.strip()
|
||||
if not (
|
||||
effort.lower() == "minimal"
|
||||
and binding.lower() in _BINDINGS_WITH_EXTRA_BODY_THINKING
|
||||
):
|
||||
data["reasoning_effort"] = effort
|
||||
|
||||
timeout = aiohttp.ClientTimeout(total=300)
|
||||
connector = _get_aiohttp_connector()
|
||||
|
||||
@@ -308,7 +308,12 @@ class OpenAICompatProvider(LLMProvider):
|
||||
if spec and spec.name == "dashscope" and semantic_effort == "minimal":
|
||||
wire_effort = "minimum"
|
||||
|
||||
if wire_effort:
|
||||
# Providers with thinking_style handle thinking via extra_body.
|
||||
# "minimal" means disable thinking — only send via extra_body, never
|
||||
# as a top-level reasoning_effort (e.g. DeepSeek rejects it).
|
||||
if wire_effort and not (
|
||||
spec and spec.thinking_style and semantic_effort == "minimal"
|
||||
):
|
||||
kwargs["reasoning_effort"] = wire_effort
|
||||
|
||||
if spec and spec.thinking_style and reasoning_effort is not None:
|
||||
|
||||
@@ -257,12 +257,9 @@ class OpenAICompatProvider(LLMProvider):
|
||||
kwargs.update(overrides)
|
||||
break
|
||||
|
||||
if reasoning_effort:
|
||||
kwargs["reasoning_effort"] = reasoning_effort
|
||||
|
||||
extra: dict[str, Any] | None = None
|
||||
if spec and reasoning_effort is not None:
|
||||
thinking_enabled = reasoning_effort.lower() != "minimal"
|
||||
extra: dict[str, Any] | None = None
|
||||
if spec.name == "dashscope":
|
||||
extra = {"enable_thinking": thinking_enabled}
|
||||
elif spec.name in (
|
||||
@@ -270,11 +267,21 @@ class OpenAICompatProvider(LLMProvider):
|
||||
"volcengine_coding_plan",
|
||||
"byteplus",
|
||||
"byteplus_coding_plan",
|
||||
"deepseek",
|
||||
):
|
||||
extra = {"thinking": {"type": "enabled" if thinking_enabled else "disabled"}}
|
||||
elif spec.name == "minimax":
|
||||
extra = {"reasoning_split": thinking_enabled}
|
||||
if extra:
|
||||
kwargs.setdefault("extra_body", {}).update(extra)
|
||||
|
||||
# Providers that handle thinking via extra_body don't need a
|
||||
# top-level reasoning_effort when the intent is to disable thinking.
|
||||
if reasoning_effort and not (
|
||||
extra and reasoning_effort.lower() == "minimal"
|
||||
):
|
||||
kwargs["reasoning_effort"] = reasoning_effort
|
||||
|
||||
if tools:
|
||||
kwargs["tools"] = tools
|
||||
kwargs["tool_choice"] = tool_choice or "auto"
|
||||
|
||||
Reference in New Issue
Block a user