mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(groq): simplify mapping check to satisfy basedpyright type budget
This commit is contained in:
parent
86789055f3
commit
f1b5a82a5c
2 changed files with 11 additions and 15 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue