mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 21:30:01 +08:00
fix(llm): scope reasoning fallback cache by endpoint and align DeepSeek Flash default_on
This commit is contained in:
@@ -21,6 +21,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable, Mapping
|
||||
import threading
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
# Provider capabilities configuration
|
||||
# Keys are binding names (lowercase), values are capability dictionaries
|
||||
@@ -568,28 +569,60 @@ def is_forced_tool_choice_disabled_at_runtime(
|
||||
return (binding.lower(), model.lower()) in _RUNTIME_DISABLED_FORCED_TOOL_CHOICE
|
||||
|
||||
|
||||
# Runtime cache for providers/models that reject reasoning/thinking parameters
|
||||
# (HTTP 400/422). Keyed by (binding_lower, model_lower) so multi-turn / tool-call
|
||||
# loops skip reasoning parameters directly after the first rejection instead of
|
||||
# paying a 400 round-trip on every turn.
|
||||
_RUNTIME_DISABLED_REASONING_PARAMS: set[tuple[str, str]] = set()
|
||||
# Runtime cache for endpoints/models that reject reasoning/thinking parameters
|
||||
# themselves (HTTP 400/422). Keyed by (binding_lower, model_lower, endpoint) so
|
||||
# multi-turn / tool-call loops skip unsupported parameters on the same endpoint
|
||||
# without leaking disablement across different relays that share a binding and
|
||||
# model ID.
|
||||
_RUNTIME_DISABLED_REASONING_PARAMS: set[tuple[str, str, str]] = set()
|
||||
|
||||
|
||||
def disable_reasoning_params_at_runtime(binding: str | None, model: str | None) -> None:
|
||||
"""Mark a (binding, model) pair as rejecting reasoning/thinking parameters."""
|
||||
def _normalize_runtime_endpoint(api_base: str | None) -> str:
|
||||
raw = str(api_base or "").strip()
|
||||
if not raw:
|
||||
return ""
|
||||
parsed = urlsplit(raw)
|
||||
if parsed.scheme and parsed.netloc:
|
||||
scheme = parsed.scheme.lower()
|
||||
netloc = parsed.netloc.lower()
|
||||
if (scheme == "https" and netloc.endswith(":443")) or (
|
||||
scheme == "http" and netloc.endswith(":80")
|
||||
):
|
||||
netloc = netloc.rsplit(":", 1)[0]
|
||||
path = parsed.path.rstrip("/")
|
||||
normalized = f"{scheme}://{netloc}{path}"
|
||||
if parsed.query:
|
||||
normalized = f"{normalized}?{parsed.query}"
|
||||
return normalized
|
||||
return raw.rstrip("/").lower()
|
||||
|
||||
|
||||
def disable_reasoning_params_at_runtime(
|
||||
binding: str | None,
|
||||
model: str | None,
|
||||
api_base: str | None = None,
|
||||
) -> None:
|
||||
"""Mark a (binding, model, endpoint) tuple as rejecting reasoning/thinking parameters."""
|
||||
if not binding or not model:
|
||||
return
|
||||
_RUNTIME_DISABLED_REASONING_PARAMS.add((binding.lower(), model.lower()))
|
||||
_RUNTIME_DISABLED_REASONING_PARAMS.add(
|
||||
(binding.lower(), model.lower(), _normalize_runtime_endpoint(api_base))
|
||||
)
|
||||
|
||||
|
||||
def is_reasoning_params_disabled_at_runtime(
|
||||
binding: str | None,
|
||||
model: str | None,
|
||||
api_base: str | None = None,
|
||||
) -> bool:
|
||||
"""Whether this pair was recorded by :func:`disable_reasoning_params_at_runtime`."""
|
||||
"""Whether this (binding, model, endpoint) was recorded by :func:`disable_reasoning_params_at_runtime`."""
|
||||
if not binding or not model:
|
||||
return False
|
||||
return (binding.lower(), model.lower()) in _RUNTIME_DISABLED_REASONING_PARAMS
|
||||
return (
|
||||
binding.lower(),
|
||||
model.lower(),
|
||||
_normalize_runtime_endpoint(api_base),
|
||||
) in _RUNTIME_DISABLED_REASONING_PARAMS
|
||||
|
||||
|
||||
def supports_response_format(binding: str, model: str | None = None) -> bool:
|
||||
|
||||
@@ -52,8 +52,8 @@ from deeptutor.services.llm.reasoning_params import (
|
||||
strip_reasoning_kwargs,
|
||||
)
|
||||
from deeptutor.services.llm.request_compat import (
|
||||
classify_reasoning_param_error,
|
||||
is_forced_tool_choice_unsupported,
|
||||
is_reasoning_param_unsupported,
|
||||
is_response_format_unsupported,
|
||||
)
|
||||
from deeptutor.services.llm.usage_frame import usage_breakdown
|
||||
@@ -586,7 +586,9 @@ class OpenAICompatProvider(LLMProvider):
|
||||
else:
|
||||
kwargs[key] = value
|
||||
|
||||
if not is_reasoning_params_disabled_at_runtime(self._binding_name(), model_name):
|
||||
if not is_reasoning_params_disabled_at_runtime(
|
||||
self._binding_name(), model_name, self._endpoint_base()
|
||||
):
|
||||
kwargs.update(
|
||||
build_openai_compatible_reasoning_kwargs(
|
||||
spec=spec,
|
||||
@@ -865,6 +867,23 @@ class OpenAICompatProvider(LLMProvider):
|
||||
spec = getattr(self, "_spec", None)
|
||||
return provider_name or (spec.name if spec else "openai")
|
||||
|
||||
def _endpoint_base(self) -> str:
|
||||
client = getattr(self, "_client", None)
|
||||
client_base = getattr(client, "base_url", None) if client is not None else None
|
||||
if isinstance(client_base, str) or (
|
||||
client_base is not None
|
||||
and hasattr(type(client_base), "scheme")
|
||||
and hasattr(type(client_base), "host")
|
||||
):
|
||||
base_text = str(client_base).strip()
|
||||
if base_text:
|
||||
return base_text
|
||||
effective = getattr(self, "_effective_base", None) or getattr(self, "api_base", None)
|
||||
if effective:
|
||||
return str(effective)
|
||||
spec = getattr(self, "_spec", None)
|
||||
return str(getattr(spec, "default_api_base", None) or "")
|
||||
|
||||
def _effective_tool_choice(
|
||||
self,
|
||||
tool_choice: str | dict[str, Any] | None,
|
||||
@@ -1241,7 +1260,7 @@ class OpenAICompatProvider(LLMProvider):
|
||||
)
|
||||
request_kwargs.update({k: v for k, v in extra_kwargs.items() if v is not None})
|
||||
if is_reasoning_params_disabled_at_runtime(
|
||||
self._binding_name(), request_kwargs.get("model")
|
||||
self._binding_name(), request_kwargs.get("model"), self._endpoint_base()
|
||||
):
|
||||
request_kwargs = strip_reasoning_kwargs(request_kwargs)
|
||||
try:
|
||||
@@ -1263,15 +1282,26 @@ class OpenAICompatProvider(LLMProvider):
|
||||
self._client.chat.completions.create, retry_kwargs
|
||||
)
|
||||
)
|
||||
if has_reasoning_kwargs(request_kwargs) and is_reasoning_param_unsupported(exc):
|
||||
disable_reasoning_params_at_runtime(
|
||||
self._binding_name(), request_kwargs.get("model")
|
||||
)
|
||||
logger.warning(
|
||||
"provider rejected reasoning parameters for model={}; retrying without reasoning params. error={}",
|
||||
request_kwargs.get("model"),
|
||||
str(exc)[:200],
|
||||
)
|
||||
if has_reasoning_kwargs(request_kwargs) and (
|
||||
reasoning_rejection := classify_reasoning_param_error(exc)
|
||||
):
|
||||
if reasoning_rejection == "param":
|
||||
disable_reasoning_params_at_runtime(
|
||||
self._binding_name(),
|
||||
request_kwargs.get("model"),
|
||||
self._endpoint_base(),
|
||||
)
|
||||
logger.warning(
|
||||
"provider rejected reasoning parameters for model={}; retrying without reasoning params. error={}",
|
||||
request_kwargs.get("model"),
|
||||
str(exc)[:200],
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"provider rejected reasoning parameter value for model={}; retrying once without reasoning params. error={}",
|
||||
request_kwargs.get("model"),
|
||||
str(exc)[:200],
|
||||
)
|
||||
retry_kwargs = strip_reasoning_kwargs(request_kwargs)
|
||||
return self._parse(
|
||||
await self._create_with_key_rotation(
|
||||
@@ -1488,7 +1518,7 @@ class OpenAICompatProvider(LLMProvider):
|
||||
if self._spec is None or self._spec.supports_stream_options:
|
||||
request_kwargs["stream_options"] = {"include_usage": True}
|
||||
if is_reasoning_params_disabled_at_runtime(
|
||||
self._binding_name(), request_kwargs.get("model")
|
||||
self._binding_name(), request_kwargs.get("model"), self._endpoint_base()
|
||||
):
|
||||
request_kwargs = strip_reasoning_kwargs(request_kwargs)
|
||||
try:
|
||||
@@ -1506,15 +1536,26 @@ class OpenAICompatProvider(LLMProvider):
|
||||
stream = await self._create_with_key_rotation(
|
||||
self._client.chat.completions.create, retry_kwargs
|
||||
)
|
||||
elif has_reasoning_kwargs(request_kwargs) and is_reasoning_param_unsupported(exc):
|
||||
disable_reasoning_params_at_runtime(
|
||||
self._binding_name(), request_kwargs.get("model")
|
||||
)
|
||||
logger.warning(
|
||||
"provider rejected reasoning parameters for streaming model={}; retrying without reasoning params. error={}",
|
||||
request_kwargs.get("model"),
|
||||
str(exc)[:200],
|
||||
)
|
||||
elif has_reasoning_kwargs(request_kwargs) and (
|
||||
reasoning_rejection := classify_reasoning_param_error(exc)
|
||||
):
|
||||
if reasoning_rejection == "param":
|
||||
disable_reasoning_params_at_runtime(
|
||||
self._binding_name(),
|
||||
request_kwargs.get("model"),
|
||||
self._endpoint_base(),
|
||||
)
|
||||
logger.warning(
|
||||
"provider rejected reasoning parameters for streaming model={}; retrying without reasoning params. error={}",
|
||||
request_kwargs.get("model"),
|
||||
str(exc)[:200],
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"provider rejected reasoning parameter value for streaming model={}; retrying once without reasoning params. error={}",
|
||||
request_kwargs.get("model"),
|
||||
str(exc)[:200],
|
||||
)
|
||||
retry_kwargs = strip_reasoning_kwargs(request_kwargs)
|
||||
stream = await self._create_with_key_rotation(
|
||||
self._client.chat.completions.create, retry_kwargs
|
||||
|
||||
@@ -338,6 +338,16 @@ def _is_qwen_instruct(model_name: str) -> bool:
|
||||
return "instruct" in tokens
|
||||
|
||||
|
||||
# Models whose upstream API enables thinking by default even when the request
|
||||
# omits ``thinking`` / ``reasoning_effort``. Kept separate from
|
||||
# ``_PROVIDER_REASONING_PATTERNS`` so requests without an explicit override
|
||||
# continue to omit wire parameters and rely on the API default, while the UI
|
||||
# toggle starts ON and disables thinking on the first click.
|
||||
_PROVIDER_IMPLICIT_THINKING_ON_PATTERNS: dict[str, tuple[str, ...]] = {
|
||||
"deepseek": ("deepseek-flash", "deepseek-v4-flash", "deepseek-v4.1-flash"),
|
||||
}
|
||||
|
||||
|
||||
def _default_toggle_on(
|
||||
resolved_provider: str,
|
||||
model_name: str,
|
||||
@@ -352,10 +362,15 @@ def _default_toggle_on(
|
||||
patterns = _PROVIDER_REASONING_PATTERNS.get(resolved_provider, ())
|
||||
if patterns and _matches(model_name, patterns):
|
||||
return True
|
||||
implicit_on = _PROVIDER_IMPLICIT_THINKING_ON_PATTERNS.get(resolved_provider, ())
|
||||
if implicit_on and _matches(model_name, implicit_on):
|
||||
return True
|
||||
if resolved_provider in {"custom", "siliconflow"}:
|
||||
custom_style, custom_patterns = _custom_thinking_style(model_name)
|
||||
if custom_style and custom_patterns and _matches(model_name, custom_patterns):
|
||||
return True
|
||||
if _matches(model_name, _PROVIDER_IMPLICIT_THINKING_ON_PATTERNS["deepseek"]):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Literal
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -114,64 +115,153 @@ def is_response_format_unsupported(exc: Exception) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def is_reasoning_param_unsupported(exc: Exception) -> bool:
|
||||
"""Whether a provider rejected reasoning/thinking request parameters (HTTP 400/422).
|
||||
_REASONING_FIELD_MARKERS = (
|
||||
"reasoning_effort",
|
||||
"reasoning effort",
|
||||
"reasoning.effort",
|
||||
"enable_thinking",
|
||||
"reasoning_split",
|
||||
"extra_body.thinking",
|
||||
"extra_body.reasoning",
|
||||
"thinking.type",
|
||||
"'thinking'",
|
||||
'"thinking"',
|
||||
"'reasoning'",
|
||||
'"reasoning"',
|
||||
"parameter: reasoning",
|
||||
"parameter reasoning",
|
||||
"argument: reasoning",
|
||||
"argument reasoning",
|
||||
"field: reasoning",
|
||||
"field reasoning",
|
||||
"parameter: thinking",
|
||||
"parameter thinking",
|
||||
"argument: thinking",
|
||||
"argument thinking",
|
||||
"field: thinking",
|
||||
"field thinking",
|
||||
"reasoning is not supported",
|
||||
"reasoning is unsupported",
|
||||
"does not support reasoning",
|
||||
"thinking is not supported",
|
||||
"thinking is unsupported",
|
||||
"does not support thinking",
|
||||
)
|
||||
|
||||
Gated strictly behind both a reasoning parameter mention and an
|
||||
unsupported/unknown/invalid parameter marker so auth, quota, or unrelated
|
||||
validation errors are never silently retried without thinking.
|
||||
_REASONING_PARAM_UNKNOWN_MARKERS = (
|
||||
"unknown parameter",
|
||||
"unknown_parameter",
|
||||
"unrecognized request argument",
|
||||
"unsupported parameter",
|
||||
"unsupported_parameter",
|
||||
"extra inputs are not permitted",
|
||||
"extra_forbidden",
|
||||
"unexpected keyword",
|
||||
)
|
||||
|
||||
_REASONING_VALUE_MARKERS = (
|
||||
"unsupported parameter value",
|
||||
"unsupported_parameter_value",
|
||||
"invalid value",
|
||||
"invalid_value",
|
||||
"unsupported value",
|
||||
"unsupported_value",
|
||||
"invalid_enum_value",
|
||||
"literal_error",
|
||||
"not a valid",
|
||||
"is not valid",
|
||||
"not valid",
|
||||
"invalid choice",
|
||||
"invalid option",
|
||||
"supported values",
|
||||
"allowed values",
|
||||
"valid values",
|
||||
"must be one of",
|
||||
"expected one of",
|
||||
"should be one of",
|
||||
"input should be",
|
||||
"only supports",
|
||||
"only accepts",
|
||||
"invalid reasoning_effort",
|
||||
"invalid reasoning effort",
|
||||
"unsupported reasoning_effort value",
|
||||
"unsupported reasoning effort value",
|
||||
)
|
||||
|
||||
_REASONING_VALUE_CONSTRAINT_RE = re.compile(
|
||||
r"(?:reasoning[_ .]effort|thinking(?:\.type)?)\s+must\s+be\b"
|
||||
)
|
||||
|
||||
_EFFORT_VALUE_TOKEN = (
|
||||
r"(?:none|minimal|minimum|low|medium|high|xhigh|max|adaptive|enabled|disabled)"
|
||||
)
|
||||
_REASONING_VALUE_IN_UNSUPPORTED_RE = re.compile(
|
||||
rf"(?:"
|
||||
rf"(?:['\"]?(?:reasoning[_ .]effort|thinking(?:\.type)?)['\"]?\s+does\s+not\s+support)"
|
||||
rf"|(?:['\"]?reasoning[_ .]effort['\"]?\s*(?:=|:|\s+)\s*['\"]?{_EFFORT_VALUE_TOKEN}['\"]?(?:$|[^a-z0-9_]))"
|
||||
rf"|(?:(?:['\"]{_EFFORT_VALUE_TOKEN}['\"]|\b{_EFFORT_VALUE_TOKEN}\b)\s+(?:is\s+)?(?:not\s+(?:a\s+)?supported|unsupported|not\s+allowed|invalid))"
|
||||
rf"|(?:does\s+not\s+support\s+(?:the\s+)?(?:value\s+|level\s+|effort\s+)?['\"]?{_EFFORT_VALUE_TOKEN}['\"]?(?:$|[^a-z0-9_]))"
|
||||
rf"|(?:(?:invalid|unsupported)\s+(?:value|level|effort|mode))"
|
||||
rf")"
|
||||
)
|
||||
|
||||
|
||||
def classify_reasoning_param_error(exc: Exception) -> Literal["param", "value"] | None:
|
||||
"""Classify an HTTP 400/422 reasoning-parameter rejection.
|
||||
|
||||
Returns:
|
||||
- ``"param"`` when the upstream explicitly rejected the reasoning
|
||||
parameter itself (safe to cache disablement for this endpoint/model).
|
||||
- ``"value"`` when the upstream rejected a specific effort/mode value
|
||||
(safe for a one-off retry without reasoning params, must NOT disable
|
||||
other valid levels such as ``"low"`` on subsequent requests).
|
||||
- ``None`` for auth, quota, transport, or unrelated validation errors.
|
||||
"""
|
||||
status = getattr(exc, "status_code", None)
|
||||
if status is None:
|
||||
response = getattr(exc, "response", None)
|
||||
status = getattr(response, "status_code", None)
|
||||
if status is not None and status not in {400, 422}:
|
||||
return False
|
||||
return None
|
||||
|
||||
text = error_text(exc)
|
||||
mentions_reasoning = any(
|
||||
field in text
|
||||
for field in (
|
||||
"reasoning_effort",
|
||||
"reasoning effort",
|
||||
"enable_thinking",
|
||||
"reasoning_split",
|
||||
"extra_body.thinking",
|
||||
"extra_body.reasoning",
|
||||
"'thinking'",
|
||||
'"thinking"',
|
||||
"'reasoning'",
|
||||
'"reasoning"',
|
||||
"parameter: reasoning",
|
||||
"parameter reasoning",
|
||||
"argument: reasoning",
|
||||
"argument reasoning",
|
||||
"field: reasoning",
|
||||
"field reasoning",
|
||||
"reasoning is not supported",
|
||||
"reasoning is unsupported",
|
||||
"does not support reasoning",
|
||||
"thinking is not supported",
|
||||
"does not support thinking",
|
||||
)
|
||||
)
|
||||
if not mentions_reasoning:
|
||||
return False
|
||||
return any(
|
||||
marker in text
|
||||
for marker in (
|
||||
"unknown parameter",
|
||||
"unrecognized request argument",
|
||||
"unsupported parameter",
|
||||
"not supported",
|
||||
"unsupported",
|
||||
"extra inputs are not permitted",
|
||||
"unexpected keyword",
|
||||
"invalid value",
|
||||
"not valid",
|
||||
"does not support",
|
||||
)
|
||||
if not any(field in text for field in _REASONING_FIELD_MARKERS):
|
||||
return None
|
||||
|
||||
is_unsupported_param_value = (
|
||||
"unsupported parameter value" in text or "unsupported_parameter_value" in text
|
||||
)
|
||||
if not is_unsupported_param_value and any(
|
||||
marker in text for marker in _REASONING_PARAM_UNKNOWN_MARKERS
|
||||
):
|
||||
return "param"
|
||||
|
||||
if any(
|
||||
marker in text for marker in _REASONING_VALUE_MARKERS
|
||||
) or _REASONING_VALUE_CONSTRAINT_RE.search(text):
|
||||
return "value"
|
||||
|
||||
if any(marker in text for marker in ("not supported", "unsupported", "does not support")):
|
||||
if _REASONING_VALUE_IN_UNSUPPORTED_RE.search(text):
|
||||
return "value"
|
||||
return "param"
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def is_reasoning_param_error(exc: Exception) -> bool:
|
||||
"""Whether a provider rejected a reasoning parameter or its value (HTTP 400/422)."""
|
||||
return classify_reasoning_param_error(exc) is not None
|
||||
|
||||
|
||||
def is_reasoning_param_unsupported(exc: Exception) -> bool:
|
||||
"""Whether a provider rejected the reasoning/thinking parameter itself (HTTP 400/422).
|
||||
|
||||
Returns ``False`` for value-specific rejections (e.g. ``invalid value`` for
|
||||
``reasoning_effort``) so callers can still do a one-off retry without
|
||||
caching a permanent disablement across other valid effort levels.
|
||||
"""
|
||||
return classify_reasoning_param_error(exc) == "param"
|
||||
|
||||
|
||||
def is_forced_tool_choice_unsupported(exc: Exception) -> bool:
|
||||
@@ -324,8 +414,10 @@ def is_transient_transport_error(exc: Exception) -> bool:
|
||||
|
||||
|
||||
__all__ = [
|
||||
"classify_reasoning_param_error",
|
||||
"error_text",
|
||||
"is_image_input_unsupported",
|
||||
"is_reasoning_param_error",
|
||||
"is_reasoning_param_unsupported",
|
||||
"is_response_format_unsupported",
|
||||
"is_stream_options_unsupported",
|
||||
|
||||
@@ -151,7 +151,23 @@ def test_resolve_reasoning_control_single_source_of_truth():
|
||||
strip_reasoning_kwargs,
|
||||
)
|
||||
|
||||
assert resolve_reasoning_control("deepseek", "deepseek-flash") == {
|
||||
for flash_model in ("deepseek-flash", "deepseek-v4-flash", "deepseek-v4.1-flash"):
|
||||
assert resolve_reasoning_control("deepseek", flash_model) == {
|
||||
"mode": "toggle",
|
||||
"off_value": "minimal",
|
||||
"on_value": "high",
|
||||
"default_on": True,
|
||||
}
|
||||
assert (
|
||||
build_openai_compatible_reasoning_kwargs(
|
||||
spec=None, binding="deepseek", model=flash_model, reasoning_effort=None
|
||||
)
|
||||
== {}
|
||||
)
|
||||
assert build_openai_compatible_reasoning_kwargs(
|
||||
spec=None, binding="deepseek", model=flash_model, reasoning_effort="minimal"
|
||||
) == {"extra_body": {"thinking": {"type": "disabled"}}}
|
||||
assert resolve_reasoning_control("deepseek", "deepseek-chat") == {
|
||||
"mode": "toggle",
|
||||
"off_value": "minimal",
|
||||
"on_value": "high",
|
||||
|
||||
@@ -132,8 +132,14 @@ def test_response_format_classifier_ignores_unrelated_unsupported_params() -> No
|
||||
|
||||
def test_is_reasoning_param_unsupported_matches_only_400_reasoning_rejections():
|
||||
from deeptutor.services.llm import request_compat
|
||||
from deeptutor.services.llm.request_compat import is_reasoning_param_unsupported
|
||||
from deeptutor.services.llm.request_compat import (
|
||||
classify_reasoning_param_error,
|
||||
is_reasoning_param_error,
|
||||
is_reasoning_param_unsupported,
|
||||
)
|
||||
|
||||
assert "classify_reasoning_param_error" in request_compat.__all__
|
||||
assert "is_reasoning_param_error" in request_compat.__all__
|
||||
assert "is_reasoning_param_unsupported" in request_compat.__all__
|
||||
|
||||
class FakeBadRequest(Exception):
|
||||
@@ -141,26 +147,56 @@ def test_is_reasoning_param_unsupported_matches_only_400_reasoning_rejections():
|
||||
super().__init__(msg)
|
||||
self.status_code = status_code
|
||||
|
||||
assert is_reasoning_param_unsupported(
|
||||
FakeBadRequest("Unknown parameter: 'reasoning_effort'", 400)
|
||||
)
|
||||
assert is_reasoning_param_unsupported(
|
||||
FakeBadRequest("Extra inputs are not permitted: enable_thinking", 422)
|
||||
)
|
||||
assert is_reasoning_param_unsupported(FakeBadRequest("Unknown parameter: 'reasoning'", 400))
|
||||
assert is_reasoning_param_unsupported(
|
||||
FakeBadRequest("Unsupported parameter: extra_body.reasoning", 400)
|
||||
)
|
||||
assert is_reasoning_param_unsupported(
|
||||
FakeBadRequest("Field reasoning is not supported by this model", 400)
|
||||
)
|
||||
assert not is_reasoning_param_unsupported(FakeBadRequest("Incorrect API key provided", 401))
|
||||
assert not is_reasoning_param_unsupported(
|
||||
FakeBadRequest("Rate limit reached for reasoning_effort requests", 429)
|
||||
)
|
||||
assert not is_reasoning_param_unsupported(
|
||||
FakeBadRequest("Unknown parameter: 'max_tokens'", 400)
|
||||
)
|
||||
# Parameter-level rejections: retryable AND safe to cache per endpoint.
|
||||
for msg, status in (
|
||||
("Unknown parameter: 'reasoning_effort'", 400),
|
||||
("Extra inputs are not permitted: enable_thinking", 422),
|
||||
("Unknown parameter: 'reasoning'", 400),
|
||||
("Unsupported parameter: extra_body.reasoning", 400),
|
||||
("Field reasoning is not supported by this model", 400),
|
||||
("This model does not support reasoning_effort", 400),
|
||||
):
|
||||
exc = FakeBadRequest(msg, status)
|
||||
assert classify_reasoning_param_error(exc) == "param", msg
|
||||
assert is_reasoning_param_unsupported(exc) is True, msg
|
||||
assert is_reasoning_param_error(exc) is True, msg
|
||||
|
||||
# Value-level rejections: retryable once, must NOT cache parameter disablement.
|
||||
for msg, status in (
|
||||
("Invalid value: 'high' for 'reasoning_effort'", 400),
|
||||
(
|
||||
"Unsupported value: 'reasoning_effort' does not support 'high' with this model. "
|
||||
"Supported values are: 'low' and 'medium'.",
|
||||
400,
|
||||
),
|
||||
("Unsupported parameter value: 'high' for 'reasoning_effort'", 400),
|
||||
("reasoning_effort='high' is not supported", 400),
|
||||
("'high' is not supported for reasoning_effort", 400),
|
||||
("Model does not support 'high' for reasoning_effort", 400),
|
||||
("reasoning_effort must be one of ['low', 'medium']", 400),
|
||||
(
|
||||
"{'detail': [{'type': 'literal_error', 'loc': ['body', 'reasoning_effort'], "
|
||||
"'msg': \"Input should be 'low' or 'medium'\", 'input': 'high'}]}",
|
||||
422,
|
||||
),
|
||||
):
|
||||
exc = FakeBadRequest(msg, status)
|
||||
assert classify_reasoning_param_error(exc) == "value", msg
|
||||
assert is_reasoning_param_unsupported(exc) is False, msg
|
||||
assert is_reasoning_param_error(exc) is True, msg
|
||||
|
||||
# Unrelated errors: neither retryable nor cacheable.
|
||||
for msg, status in (
|
||||
("Incorrect API key provided", 401),
|
||||
("Rate limit reached for reasoning_effort requests", 429),
|
||||
("Unknown parameter: 'max_tokens'", 400),
|
||||
("Thinking mode does not support this tool_choice", 400),
|
||||
("Maximum context length exceeded (reasoning_effort=high)", 400),
|
||||
):
|
||||
exc = FakeBadRequest(msg, status)
|
||||
assert classify_reasoning_param_error(exc) is None, msg
|
||||
assert is_reasoning_param_unsupported(exc) is False, msg
|
||||
assert is_reasoning_param_error(exc) is False, msg
|
||||
|
||||
|
||||
def test_openai_compat_provider_caches_reasoning_400_fallback_across_turns() -> None:
|
||||
@@ -230,7 +266,25 @@ def test_openai_compat_provider_caches_reasoning_400_fallback_across_turns() ->
|
||||
assert len(seen_kwargs) == 2
|
||||
assert seen_kwargs[0].get("reasoning_effort") == "high"
|
||||
assert "reasoning_effort" not in seen_kwargs[1]
|
||||
assert is_reasoning_params_disabled_at_runtime("custom", "custom-chat") is True
|
||||
assert (
|
||||
is_reasoning_params_disabled_at_runtime(
|
||||
"custom", "custom-chat", "https://relay.example.com/v1"
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
is_reasoning_params_disabled_at_runtime(
|
||||
"custom", "custom-chat", "https://RELAY.EXAMPLE.COM/v1/"
|
||||
)
|
||||
is True
|
||||
)
|
||||
assert (
|
||||
is_reasoning_params_disabled_at_runtime(
|
||||
"custom", "custom-chat", "https://other-relay.example.com/v1"
|
||||
)
|
||||
is False
|
||||
)
|
||||
assert is_reasoning_params_disabled_at_runtime("custom", "custom-chat") is False
|
||||
|
||||
# Second call (streaming) skips reasoning params upfront without another 400 round-trip.
|
||||
second = asyncio.run(
|
||||
@@ -304,6 +358,350 @@ def test_openai_compat_provider_stream_400_fallback_caches_disablement() -> None
|
||||
assert len(seen_kwargs) == 2
|
||||
assert seen_kwargs[0]["extra_body"] == {"enable_thinking": True}
|
||||
assert "extra_body" not in seen_kwargs[1]
|
||||
assert is_reasoning_params_disabled_at_runtime("siliconflow", "vendor/no-thinking-model")
|
||||
assert is_reasoning_params_disabled_at_runtime(
|
||||
"siliconflow", "vendor/no-thinking-model", "https://api.siliconflow.cn/v1"
|
||||
)
|
||||
assert not is_reasoning_params_disabled_at_runtime(
|
||||
"siliconflow", "vendor/no-thinking-model", "https://other.siliconflow.cn/v1"
|
||||
)
|
||||
finally:
|
||||
llm_capabilities._RUNTIME_DISABLED_REASONING_PARAMS.clear()
|
||||
|
||||
|
||||
def test_openai_compat_provider_value_rejection_retries_once_without_disabling_low_on_a_or_b() -> (
|
||||
None
|
||||
):
|
||||
"""A relay rejecting ``high`` as an invalid value retries once but still receives ``low``,
|
||||
and another relay with the same binding and model ID is unaffected."""
|
||||
import asyncio
|
||||
from types import SimpleNamespace
|
||||
|
||||
from deeptutor.services.llm import capabilities as llm_capabilities
|
||||
from deeptutor.services.llm.capabilities import is_reasoning_params_disabled_at_runtime
|
||||
from deeptutor.services.llm.provider_core.openai_compat_provider import OpenAICompatProvider
|
||||
from deeptutor.services.provider_registry import find_by_name
|
||||
|
||||
class FakeBadRequest(Exception):
|
||||
def __init__(self, msg: str, status_code: int = 400):
|
||||
super().__init__(msg)
|
||||
self.status_code = status_code
|
||||
|
||||
def _ok_response(stream: bool):
|
||||
if stream:
|
||||
|
||||
async def _stream():
|
||||
yield SimpleNamespace(
|
||||
choices=[
|
||||
SimpleNamespace(
|
||||
delta=SimpleNamespace(content="ok", tool_calls=None),
|
||||
finish_reason="stop",
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
return _stream()
|
||||
return SimpleNamespace(
|
||||
choices=[
|
||||
SimpleNamespace(
|
||||
message=SimpleNamespace(content="ok", tool_calls=None),
|
||||
finish_reason="stop",
|
||||
)
|
||||
],
|
||||
usage=None,
|
||||
)
|
||||
|
||||
for use_stream in (False, True):
|
||||
llm_capabilities._RUNTIME_DISABLED_REASONING_PARAMS.clear()
|
||||
try:
|
||||
relay_a = OpenAICompatProvider(
|
||||
api_key="key-a",
|
||||
api_base="https://relay-a.example.com/v1",
|
||||
default_model="shared-model",
|
||||
spec=find_by_name("custom"),
|
||||
provider_name="custom",
|
||||
configure_env=False,
|
||||
)
|
||||
relay_b = OpenAICompatProvider(
|
||||
api_key="key-b",
|
||||
api_base="https://relay-b.example.com/v1",
|
||||
default_model="shared-model",
|
||||
spec=find_by_name("custom"),
|
||||
provider_name="custom",
|
||||
configure_env=False,
|
||||
)
|
||||
seen_a: list[dict] = []
|
||||
seen_b: list[dict] = []
|
||||
|
||||
async def fake_a(**kwargs):
|
||||
seen_a.append(dict(kwargs))
|
||||
if kwargs.get("reasoning_effort") == "high":
|
||||
raise FakeBadRequest(
|
||||
"Invalid value: 'high' for 'reasoning_effort'. Supported values are: 'low'.",
|
||||
400,
|
||||
)
|
||||
return _ok_response(bool(kwargs.get("stream")))
|
||||
|
||||
async def fake_b(**kwargs):
|
||||
seen_b.append(dict(kwargs))
|
||||
return _ok_response(bool(kwargs.get("stream")))
|
||||
|
||||
relay_a._client.chat.completions.create = fake_a # type: ignore[method-assign]
|
||||
relay_b._client.chat.completions.create = fake_b # type: ignore[method-assign]
|
||||
|
||||
async def _call(provider: OpenAICompatProvider, effort: str):
|
||||
if use_stream:
|
||||
return await provider.chat_stream(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
model="shared-model",
|
||||
reasoning_effort=effort,
|
||||
)
|
||||
return await provider.chat(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
model="shared-model",
|
||||
reasoning_effort=effort,
|
||||
)
|
||||
|
||||
# 1. Send high to A -> rejected with 400, retries once without reasoning_effort.
|
||||
res1 = asyncio.run(_call(relay_a, "high"))
|
||||
assert res1.content == "ok"
|
||||
assert len(seen_a) == 2
|
||||
assert seen_a[0].get("reasoning_effort") == "high"
|
||||
assert "reasoning_effort" not in seen_a[1]
|
||||
assert not is_reasoning_params_disabled_at_runtime(
|
||||
"custom", "shared-model", "https://relay-a.example.com/v1"
|
||||
)
|
||||
|
||||
# 2. Send low to A -> A still receives low.
|
||||
res2 = asyncio.run(_call(relay_a, "low"))
|
||||
assert res2.content == "ok"
|
||||
assert len(seen_a) == 3
|
||||
assert seen_a[2].get("reasoning_effort") == "low"
|
||||
|
||||
# 3. Send low to B -> B still receives low.
|
||||
res3 = asyncio.run(_call(relay_b, "low"))
|
||||
assert res3.content == "ok"
|
||||
assert len(seen_b) == 1
|
||||
assert seen_b[0].get("reasoning_effort") == "low"
|
||||
finally:
|
||||
llm_capabilities._RUNTIME_DISABLED_REASONING_PARAMS.clear()
|
||||
|
||||
|
||||
def test_openai_compat_provider_param_rejection_cache_is_scoped_by_endpoint() -> None:
|
||||
"""Caching a parameter-level rejection on Relay A must not disable reasoning params on Relay B."""
|
||||
import asyncio
|
||||
from types import SimpleNamespace
|
||||
|
||||
from deeptutor.services.llm import capabilities as llm_capabilities
|
||||
from deeptutor.services.llm.capabilities import is_reasoning_params_disabled_at_runtime
|
||||
from deeptutor.services.llm.provider_core.openai_compat_provider import OpenAICompatProvider
|
||||
from deeptutor.services.provider_registry import find_by_name
|
||||
|
||||
class FakeBadRequest(Exception):
|
||||
def __init__(self, msg: str, status_code: int = 400):
|
||||
super().__init__(msg)
|
||||
self.status_code = status_code
|
||||
|
||||
def _ok():
|
||||
return SimpleNamespace(
|
||||
choices=[
|
||||
SimpleNamespace(
|
||||
message=SimpleNamespace(content="ok", tool_calls=None),
|
||||
finish_reason="stop",
|
||||
)
|
||||
],
|
||||
usage=None,
|
||||
)
|
||||
|
||||
llm_capabilities._RUNTIME_DISABLED_REASONING_PARAMS.clear()
|
||||
try:
|
||||
relay_a = OpenAICompatProvider(
|
||||
api_key="key-a",
|
||||
api_base="https://relay-a.example.com/v1",
|
||||
default_model="shared-model",
|
||||
spec=find_by_name("custom"),
|
||||
provider_name="custom",
|
||||
configure_env=False,
|
||||
)
|
||||
relay_b = OpenAICompatProvider(
|
||||
api_key="key-b",
|
||||
api_base="https://relay-b.example.com/v1",
|
||||
default_model="shared-model",
|
||||
spec=find_by_name("custom"),
|
||||
provider_name="custom",
|
||||
configure_env=False,
|
||||
)
|
||||
seen_a: list[dict] = []
|
||||
seen_b: list[dict] = []
|
||||
|
||||
async def fake_a(**kwargs):
|
||||
seen_a.append(dict(kwargs))
|
||||
if "reasoning_effort" in kwargs:
|
||||
raise FakeBadRequest("Unknown parameter: 'reasoning_effort'", 400)
|
||||
return _ok()
|
||||
|
||||
async def fake_b(**kwargs):
|
||||
seen_b.append(dict(kwargs))
|
||||
return _ok()
|
||||
|
||||
relay_a._client.chat.completions.create = fake_a # type: ignore[method-assign]
|
||||
relay_b._client.chat.completions.create = fake_b # type: ignore[method-assign]
|
||||
|
||||
# Relay A rejects the parameter itself -> retried once and cached for Relay A's endpoint.
|
||||
first = asyncio.run(
|
||||
relay_a.chat(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
model="shared-model",
|
||||
reasoning_effort="high",
|
||||
)
|
||||
)
|
||||
assert first.content == "ok"
|
||||
assert len(seen_a) == 2
|
||||
assert seen_a[0].get("reasoning_effort") == "high"
|
||||
assert "reasoning_effort" not in seen_a[1]
|
||||
assert is_reasoning_params_disabled_at_runtime(
|
||||
"custom", "shared-model", "https://relay-a.example.com/v1"
|
||||
)
|
||||
assert not is_reasoning_params_disabled_at_runtime(
|
||||
"custom", "shared-model", "https://relay-b.example.com/v1"
|
||||
)
|
||||
|
||||
# Follow-up request to Relay A skips reasoning_effort upfront.
|
||||
second = asyncio.run(
|
||||
relay_a.chat(
|
||||
messages=[{"role": "user", "content": "again"}],
|
||||
model="shared-model",
|
||||
reasoning_effort="low",
|
||||
)
|
||||
)
|
||||
assert second.content == "ok"
|
||||
assert len(seen_a) == 3
|
||||
assert "reasoning_effort" not in seen_a[2]
|
||||
|
||||
# Relay B (same binding + model ID, different API base) still receives low.
|
||||
third = asyncio.run(
|
||||
relay_b.chat(
|
||||
messages=[{"role": "user", "content": "hi B"}],
|
||||
model="shared-model",
|
||||
reasoning_effort="low",
|
||||
)
|
||||
)
|
||||
assert third.content == "ok"
|
||||
assert len(seen_b) == 1
|
||||
assert seen_b[0].get("reasoning_effort") == "low"
|
||||
finally:
|
||||
llm_capabilities._RUNTIME_DISABLED_REASONING_PARAMS.clear()
|
||||
|
||||
|
||||
def test_openai_compat_provider_real_sdk_two_mocked_relays_preserve_low() -> None:
|
||||
"""Exercise the real AsyncOpenAI SDK + BadRequestError path against two mocked relays."""
|
||||
import asyncio
|
||||
import importlib
|
||||
import json
|
||||
|
||||
from deeptutor.services.llm import capabilities as llm_capabilities
|
||||
from deeptutor.services.llm.provider_core.openai_compat_provider import OpenAICompatProvider
|
||||
from deeptutor.services.provider_registry import find_by_name
|
||||
|
||||
def _attach_mock_transport(provider: OpenAICompatProvider, handler):
|
||||
sdk = provider._client
|
||||
base = importlib.import_module(type(sdk).__module__.split(".")[0] + "._base_client")
|
||||
transport_mod = getattr(base, "httpx2", None) or base.httpx
|
||||
|
||||
def _adapt(request):
|
||||
status, payload = handler(json.loads(request.content.decode("utf-8")))
|
||||
return transport_mod.Response(status, json=payload)
|
||||
|
||||
provider._client = sdk.with_options(
|
||||
http_client=transport_mod.AsyncClient(transport=transport_mod.MockTransport(_adapt))
|
||||
)
|
||||
|
||||
ok_body = {
|
||||
"id": "chatcmpl-test",
|
||||
"object": "chat.completion",
|
||||
"created": 0,
|
||||
"model": "shared-model",
|
||||
"choices": [
|
||||
{
|
||||
"index": 0,
|
||||
"message": {"role": "assistant", "content": "ok"},
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
async def _run() -> None:
|
||||
relay_a = OpenAICompatProvider(
|
||||
api_key="key-a",
|
||||
api_base="https://relay-a.example.com/v1",
|
||||
default_model="shared-model",
|
||||
spec=find_by_name("custom"),
|
||||
provider_name="custom",
|
||||
configure_env=False,
|
||||
)
|
||||
relay_b = OpenAICompatProvider(
|
||||
api_key="key-b",
|
||||
api_base="https://relay-b.example.com/v1",
|
||||
default_model="shared-model",
|
||||
spec=find_by_name("custom"),
|
||||
provider_name="custom",
|
||||
configure_env=False,
|
||||
)
|
||||
bodies_a: list[dict] = []
|
||||
bodies_b: list[dict] = []
|
||||
|
||||
def handle_a(body: dict):
|
||||
bodies_a.append(body)
|
||||
if body.get("reasoning_effort") == "high":
|
||||
return (
|
||||
400,
|
||||
{
|
||||
"error": {
|
||||
"message": "Invalid value: 'high'. Supported values are: 'low'.",
|
||||
"type": "invalid_request_error",
|
||||
"param": "reasoning_effort",
|
||||
"code": "invalid_value",
|
||||
}
|
||||
},
|
||||
)
|
||||
return 200, ok_body
|
||||
|
||||
def handle_b(body: dict):
|
||||
bodies_b.append(body)
|
||||
return 200, ok_body
|
||||
|
||||
_attach_mock_transport(relay_a, handle_a)
|
||||
_attach_mock_transport(relay_b, handle_b)
|
||||
|
||||
try:
|
||||
r1 = await relay_a.chat(
|
||||
messages=[{"role": "user", "content": "1"}],
|
||||
model="shared-model",
|
||||
reasoning_effort="high",
|
||||
)
|
||||
assert r1.content == "ok"
|
||||
assert [b.get("reasoning_effort") for b in bodies_a] == ["high", None]
|
||||
|
||||
r2 = await relay_a.chat(
|
||||
messages=[{"role": "user", "content": "2"}],
|
||||
model="shared-model",
|
||||
reasoning_effort="low",
|
||||
)
|
||||
assert r2.content == "ok"
|
||||
assert [b.get("reasoning_effort") for b in bodies_a] == ["high", None, "low"]
|
||||
|
||||
r3 = await relay_b.chat(
|
||||
messages=[{"role": "user", "content": "3"}],
|
||||
model="shared-model",
|
||||
reasoning_effort="low",
|
||||
)
|
||||
assert r3.content == "ok"
|
||||
assert [b.get("reasoning_effort") for b in bodies_b] == ["low"]
|
||||
finally:
|
||||
await relay_a._client.close()
|
||||
await relay_b._client.close()
|
||||
|
||||
llm_capabilities._RUNTIME_DISABLED_REASONING_PARAMS.clear()
|
||||
try:
|
||||
asyncio.run(_run())
|
||||
finally:
|
||||
llm_capabilities._RUNTIME_DISABLED_REASONING_PARAMS.clear()
|
||||
|
||||
@@ -185,6 +185,7 @@ def test_list_llm_options_includes_reasoning_control():
|
||||
"model": "deepseek-chat",
|
||||
"reasoning_effort": "high",
|
||||
},
|
||||
{"id": "m5", "name": "deepseek-chat-default", "model": "deepseek-chat"},
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -203,7 +204,7 @@ def test_list_llm_options_includes_reasoning_control():
|
||||
"mode": "toggle",
|
||||
"off_value": "minimal",
|
||||
"on_value": "high",
|
||||
"default_on": False,
|
||||
"default_on": True,
|
||||
}
|
||||
assert by_id["m3"]["reasoning_control"] == {
|
||||
"mode": "toggle",
|
||||
@@ -217,4 +218,10 @@ def test_list_llm_options_includes_reasoning_control():
|
||||
"on_value": "high",
|
||||
"default_on": True,
|
||||
}
|
||||
assert by_id["m5"]["reasoning_control"] == {
|
||||
"mode": "toggle",
|
||||
"off_value": "minimal",
|
||||
"on_value": "high",
|
||||
"default_on": False,
|
||||
}
|
||||
assert by_id["m2"]["reasoning_control"]["mode"] == "levels"
|
||||
|
||||
@@ -211,6 +211,7 @@ function tableReasoningEffortOptions(
|
||||
"deepseek-reasoner",
|
||||
"deepseek-v4-pro",
|
||||
"deepseek-v4-flash",
|
||||
"deepseek-v4.1-flash",
|
||||
"deepseek-flash",
|
||||
"qwen3",
|
||||
"qwen-3",
|
||||
@@ -341,7 +342,13 @@ function deriveToggleDefaultOn(
|
||||
}
|
||||
if (isQwenInstruct(modelName)) return false;
|
||||
if (provider === "deepseek") {
|
||||
return includesAny(modelName, ["deepseek-v4-pro", "deepseek-reasoner"]);
|
||||
return includesAny(modelName, [
|
||||
"deepseek-v4-pro",
|
||||
"deepseek-reasoner",
|
||||
"deepseek-flash",
|
||||
"deepseek-v4-flash",
|
||||
"deepseek-v4.1-flash",
|
||||
]);
|
||||
}
|
||||
if (provider === "dashscope") {
|
||||
return includesAny(modelName, ["qwen3", "qwen-3", "qwq", "qwen-plus"]);
|
||||
@@ -355,6 +362,9 @@ function deriveToggleDefaultOn(
|
||||
"deepseek-v4-pro",
|
||||
"deepseek-reasoner",
|
||||
"deepseek-r1",
|
||||
"deepseek-flash",
|
||||
"deepseek-v4-flash",
|
||||
"deepseek-v4.1-flash",
|
||||
]);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -129,7 +129,7 @@ it("renders a one-click Thinking toggle for binary domestic and custom models",
|
||||
const onChange = vi.fn();
|
||||
const { rerender } = render(
|
||||
<ReasoningEffortSelector
|
||||
option={option({ provider: "deepseek", model: "deepseek-flash" })}
|
||||
option={option({ provider: "deepseek", model: "deepseek-chat" })}
|
||||
value={null}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
@@ -141,7 +141,7 @@ it("renders a one-click Thinking toggle for binary domestic and custom models",
|
||||
|
||||
rerender(
|
||||
<ReasoningEffortSelector
|
||||
option={option({ provider: "deepseek", model: "deepseek-flash" })}
|
||||
option={option({ provider: "deepseek", model: "deepseek-chat" })}
|
||||
value="high"
|
||||
onChange={onChange}
|
||||
/>,
|
||||
@@ -153,6 +153,34 @@ it("renders a one-click Thinking toggle for binary domestic and custom models",
|
||||
expect(onChange).toHaveBeenLastCalledWith("minimal");
|
||||
});
|
||||
|
||||
it("shows DeepSeek Flash thinking as on by default and turns it off on the first click", () => {
|
||||
const onChange = vi.fn();
|
||||
const { rerender } = render(
|
||||
<ReasoningEffortSelector
|
||||
option={option({ provider: "deepseek", model: "deepseek-flash" })}
|
||||
value={null}
|
||||
onChange={onChange}
|
||||
/>,
|
||||
);
|
||||
const toggle = screen.getByRole("button", { name: "Reasoning effort" });
|
||||
expect(toggle.getAttribute("aria-pressed")).toBe("true");
|
||||
fireEvent.click(toggle);
|
||||
expect(onChange).toHaveBeenLastCalledWith("minimal");
|
||||
|
||||
rerender(
|
||||
<ReasoningEffortSelector
|
||||
option={option({ provider: "deepseek", model: "deepseek-flash" })}
|
||||
value="minimal"
|
||||
onChange={onChange}
|
||||
/>,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Reasoning effort" }).getAttribute("aria-pressed"),
|
||||
).toBe("false");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Reasoning effort" }));
|
||||
expect(onChange).toHaveBeenLastCalledWith("high");
|
||||
});
|
||||
|
||||
it("aligns default-on toggle state so models enabled by default turn off on a single click", () => {
|
||||
const onChange = vi.fn();
|
||||
const { rerender } = render(
|
||||
|
||||
@@ -387,6 +387,14 @@ test("deepseek-flash and deepseek-v4-flash expose binary thinking controls in se
|
||||
|
||||
assert.deepEqual(
|
||||
resolveReasoningControl({ provider: "deepseek", model: "deepseek-flash" }),
|
||||
{ kind: "toggle", offValue: "minimal", onValue: "high", defaultOn: true },
|
||||
);
|
||||
assert.deepEqual(
|
||||
resolveReasoningControl({ provider: "deepseek", model: "deepseek-v4-flash" }),
|
||||
{ kind: "toggle", offValue: "minimal", onValue: "high", defaultOn: true },
|
||||
);
|
||||
assert.deepEqual(
|
||||
resolveReasoningControl({ provider: "deepseek", model: "deepseek-chat" }),
|
||||
{ kind: "toggle", offValue: "minimal", onValue: "high", defaultOn: false },
|
||||
);
|
||||
assert.deepEqual(
|
||||
|
||||
Reference in New Issue
Block a user