mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-04 22:29:25 +08:00
fix: correct temperature-rejection model set + skip tests where anthropic SDK absent
Opus 4.6 and Sonnet 4.6 still accept `temperature` — omitting it there
silently dropped the user's configured setting; and `opus-5`/`haiku-5`
matched no real model id. The set is now a documented module constant
covering exactly the effort-based families that 400 on temperature
(opus-4-7/4-8, sonnet-5, fable-5, mythos-5), with regression coverage
both ways. The new test file also gains pytest.importorskip('anthropic')
so it skips cleanly in environments without the optional [cli] SDK
(e.g. the CI python-tests job) instead of erroring on construction.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,18 @@ from deeptutor.services.llm.provider_core.base import LLMProvider, LLMResponse,
|
||||
|
||||
_ALNUM = string.ascii_letters + string.digits
|
||||
|
||||
# Model families that REJECT the `temperature` parameter with a 400 — the
|
||||
# effort-based generation from Opus 4.7 onward. Opus 4.6 and Sonnet 4.6 still
|
||||
# ACCEPT temperature; adding them here would silently drop the user's setting.
|
||||
# Extend as new families ship (a capability lookup is the longer-term fix).
|
||||
_TEMPERATURE_REJECTING_FAMILIES: tuple[str, ...] = (
|
||||
"opus-4-7",
|
||||
"opus-4-8",
|
||||
"sonnet-5",
|
||||
"fable-5",
|
||||
"mythos-5",
|
||||
)
|
||||
|
||||
|
||||
def _gen_tool_id() -> str:
|
||||
return "toolu_" + "".join(secrets.choice(_ALNUM) for _ in range(22))
|
||||
@@ -361,22 +373,7 @@ class AnthropicProvider(LLMProvider):
|
||||
|
||||
max_tokens = max(1, max_tokens)
|
||||
thinking_enabled = bool(reasoning_effort)
|
||||
# Newer effort-based Claude models reject the `temperature` parameter.
|
||||
# Extend this list as new families ship (a capability lookup would be
|
||||
# the longer-term fix).
|
||||
omit_temperature = any(
|
||||
family in model_name
|
||||
for family in (
|
||||
"opus-4-6",
|
||||
"opus-4-7",
|
||||
"opus-4-8",
|
||||
"sonnet-4-6",
|
||||
"sonnet-5",
|
||||
"opus-5",
|
||||
"fable-5",
|
||||
"haiku-5",
|
||||
)
|
||||
)
|
||||
omit_temperature = any(family in model_name for family in _TEMPERATURE_REJECTING_FAMILIES)
|
||||
|
||||
kwargs: dict[str, Any] = {
|
||||
"model": model_name,
|
||||
|
||||
@@ -10,6 +10,12 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
# Constructing AnthropicProvider imports the optional `anthropic` SDK ([cli]
|
||||
# extra) — skip cleanly where it isn't installed (e.g. the CI python-tests job).
|
||||
pytest.importorskip("anthropic")
|
||||
|
||||
from deeptutor.services.llm.provider_core.anthropic_provider import AnthropicProvider
|
||||
|
||||
|
||||
@@ -42,13 +48,21 @@ def _kwargs(provider: AnthropicProvider, model: str) -> dict[str, Any]:
|
||||
|
||||
def test_temperature_omitted_for_effort_based_models() -> None:
|
||||
provider = _provider()
|
||||
for model in ("claude-opus-4-8", "claude-sonnet-5", "claude-opus-4-7"):
|
||||
for model in ("claude-opus-4-8", "claude-sonnet-5", "claude-opus-4-7", "claude-fable-5"):
|
||||
assert "temperature" not in _kwargs(provider, model), model
|
||||
|
||||
|
||||
def test_temperature_kept_for_older_models() -> None:
|
||||
def test_temperature_kept_for_models_that_accept_it() -> None:
|
||||
provider = _provider()
|
||||
for model in ("claude-sonnet-4-5-20250929", "claude-haiku-4-5-20251001", "claude-opus-4-1"):
|
||||
# Opus 4.6 / Sonnet 4.6 still accept temperature — omitting it there
|
||||
# would silently drop the user's configured setting.
|
||||
for model in (
|
||||
"claude-opus-4-6",
|
||||
"claude-sonnet-4-6",
|
||||
"claude-sonnet-4-5-20250929",
|
||||
"claude-haiku-4-5-20251001",
|
||||
"claude-opus-4-1",
|
||||
):
|
||||
assert "temperature" in _kwargs(provider, model), model
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user