mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
test(model_prices): type the Mistral cache-read helpers and check the backup registry too
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
6933ca2337
commit
1bc4509bf0
1 changed files with 22 additions and 10 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import importlib.util
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Mapping
|
||||
from pathlib import Path
|
||||
from types import MappingProxyType
|
||||
from typing import Final
|
||||
|
|
@ -276,29 +277,40 @@ def test_every_bedrock_openai_gpt_row_advertises_xhigh(prices: dict):
|
|||
assert missing == []
|
||||
|
||||
|
||||
def is_active_priced_mistral_chat_row(name: str, entry: dict) -> bool:
|
||||
def is_active_priced_mistral_chat_row(name: str, entry: Mapping[str, object]) -> bool:
|
||||
input_cost: Final = entry.get("input_cost_per_token")
|
||||
return (
|
||||
name.startswith("mistral/")
|
||||
and entry.get("mode") == "chat"
|
||||
and entry.get("deprecation_date") is None
|
||||
and (entry.get("input_cost_per_token") or 0) > 0
|
||||
and isinstance(input_cost, (int, float))
|
||||
and input_cost > 0
|
||||
)
|
||||
|
||||
|
||||
def test_active_mistral_chat_rows_price_cache_reads_below_input(prices: dict):
|
||||
def cache_read_is_tenth_of_input(entry: Mapping[str, object]) -> bool:
|
||||
cache_read: Final = entry.get("cache_read_input_token_cost")
|
||||
input_cost: Final = entry.get("input_cost_per_token")
|
||||
return (
|
||||
isinstance(cache_read, float)
|
||||
and isinstance(input_cost, (int, float))
|
||||
and 0 < cache_read < input_cost
|
||||
and cache_read == pytest.approx(input_cost / 10)
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("path", (PRICES_PATH, BACKUP_PRICES_PATH), ids=("main", "backup"))
|
||||
def test_active_mistral_chat_rows_price_cache_reads_below_input(path: Path):
|
||||
"""A Mistral chat row without a cache-read rate bills cached prompt tokens at zero, so every
|
||||
active priced row must carry one, and it must be cheaper than a fresh input token. Mistral
|
||||
bills cached tokens at 10% of the input price for every model (docs.mistral.ai/studio/
|
||||
conversations/advanced/prompt-caching, read 2026-09-18), so the ratio is checked as well."""
|
||||
rows: Mapping[str, object] = json.loads(path.read_text())
|
||||
drifted: Final = [
|
||||
f"{name}: cache_read={entry.get('cache_read_input_token_cost')} input={entry['input_cost_per_token']}"
|
||||
for name, entry in prices.items()
|
||||
f"{name}: cache_read={entry.get('cache_read_input_token_cost')} input={entry.get('input_cost_per_token')}"
|
||||
for name, entry in rows.items()
|
||||
if isinstance(entry, dict)
|
||||
and is_active_priced_mistral_chat_row(name, entry)
|
||||
and not (
|
||||
isinstance(entry.get("cache_read_input_token_cost"), float)
|
||||
and 0 < entry["cache_read_input_token_cost"] < entry["input_cost_per_token"]
|
||||
and entry["cache_read_input_token_cost"] == pytest.approx(entry["input_cost_per_token"] / 10)
|
||||
)
|
||||
and not cache_read_is_tenth_of_input(entry)
|
||||
]
|
||||
assert drifted == []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue