-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
fix(router): register model info under responses/-stripped variant #27531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7076,11 +7076,11 @@ def _create_deployment( | |||||||||||||||||||||||||||||
| _shared_model_info = { | ||||||||||||||||||||||||||||||
| k: v for k, v in _model_info.items() if k not in _custom_pricing_fields | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| litellm.register_model( | ||||||||||||||||||||||||||||||
| model_cost={ | ||||||||||||||||||||||||||||||
| _model_name: _shared_model_info, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| _backend_alias_cost = {_model_name: _shared_model_info} | ||||||||||||||||||||||||||||||
| if "responses/" in _model_name: | ||||||||||||||||||||||||||||||
| _stripped_model_name = _model_name.replace("responses/", "") | ||||||||||||||||||||||||||||||
| _backend_alias_cost[_stripped_model_name] = _shared_model_info | ||||||||||||||||||||||||||||||
| litellm.register_model(model_cost=_backend_alias_cost) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## Check if LLM Deployment is allowed for this deployment | ||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||
|
|
@@ -7752,20 +7752,44 @@ def add_deployment(self, deployment: Deployment) -> Optional[Deployment]: | |||||||||||||||||||||||||||||
| # initialize client | ||||||||||||||||||||||||||||||
| self._add_deployment(deployment=deployment) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| _model_info_dict: dict = deployment.model_info.model_dump(exclude_none=True) | ||||||||||||||||||||||||||||||
| for field in CustomPricingLiteLLMParams.model_fields.keys(): | ||||||||||||||||||||||||||||||
| field_value = deployment.litellm_params.get(field) | ||||||||||||||||||||||||||||||
| if field_value is not None: | ||||||||||||||||||||||||||||||
| _model_info_dict[field] = field_value | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Register custom pricing in litellm.model_cost. | ||||||||||||||||||||||||||||||
| # Mirrors _create_deployment() logic to ensure dynamically-added deployments | ||||||||||||||||||||||||||||||
| # (e.g., loaded from DB) also have their custom pricing registered. | ||||||||||||||||||||||||||||||
| # Without this, _is_model_cost_zero() cannot detect explicitly-configured | ||||||||||||||||||||||||||||||
| # zero-cost models, causing budget checks to block free models. | ||||||||||||||||||||||||||||||
| _model_id = deployment.model_info.id | ||||||||||||||||||||||||||||||
| if _model_id is not None: | ||||||||||||||||||||||||||||||
| _model_info_dict: dict = deployment.model_info.model_dump(exclude_none=True) | ||||||||||||||||||||||||||||||
| for field in CustomPricingLiteLLMParams.model_fields.keys(): | ||||||||||||||||||||||||||||||
| field_value = deployment.litellm_params.get(field) | ||||||||||||||||||||||||||||||
| if field_value is not None: | ||||||||||||||||||||||||||||||
| _model_info_dict[field] = field_value | ||||||||||||||||||||||||||||||
| litellm.register_model(model_cost={_model_id: _model_info_dict}) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| ## REGISTER MODEL INFO IN LITELLM MODEL COST MAP | ||||||||||||||||||||||||||||||
| ## OLD MODEL REGISTRATION ## Kept to prevent breaking changes | ||||||||||||||||||||||||||||||
| _model_name = deployment.litellm_params.model | ||||||||||||||||||||||||||||||
| if deployment.litellm_params.custom_llm_provider is not None: | ||||||||||||||||||||||||||||||
| _model_name = ( | ||||||||||||||||||||||||||||||
| deployment.litellm_params.custom_llm_provider + "/" + _model_name | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # For the shared backend key, strip custom pricing fields so that | ||||||||||||||||||||||||||||||
| # one deployment's pricing overrides don't pollute another | ||||||||||||||||||||||||||||||
| # deployment sharing the same backend model name. | ||||||||||||||||||||||||||||||
| # Each deployment's full pricing is already stored under its | ||||||||||||||||||||||||||||||
| # unique model_id above (when present). | ||||||||||||||||||||||||||||||
| _custom_pricing_fields = CustomPricingLiteLLMParams.model_fields.keys() | ||||||||||||||||||||||||||||||
| _shared_model_info = { | ||||||||||||||||||||||||||||||
| k: v for k, v in _model_info_dict.items() if k not in _custom_pricing_fields | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| _backend_alias_cost = {_model_name: _shared_model_info} | ||||||||||||||||||||||||||||||
| if "responses/" in _model_name: | ||||||||||||||||||||||||||||||
| _stripped_model_name = _model_name.replace("responses/", "") | ||||||||||||||||||||||||||||||
| _backend_alias_cost[_stripped_model_name] = _shared_model_info | ||||||||||||||||||||||||||||||
| litellm.register_model(model_cost=_backend_alias_cost) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # add to model names | ||||||||||||||||||||||||||||||
|
Comment on lines
+7787
to
7793
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||
| self._add_model_to_list_and_index_map( | ||||||||||||||||||||||||||||||
| model=_deployment, model_id=deployment.model_info.id | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"responses/" in _model_nameoperates on the fully-constructedprovider/modelstring, so a model named something likeazure/custom-responses/v2(where "responses/" is not a prefix of the model field) would also trigger the alias stripping and produceazure/custom-v2— a potentially incorrect or conflicting key. A tighter guard that checks only thelitellm_params.modelfield (before prepending the provider) avoids this false-positive.str.replacewithoutcount=1would also replace multiple occurrences of"responses/"if they exist.