From f1b5a82a5c83742d9a9bb28cdae910471b6e7bf8 Mon Sep 17 00:00:00 2001 From: DarRahman Date: Fri, 28 Aug 2026 14:47:35 +0700 Subject: [PATCH] fix(groq): simplify mapping check to satisfy basedpyright type budget --- litellm/llms/groq/cost_calculator.py | 6 ++---- .../llms/groq/test_groq_cost_calculator.py | 20 +++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/litellm/llms/groq/cost_calculator.py b/litellm/llms/groq/cost_calculator.py index 1d60696d6fd..3d726e54136 100644 --- a/litellm/llms/groq/cost_calculator.py +++ b/litellm/llms/groq/cost_calculator.py @@ -18,11 +18,9 @@ if TYPE_CHECKING: def cost_per_web_search_request(usage: Usage, model_info: "ModelInfo") -> float: - search_costs: Final = model_info.get("search_context_cost_per_query") + search_costs = model_info.get("search_context_cost_per_query") if isinstance(search_costs, Mapping): - cost_per_search: Final = float(search_costs.get("search_context_size_medium", 0.0) or 0.0) - elif isinstance(search_costs, (int, float)) and not isinstance(search_costs, bool): - cost_per_search = float(search_costs) + cost_per_search = float(search_costs.get("search_context_size_medium", 0.0) or 0.0) else: cost_per_search = 0.0 diff --git a/tests/test_litellm/llms/groq/test_groq_cost_calculator.py b/tests/test_litellm/llms/groq/test_groq_cost_calculator.py index d0366268c23..2e6ccbe69fe 100644 --- a/tests/test_litellm/llms/groq/test_groq_cost_calculator.py +++ b/tests/test_litellm/llms/groq/test_groq_cost_calculator.py @@ -56,17 +56,6 @@ def test_bills_searches_and_opens_together(): assert cost == pytest.approx(2 * 0.005 + 3 * 0.001) -def test_bills_per_executed_search_flat_cost(): - flat_priced = ModelInfo( - key="groq/openai/gpt-oss-20b", - litellm_provider="groq", - mode="chat", - search_context_cost_per_query=0.005, - ) - cost = cost_per_web_search_request(usage=_usage_with_actions(4), model_info=flat_priced) - assert cost == pytest.approx(4 * 0.005) - - def test_invalid_pricing_type_safe(): invalid_priced = ModelInfo( key="groq/openai/gpt-oss-20b", @@ -85,3 +74,12 @@ def test_invalid_pricing_type_safe(): ) cost_bool = cost_per_web_search_request(usage=_usage_with_actions(4), model_info=bool_priced) assert cost_bool == 0.0 + + float_priced = ModelInfo( + key="groq/openai/gpt-oss-20b", + litellm_provider="groq", + mode="chat", + search_context_cost_per_query=0.005, + ) + cost_float = cost_per_web_search_request(usage=_usage_with_actions(4), model_info=float_priced) + assert cost_float == 0.0