speed up use_custom_pricing_for_model (#7674)

This commit is contained in:
Ishaan Jaff 2025-01-10 14:00:48 -08:00 • committed by GitHub
parent af08a0caed
commit b3bd15e35a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2561,19 +2561,22 @@ def _get_custom_logger_settings_from_proxy_server(callback_name: str) -> Dict:
def use_custom_pricing_for_model(litellm_params: Optional[dict]) -> bool:
"""
Check if the model uses custom pricing
Returns True if any of `SPECIAL_MODEL_INFO_PARAMS` are present in `litellm_params` or `model_info`
"""
if litellm_params is None:
return False
for k, v in litellm_params.items():
if k in SPECIAL_MODEL_INFO_PARAMS and v is not None:
metadata: dict = litellm_params.get("metadata", {}) or {}
model_info: dict = metadata.get("model_info", {}) or {}
for _custom_cost_param in SPECIAL_MODEL_INFO_PARAMS:
if litellm_params.get(_custom_cost_param, None) is not None:
return True
elif model_info.get(_custom_cost_param, None) is not None:
return True
metadata: Optional[dict] = litellm_params.get("metadata", {})
if metadata is None:
return False
model_info: Optional[dict] = metadata.get("model_info", {})
if model_info is not None:
for k, v in model_info.items():
if k in SPECIAL_MODEL_INFO_PARAMS:
return True
return False