Self-hosted AI workspace.
Python
tests(llm): cover Anthropic temperature clamping
Alexandre Teixeira1d55fc48ca13
diff --git a/tests/test_llm_core_temperature.py b/tests/test_llm_core_temperature.pyindex 09abf8a32..00be525b7 100644--- a/tests/test_llm_core_temperature.py+++ b/tests/test_llm_core_temperature.py@@ -66,3 +66,37 @@ def test_normal_model_payload_keeps_temperature(monkeypatch):payload = _capture_openai_payload(monkeypatch, "gpt-4o", 0.2)assert payload["temperature"] == 0.2assert payload["max_tokens"] == 5+++def test_normal_model_payload_keeps_temperature_above_one(monkeypatch):+ # OpenAI/local providers may validly use temperatures above 1.0; the clamp+ # is Anthropic-only and must not touch this path.+ payload = _capture_openai_payload(monkeypatch, "gpt-4o", 1.2)+ assert payload["temperature"] == 1.2+++def _anthropic_payload(temperature):+ return llm_core._build_anthropic_payload(+ "claude-3-5-sonnet",+ [{"role": "user", "content": "Hi"}],+ temperature,+ max_tokens=5,+ )+++def test_anthropic_payload_clamps_above_one():+ # Anthropic rejects temperature > 1.0 (e.g. the Nietzsche preset's 1.2).+ assert _anthropic_payload(1.2)["temperature"] == 1.0+++def test_anthropic_payload_keeps_in_range():+ assert _anthropic_payload(0.7)["temperature"] == 0.7+++def test_anthropic_payload_clamps_negative():+ assert _anthropic_payload(-0.5)["temperature"] == 0.0+++def test_anthropic_payload_none_temperature_does_not_crash():+ payload = _anthropic_payload(None)+ assert payload["temperature"] is None