perf: skip pattern_router.route() for non-wildcard models (#19664)

Check "*" in model before calling pattern_router.route() to avoid
unnecessary pattern matching for non-wildcard model configurations.
This commit is contained in:
ryan-crabbe 2026-01-23 17:21:41 -08:00 committed by GitHub
parent 54f9ad370f
commit 6e930c9724
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6355,19 +6355,20 @@ class Router:
elif custom_llm_provider != "azure":
model = _model
potential_models = self.pattern_router.route(received_model_name)
if "*" in model and potential_models is not None: # if wildcard route
for potential_model in potential_models:
try:
if potential_model.get("model_info", {}).get(
"id"
) == deployment.get("model_info", {}).get("id"):
model = potential_model.get("litellm_params", {}).get(
"model"
)
break
except Exception:
pass
if "*" in model: # only call pattern_router for wildcard models
potential_models = self.pattern_router.route(received_model_name)
if potential_models is not None:
for potential_model in potential_models:
try:
if potential_model.get("model_info", {}).get(
"id"
) == deployment.get("model_info", {}).get("id"):
model = potential_model.get("litellm_params", {}).get(
"model"
)
break
except Exception:
pass
## GET LITELLM MODEL INFO - raises exception, if model is not mapped
if model is None: