From 00cc0da530c8397b779da1f5e4834be207d939e4 Mon Sep 17 00:00:00 2001 From: Hamb_y Date: Fri, 3 Jul 2026 13:18:46 +0530 Subject: [PATCH] fix(providers): omit temperature for sonnet 5 Add sonnet-5 to the Anthropic omit-temperature model families and cover adaptive, enabled, and non-thinking request paths. Fixes #4683 --- nanobot/providers/anthropic_provider.py | 6 ++++-- tests/providers/test_anthropic_thinking.py | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nanobot/providers/anthropic_provider.py b/nanobot/providers/anthropic_provider.py index 679ef0bc..68bb8316 100644 --- a/nanobot/providers/anthropic_provider.py +++ b/nanobot/providers/anthropic_provider.py @@ -545,10 +545,12 @@ class AnthropicProvider(LLMProvider): max_tokens = max(1, max_tokens) thinking_enabled = bool(reasoning_effort) and reasoning_effort.lower() != "none" - # Several Anthropic models (opus-4-7, opus-4-8, fable) deprecated the + # Several Anthropic models (opus-4-7, opus-4-8, sonnet-5, fable) deprecated the # `temperature` parameter — the API returns 400 if it is present. _model_lower = model_name.lower() - omit_temperature = any(m in _model_lower for m in ("opus-4-7", "opus-4-8", "fable")) + omit_temperature = any( + m in _model_lower for m in ("opus-4-7", "opus-4-8", "sonnet-5", "fable") + ) kwargs: dict[str, Any] = { "model": model_name, diff --git a/tests/providers/test_anthropic_thinking.py b/tests/providers/test_anthropic_thinking.py index 547a4817..0672709e 100644 --- a/tests/providers/test_anthropic_thinking.py +++ b/tests/providers/test_anthropic_thinking.py @@ -115,6 +115,24 @@ def test_fable_omits_temperature_none() -> None: assert "temperature" not in kw +def test_sonnet_5_omits_temperature_adaptive() -> None: + kw = _build(_make_provider("claude-sonnet-5"), "adaptive") + assert "temperature" not in kw + assert kw["thinking"] == {"type": "adaptive"} + + +def test_sonnet_5_omits_temperature_enabled() -> None: + kw = _build(_make_provider("claude-sonnet-5"), "high", max_tokens=4096) + assert "temperature" not in kw + assert kw["thinking"]["type"] == "enabled" + + +def test_sonnet_5_omits_temperature_none() -> None: + kw = _build(_make_provider("anthropic/claude-sonnet-5"), None) + assert "temperature" not in kw + assert "thinking" not in kw + + def test_ordinary_model_sends_temperature() -> None: kw = _build(_make_provider("claude-sonnet-4-6"), None) assert kw["temperature"] == 0.7