mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix(test): use model with cache pricing so assertion actually executes
Switch test from `fireworks_ai/llama-v3p3-70b-instruct` (no cache_read_input_token_cost) to `fireworks_ai/kimi-k2p5` (has cache pricing at 1e-07 vs input 6e-07). Remove the conditional guard so the assertion always runs. Addresses Greptile review feedback on #24860. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: GopalGB <67310594+GopalGB@users.noreply.github.com>
This commit is contained in:
parent
73112c87ac
commit
a7a0c328d4
2 changed files with 9 additions and 15 deletions
|
|
@ -91,9 +91,7 @@ def cost_per_token(model: str, usage: Usage) -> Tuple[float, float]:
|
|||
)
|
||||
|
||||
## ADJUST FOR CACHE CREATION TOKENS
|
||||
cache_creation_input_tokens = (
|
||||
usage.get("cache_creation_input_tokens", None) or 0
|
||||
)
|
||||
cache_creation_input_tokens = usage.get("cache_creation_input_tokens", None) or 0
|
||||
cache_creation_cost = model_info.get("cache_creation_input_token_cost", None)
|
||||
if cache_creation_input_tokens > 0 and cache_creation_cost is not None:
|
||||
prompt_cost += cache_creation_input_tokens * (
|
||||
|
|
|
|||
|
|
@ -1221,27 +1221,23 @@ def test_fireworks_ai_cache_token_pricing():
|
|||
os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"
|
||||
litellm.model_cost = litellm.get_model_cost_map(url="")
|
||||
|
||||
# Use kimi-k2p5 which has cache_read_input_token_cost in the pricing config
|
||||
prompt_cost_cached, completion_cost_cached = cost_per_token(
|
||||
model="fireworks_ai/llama-v3p3-70b-instruct", usage=usage_with_cache
|
||||
model="fireworks_ai/kimi-k2p5", usage=usage_with_cache
|
||||
)
|
||||
prompt_cost_no_cache, completion_cost_no_cache = cost_per_token(
|
||||
model="fireworks_ai/llama-v3p3-70b-instruct", usage=usage_no_cache
|
||||
model="fireworks_ai/kimi-k2p5", usage=usage_no_cache
|
||||
)
|
||||
|
||||
# Completion cost should be the same regardless of cache
|
||||
assert completion_cost_cached == completion_cost_no_cache
|
||||
|
||||
# If the model has cache pricing, the prompt cost with cache should differ
|
||||
# from the prompt cost without cache (cache read rate is cheaper)
|
||||
model_info = litellm.get_model_info(
|
||||
model="fireworks_ai/llama-v3p3-70b-instruct",
|
||||
custom_llm_provider="fireworks_ai",
|
||||
# kimi-k2p5 has cache_read_input_token_cost (1e-07) < input_cost_per_token (6e-07),
|
||||
# so prompt cost with 800 cache-read tokens must be cheaper
|
||||
assert prompt_cost_cached < prompt_cost_no_cache, (
|
||||
"Prompt cost with 800 cache-read tokens should be less than "
|
||||
"full-price for the same total prompt tokens"
|
||||
)
|
||||
if model_info.get("cache_read_input_token_cost") is not None:
|
||||
assert prompt_cost_cached < prompt_cost_no_cache, (
|
||||
"Prompt cost with 800 cache-read tokens should be less than "
|
||||
"full-price for the same total prompt tokens"
|
||||
)
|
||||
|
||||
|
||||
def test_cost_azure_openai_prompt_caching():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue