fix: strip provider prefixes from catalog keys and handle collisions - #3
Conversation
Strip LiteLLM provider prefixes (bedrock/, deepseek/, sagemaker/) from catalog keys to produce cleaner URIs. When two LiteLLM entries collide on the same key, prefer the prefixed (canonical) entry. Updates tests to reflect the new key format. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @vsraccubits, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors how LiteLLM model catalog keys are generated and managed. It introduces a standardized approach to strip provider-specific prefixes from model keys, resulting in cleaner and more consistent URIs. Additionally, it implements a robust collision resolution strategy to ensure that when multiple LiteLLM entries map to the same catalog key, the most appropriate (prefixed) entry is retained, improving data integrity and catalog usability. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request successfully implements stripping of LiteLLM provider prefixes from catalog keys and adds logic to handle collisions by preferring canonical (prefixed) entries. The changes are well-tested and improve the clarity of the generated URIs. I have suggested an enhancement to the collision logging for better observability.
| if new_key in result: | ||
| prefix = STRIP_PREFIXES.get(tz_provider) | ||
| if prefix: | ||
| existing_original = result[new_key]["metadata"]["original_key"] | ||
| # Keep the prefixed entry (canonical LiteLLM routing format) | ||
| if existing_original.startswith(prefix) and not original_key.startswith(prefix): | ||
| skipped += 1 | ||
| continue | ||
| logger.warning("Catalog key collision on '%s', overwriting", new_key) |
There was a problem hiding this comment.
The collision warning log could be more informative by including the specific original keys that are colliding. This helps in identifying which entries in the LiteLLM pricing data are causing the issue. Moving the extraction of existing_original outside the if prefix block allows it to be used in the log message regardless of whether a prefix is defined for the provider.
| if new_key in result: | |
| prefix = STRIP_PREFIXES.get(tz_provider) | |
| if prefix: | |
| existing_original = result[new_key]["metadata"]["original_key"] | |
| # Keep the prefixed entry (canonical LiteLLM routing format) | |
| if existing_original.startswith(prefix) and not original_key.startswith(prefix): | |
| skipped += 1 | |
| continue | |
| logger.warning("Catalog key collision on '%s', overwriting", new_key) | |
| if new_key in result: | |
| existing_original = result[new_key]["metadata"]["original_key"] | |
| prefix = STRIP_PREFIXES.get(tz_provider) | |
| if prefix: | |
| # Keep the prefixed entry (canonical LiteLLM routing format) | |
| if existing_original.startswith(prefix) and not original_key.startswith(prefix): | |
| skipped += 1 | |
| continue | |
| logger.warning( | |
| "Catalog key collision on '%s': overwriting '%s' with '%s'", | |
| new_key, | |
| existing_original, | |
| original_key, | |
| ) |
Summary
gemini/gemini-2.0-flashanddeepseek/deepseek-chathad doubled prefixes in the catalog (e.g.gemini/gemini/gemini-2.0-flash). Addedbedrock/,deepseek/, andsagemaker/toSTRIP_PREFIXESand introducedstrip_provider_prefix()to produce clean{provider}/{model}keys.deepseek-chat) and a prefixed key (deepseek/deepseek-chat) for the same model. After prefix stripping, both map todeepseek/deepseek-chat. The collision handler now always prefers the prefixed (canonical) entry regardless of iteration order.Changes
src/bud_model_catalog/mappings.pybedrock/,deepseek/,sagemaker/toSTRIP_PREFIXES; addedstrip_provider_prefix()helpersrc/bud_model_catalog/sources/litellm.pystrip_provider_prefix()for key construction; added collision resolution logictests/test_litellm_source.pytests/test_merger.pygemini/gemini/gemini-2.0-flashtogemini/gemini-2.0-flashin fixtureTest plan
test_collision_prefers_prefixed_entry— bare key first, prefixed key secondtest_collision_prefers_prefixed_entry_reverse_order— prefixed key first, bare key secondpytest -vto verify all tests pass🤖 Generated with Claude Code