Skip to content

Fix compact dated LiteLLM model refs#346

Open
Kcstring wants to merge 1 commit intopydantic:mainfrom
Kcstring:fix-litellm-compact-date-model-refs
Open

Fix compact dated LiteLLM model refs#346
Kcstring wants to merge 1 commit intopydantic:mainfrom
Kcstring:fix-litellm-compact-date-model-refs

Conversation

@Kcstring
Copy link
Copy Markdown
Contributor

Fixes #333

Summary

  • normalize trailing compact date model refs like gpt-5.2-20251211 as a fallback after exact model lookup fails
  • keep the original cache key so repeated lookups of the original ref still benefit from caching
  • cover both find_provider_model and the public calc_price path for LiteLLM-prefixed refs

Tests

  • UV_CACHE_DIR=/tmp/uv-cache UV_PYTHON_INSTALL_DIR=/tmp/uv-python uv run --package genai-prices pytest tests/test_model_matching.py -k litellm_provider_id
  • UV_CACHE_DIR=/tmp/uv-cache UV_PYTHON_INSTALL_DIR=/tmp/uv-python uv run --package genai-prices pytest tests/test_price_calc.py -k compact_date_model_ref
  • UV_CACHE_DIR=/tmp/uv-cache UV_PYTHON_INSTALL_DIR=/tmp/uv-python uv run --package genai-prices ruff check packages/python/genai_prices/data_snapshot.py tests/test_model_matching.py tests/test_price_calc.py
  • UV_CACHE_DIR=/tmp/uv-cache UV_PYTHON_INSTALL_DIR=/tmp/uv-python uv run --package genai-prices ruff format --check packages/python/genai_prices/data_snapshot.py tests/test_model_matching.py tests/test_price_calc.py
  • UV_CACHE_DIR=/tmp/uv-cache UV_PYTHON_INSTALL_DIR=/tmp/uv-python uv run --package genai-prices basedpyright packages/python/genai_prices/data_snapshot.py tests/test_model_matching.py tests/test_price_calc.py

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review


normalized_model_ref = _normalize_compact_date_model_ref(model_ref)
if normalized_model_ref != model_ref and (
model := provider.find_model(normalized_model_ref, all_providers=self.providers)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about putting this logic in provider.find_model instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LiteLLM/OpenRouter] pricing lookup fails for compact dated model refs

2 participants