mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
test(models): drive Grok prompt caching coverage through litellm APIs
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
ba03f60f71
commit
a229f99ac8
1 changed files with 9 additions and 29 deletions
|
|
@ -1,37 +1,28 @@
|
|||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
import pytest
|
||||
from pydantic import TypeAdapter
|
||||
|
||||
import litellm
|
||||
from litellm import get_model_info
|
||||
from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider
|
||||
from litellm.utils import supports_prompt_caching
|
||||
|
||||
REPO_ROOT: Final = Path(__file__).parents[2]
|
||||
MODEL: Final = "vertex_ai/xai/grok-4.6"
|
||||
GROK_KEY_PREFIXES: Final = ("vertex_ai/xai/grok-", "azure_ai/grok-", "xai/grok-")
|
||||
COST_MAP_ADAPTER: Final = TypeAdapter(dict[str, dict[str, object]])
|
||||
MAIN_COST_MAP: Final = REPO_ROOT / "model_prices_and_context_window.json"
|
||||
BACKUP_COST_MAP: Final = REPO_ROOT / "litellm" / "model_prices_and_context_window_backup.json"
|
||||
|
||||
|
||||
def _cost_map(path: Path) -> dict[str, dict[str, object]]:
|
||||
return COST_MAP_ADAPTER.validate_json(path.read_bytes())
|
||||
|
||||
|
||||
def test_grok_entries_with_cache_read_price_advertise_prompt_caching() -> None:
|
||||
cost_map = _cost_map(MAIN_COST_MAP)
|
||||
cached_grok_entries = tuple(
|
||||
(key, entry)
|
||||
for key, entry in cost_map.items()
|
||||
@pytest.mark.usefixtures("local_model_cost_map")
|
||||
def test_grok_models_with_cache_read_price_advertise_prompt_caching() -> None:
|
||||
cached_grok_models = tuple(
|
||||
key
|
||||
for key, entry in litellm.model_cost.items()
|
||||
if key.startswith(GROK_KEY_PREFIXES) and entry.get("cache_read_input_token_cost")
|
||||
)
|
||||
assert cached_grok_entries, "expected at least one grok entry with a cache read price"
|
||||
assert cached_grok_models, "expected at least one grok model with a cache read price"
|
||||
|
||||
missing_flag = tuple(key for key, entry in cached_grok_entries if entry.get("supports_prompt_caching") is not True)
|
||||
missing_flag = tuple(key for key in cached_grok_models if supports_prompt_caching(model=key) is not True)
|
||||
assert missing_flag == (), (
|
||||
f"grok entries with cache_read_input_token_cost missing supports_prompt_caching: {missing_flag}"
|
||||
f"grok models with cache_read_input_token_cost fail supports_prompt_caching: {missing_flag}"
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -45,14 +36,3 @@ def test_vertex_ai_grok_4_6_supports_prompt_caching_via_get_model_info() -> None
|
|||
assert info.get("supports_prompt_caching") is True
|
||||
|
||||
assert supports_prompt_caching(model=MODEL) is True
|
||||
|
||||
|
||||
def test_vertex_ai_grok_entries_source_and_backup_match() -> None:
|
||||
main_map = _cost_map(MAIN_COST_MAP)
|
||||
backup_map = _cost_map(BACKUP_COST_MAP)
|
||||
|
||||
vertex_grok_keys = tuple(key for key in main_map if key.startswith("vertex_ai/xai/grok-"))
|
||||
assert vertex_grok_keys, "expected at least one vertex_ai/xai/grok- entry"
|
||||
|
||||
mismatched = tuple(key for key in vertex_grok_keys if backup_map.get(key) != main_map[key])
|
||||
assert mismatched == (), f"vertex grok entries differ between source and backup: {mismatched}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue