test_update_model_cost_map_url

This commit is contained in:
Ishaan Jaffer 2025-12-22 12:58:49 +05:30
parent 09dcb38b4b
commit 29513cf6a6

View file

@ -2364,14 +2364,27 @@ def register_model(model_cost: Union[str, dict]): # noqa: PLR0915
elif isinstance(model_cost, str):
loaded_model_cost = litellm.get_model_cost_map(url=model_cost)
# Providers that trigger side effects (e.g., OAuth flows) when get_model_info is called
# Skip get_model_info for these providers during model registration
_skip_get_model_info_providers = {
LlmProviders.GITHUB_COPILOT.value,
}
for key, value in loaded_model_cost.items():
## get model info ##
try:
existing_model: dict = cast(dict, get_model_info(model=key))
model_cost_key = existing_model["key"]
except Exception:
existing_model = {}
provider = value.get("litellm_provider", "")
if provider in _skip_get_model_info_providers or any(
key.startswith(f"{p}/") for p in _skip_get_model_info_providers
):
existing_model = litellm.model_cost.get(key, {})
model_cost_key = key
else:
try:
existing_model = cast(dict, get_model_info(model=key))
model_cost_key = existing_model["key"]
except Exception:
existing_model = {}
model_cost_key = key
## override / add new keys to the existing model cost dictionary
updated_dictionary = _update_dictionary(existing_model, value)
litellm.model_cost.setdefault(model_cost_key, {}).update(updated_dictionary)