From 2116ae8ca2413e6524bf2bc2872d820d0e4a266e Mon Sep 17 00:00:00 2001 From: "Bingxi Zhao (Frank)" <13051345080@163.com> Date: Sun, 19 Jul 2026 01:00:12 +0800 Subject: [PATCH] fix: correct temperature-rejection model set + skip tests where anthropic SDK absent MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../llm/provider_core/anthropic_provider.py | 29 +++++++++---------- .../llm/test_anthropic_provider_fixes.py | 20 +++++++++++-- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/deeptutor/services/llm/provider_core/anthropic_provider.py b/deeptutor/services/llm/provider_core/anthropic_provider.py index aa35731e4..ddf3c7c8f 100644 --- a/deeptutor/services/llm/provider_core/anthropic_provider.py +++ b/deeptutor/services/llm/provider_core/anthropic_provider.py @@ -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, diff --git a/tests/services/llm/test_anthropic_provider_fixes.py b/tests/services/llm/test_anthropic_provider_fixes.py index 098934d8f..e27d4efdd 100644 --- a/tests/services/llm/test_anthropic_provider_fixes.py +++ b/tests/services/llm/test_anthropic_provider_fixes.py @@ -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