mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-06 02:48:13 +00:00
fix(router): call async_pre_routing_hook in non-async routing strategy fallback path
Fixes #26224: complexity_router and other auto-routers that rely on async_pre_routing_hook to resolve router model names were silently bypassed when the default (non-async) routing strategy was active. The async_get_available_deployment function falls back to the sync get_available_deployment for routing strategies that don't have an async implementation. This fallback skipped async_pre_routing_hook entirely, so the model name was never resolved from the router alias (e.g. 'smart-router') to the actual downstream model (e.g. 'claude-sonnet-4-6'), causing downstream errors like 'unknown model auto_router/complexity_router'. Fix: call async_pre_routing_hook before get_available_deployment in the sync fallback path so the model is properly resolved regardless of routing strategy.
This commit is contained in:
parent
f69b9d6564
commit
a2f9963a1d
1 changed files with 14 additions and 0 deletions
|
|
@ -9317,6 +9317,20 @@ class Router:
|
|||
and self.routing_strategy != "latency-based-routing"
|
||||
and self.routing_strategy != "least-busy"
|
||||
): # prevent regressions for other routing strategies, that don't have async get available deployments implemented.
|
||||
# Run async pre-routing hooks (e.g. complexity_router) so that router
|
||||
# model names are resolved to the correct downstream model before
|
||||
# deployment selection, even when a non-async routing strategy is used.
|
||||
pre_routing_hook_response = await self.async_pre_routing_hook(
|
||||
model=model,
|
||||
request_kwargs=request_kwargs,
|
||||
messages=messages,
|
||||
input=input,
|
||||
specific_deployment=specific_deployment,
|
||||
)
|
||||
if pre_routing_hook_response is not None:
|
||||
model = pre_routing_hook_response.model
|
||||
if pre_routing_hook_response.messages is not None:
|
||||
messages = pre_routing_hook_response.messages
|
||||
return self.get_available_deployment(
|
||||
model=model,
|
||||
messages=messages,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue