feat: tier-aware build_model_id_name_mapping#312
Open
NBibikov wants to merge 1 commit intoHanaokaYuzu:masterfrom
Open
feat: tier-aware build_model_id_name_mapping#312NBibikov wants to merge 1 commit intoHanaokaYuzu:masterfrom
NBibikov wants to merge 1 commit intoHanaokaYuzu:masterfrom
Conversation
PLUS and ADVANCED enum members share model_ids with each other; the name stripped to BASIC regardless of tier meant Plus/Advanced accounts would see basic names in the registry and build request headers that did not match the name the caller expected. Pass the account's (capacity, capacity_field) into the mapping so the primary tier is chosen deliberately, with fallbacks covering any ids the primary does not provide. Default args keep the legacy BASIC-only behaviour for any external caller still using the zero-arg form. Update the client to forward the capacity it has already computed. Add unit tests covering all tier combinations; default-args parity guards the legacy contract.
Contributor
|
Don't worry about that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AvailableModel.build_model_id_name_mapping()unconditionally rewritesevery resolved
model_idto itsBASIC_*enum name, even when theaccount is on PLUS or ADVANCED tier. The comment on the existing logic
states the intent, but it means:
capacity=4, capacity_field=12) sees its registeredmodels as
gemini-3-pro,gemini-3-flash,gemini-3-flash-thinking—the Plus variants (
*-plus) are never surfaced throughlist_models().capacity=2) has the same issue vs.*-advanced.model_nameback intogenerate_content(model=...)end up with a name/tier mismatch: thestring resolves via
_resolve_model_by_name→_model_registry, whichreturns the AvailableModel with the account's real capacity header, but
the name the caller saw suggests basic tier.
The PLUS and ADVANCED enum members also share
model_idvalues with eachother (they differ only in the
capacityencoded in the header), so theright name cannot be inferred from
model_idalone — it has to be chosenagainst the caller's tier.
Fix
build_model_id_name_mappingnow takes(capacity, capacity_field)andwalks
Modelin a tier-priority order derived from them. Primary-tierids register first; remaining tiers fill any ids the primary doesn't
cover (e.g.
BASIC_*ids that Plus/Advanced don't share).capacity=1, capacity_field=12)behaviour so any external caller on the zero-arg form is unchanged.
_fetch_user_statusforwards thecapacity/capacity_fieldit alreadycomputes a few lines above.
Tests
New
tests/test_available_model.py— pure unit tests, no network/cookies:-plus/-advanced).BASIC_*unique ids still resolve on higher tiers (fallback works).Backwards compatibility
The function signature gains optional parameters with defaults matching
the free tier, so external callers on the zero-arg form see no change.