From 3d2526035f588acf7aa106a9535eebe9ff09d6e1 Mon Sep 17 00:00:00 2001 From: kerry Date: Wed, 7 Oct 2026 19:35:14 +0000 Subject: [PATCH] test(model_prices): type and tidy the claude-haiku-5-5 config tests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/unit/test_claude_haiku_5_5_config.py | 83 ++++++++++------------ 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/tests/unit/test_claude_haiku_5_5_config.py b/tests/unit/test_claude_haiku_5_5_config.py index a4b93ed2bb3..99c7d167df4 100644 --- a/tests/unit/test_claude_haiku_5_5_config.py +++ b/tests/unit/test_claude_haiku_5_5_config.py @@ -10,6 +10,8 @@ tool). Its cost-map rows therefore carry ``thinking_always_on: false`` and import json import os +from collections.abc import Iterator +from typing import Final, cast import pytest @@ -17,12 +19,23 @@ import litellm from litellm.litellm_core_utils.get_model_cost_map import GetModelCostMap from litellm.llms.anthropic.common_utils import AnthropicModelInfo -REPO_ROOT = os.path.join(os.path.dirname(__file__), "../..") +REPO_ROOT: Final = os.path.join(os.path.dirname(__file__), "../..") + +GET_WEATHER_TOOL: Final = { + "type": "function", + "function": { + "name": "get_weather", + "description": "Get the weather", + "parameters": { + "type": "object", + "properties": {"city": {"type": "string"}}, + }, + }, +} @pytest.fixture(autouse=True) -def local_model_cost_map(monkeypatch): - """Never depend on the published cost map having this new model yet.""" +def local_model_cost_map(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]: monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url="")) monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) @@ -31,13 +44,13 @@ def local_model_cost_map(monkeypatch): litellm.get_model_info.cache_clear() -def _load_root_cost_map() -> dict: - json_path = os.path.join(REPO_ROOT, "model_prices_and_context_window.json") +def _load_root_cost_map() -> dict[str, dict[str, object]]: + json_path: Final = os.path.join(REPO_ROOT, "model_prices_and_context_window.json") with open(json_path) as f: - return json.load(f) + return cast(dict[str, dict[str, object]], json.load(f)) -HAIKU_5_5_VARIANTS = ( +HAIKU_5_5_VARIANTS: Final = ( "claude-haiku-5-5", "anthropic.claude-haiku-5-5", "apac.anthropic.claude-haiku-5-5", @@ -57,11 +70,13 @@ HAIKU_5_5_VARIANTS = ( @pytest.mark.parametrize("model_name", HAIKU_5_5_VARIANTS) -def test_haiku_5_5_rows_allow_disabling_thinking_and_forced_tools(model_name): - root = _load_root_cost_map() - backup = GetModelCostMap.load_local_model_cost_map() +def test_haiku_5_5_rows_allow_disabling_thinking_and_forced_tools( + model_name: str, +) -> None: + root: Final = _load_root_cost_map() + backup: Final = GetModelCostMap.load_local_model_cost_map() assert model_name in root - row = root[model_name] + row: Final = root[model_name] # https://platform.claude.com/docs/en/models/haiku-5-5/whats-new-haiku-5-5 (2026-10-07): # thinking can be disabled, forced tool_choice accepted assert row["thinking_always_on"] is False @@ -77,30 +92,18 @@ def test_haiku_5_5_rows_allow_disabling_thinking_and_forced_tools(model_name): ("vertex_ai/claude-haiku-5-5", "vertex_ai"), ], ) -def test_haiku_5_5_runtime_profile(local_model_cost_map, model, provider): +def test_haiku_5_5_runtime_profile(local_model_cost_map: None, model: str, provider: str) -> None: assert AnthropicModelInfo.is_adaptive_thinking_model(model, provider) is True assert AnthropicModelInfo._is_always_on_thinking_model(model, provider) is False assert AnthropicModelInfo.forced_tool_use_unsupported(model.removeprefix("anthropic/")) is False -def test_haiku_5_5_anthropic_tool_choice_required_maps_to_any(local_model_cost_map): - """``tool_choice="required"`` on ``claude-haiku-5-5`` must not raise the - forced-tool-use UnsupportedParamsError and maps to Anthropic ``any``.""" - optional_params = litellm.AnthropicConfig().map_openai_params( +def test_haiku_5_5_anthropic_tool_choice_required_maps_to_any( + local_model_cost_map: None, +) -> None: + optional_params: Final = litellm.AnthropicConfig().map_openai_params( non_default_params={ - "tools": [ - { - "type": "function", - "function": { - "name": "get_weather", - "description": "Get the weather", - "parameters": { - "type": "object", - "properties": {"city": {"type": "string"}}, - }, - }, - } - ], + "tools": [dict(GET_WEATHER_TOOL)], "tool_choice": "required", }, optional_params={}, @@ -110,24 +113,12 @@ def test_haiku_5_5_anthropic_tool_choice_required_maps_to_any(local_model_cost_m assert optional_params["tool_choice"] == {"type": "any"} -def test_haiku_5_5_bedrock_tool_choice_required_maps_to_any(local_model_cost_map): - """``tool_choice="required"`` on the Bedrock Converse row maps to the - Converse ``any`` block.""" - optional_params = litellm.AmazonConverseConfig().map_openai_params( +def test_haiku_5_5_bedrock_tool_choice_required_maps_to_any( + local_model_cost_map: None, +) -> None: + optional_params: Final = litellm.AmazonConverseConfig().map_openai_params( non_default_params={ - "tools": [ - { - "type": "function", - "function": { - "name": "get_weather", - "description": "Get the weather", - "parameters": { - "type": "object", - "properties": {"city": {"type": "string"}}, - }, - }, - } - ], + "tools": [dict(GET_WEATHER_TOOL)], "tool_choice": "required", }, optional_params={},