mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(proxy): mirror routerless and fully-blocked paths in routability check
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
e72d2f3b77
commit
52992e42ae
2 changed files with 15 additions and 6 deletions
|
|
@ -580,6 +580,7 @@ async def route_request(
|
|||
def _router_can_route(
|
||||
data: Mapping[str, object],
|
||||
llm_router: LitellmRouter | None,
|
||||
user_model: str | None,
|
||||
route_type: str,
|
||||
) -> bool:
|
||||
"""Pure predicate mirroring the branch structure of _route_request_single_attempt.
|
||||
|
|
@ -587,17 +588,18 @@ def _router_can_route(
|
|||
Returns True when the existing routing tree would dispatch this request
|
||||
somewhere instead of falling through to the final ProxyModelNotFoundError.
|
||||
"""
|
||||
if llm_router is None:
|
||||
return True
|
||||
if route_type in _NO_MODEL_ROUTING_ROUTE_TYPES:
|
||||
return True
|
||||
if "api_key" in data or "api_base" in data:
|
||||
return True
|
||||
model: Final = data.get("model")
|
||||
if route_type == "acompletion" and isinstance(model, str) and "," in model:
|
||||
if route_type == "acompletion" and isinstance(model, str) and "," in model and llm_router is not None:
|
||||
return True
|
||||
if "user_config" in data or "router_settings_override" in data:
|
||||
return True
|
||||
if llm_router is None:
|
||||
return user_model is not None or route_type == "allm_passthrough_route"
|
||||
_raise_if_model_fully_blocked(llm_router=llm_router, model_name=model, team_id=get_team_id_from_data(dict(data)))
|
||||
if (
|
||||
route_type in _EVAL_ROUTE_TYPES
|
||||
or route_type in _CONTAINER_ROUTE_TYPES
|
||||
|
|
@ -657,7 +659,7 @@ async def raise_if_model_not_routable(
|
|||
Lets pre-call steps (e.g. guardrails) skip work for requests that can never
|
||||
route, and mirrors route_request's registry read-through retry.
|
||||
"""
|
||||
if _router_can_route(data=data, llm_router=llm_router, route_type=route_type):
|
||||
if _router_can_route(data=data, llm_router=llm_router, user_model=user_model, route_type=route_type):
|
||||
return
|
||||
requested_model: Final = data.get("model")
|
||||
if isinstance(requested_model, str) and requested_model:
|
||||
|
|
@ -667,7 +669,7 @@ async def raise_if_model_not_routable(
|
|||
)
|
||||
|
||||
if await model_registry_read_through.attempt(requested_model) and _router_can_route(
|
||||
data=data, llm_router=proxy_server.llm_router, route_type=route_type
|
||||
data=data, llm_router=proxy_server.llm_router, user_model=user_model, route_type=route_type
|
||||
):
|
||||
return
|
||||
raise ProxyModelNotFoundError(
|
||||
|
|
|
|||
|
|
@ -300,6 +300,7 @@ class TestProxyBaseLLMRequestProcessing:
|
|||
mock_general_settings = {}
|
||||
mock_user_api_key_dict = MagicMock(spec=UserAPIKeyAuth)
|
||||
mock_proxy_config = MagicMock(spec=ProxyConfig)
|
||||
mock_proxy_config._get_hierarchical_router_settings = AsyncMock(return_value=None)
|
||||
route_type = "acompletion"
|
||||
|
||||
# Call the actual method.
|
||||
|
|
@ -313,6 +314,7 @@ class TestProxyBaseLLMRequestProcessing:
|
|||
proxy_logging_obj=mock_proxy_logging_obj,
|
||||
proxy_config=mock_proxy_config,
|
||||
route_type=route_type,
|
||||
llm_router=self._router_with_free_and_paid_models(),
|
||||
)
|
||||
|
||||
mock_proxy_logging_obj.pre_call_hook.assert_called_once()
|
||||
|
|
@ -364,14 +366,17 @@ class TestProxyBaseLLMRequestProcessing:
|
|||
"add_litellm_data_to_request",
|
||||
mock_add_litellm_data_to_request,
|
||||
)
|
||||
mock_proxy_config = MagicMock(spec=ProxyConfig)
|
||||
mock_proxy_config._get_hierarchical_router_settings = AsyncMock(return_value=None)
|
||||
|
||||
returned_data, _ = await processing_obj.common_processing_pre_call_logic(
|
||||
request=mock_request,
|
||||
general_settings={},
|
||||
user_api_key_dict=MagicMock(spec=UserAPIKeyAuth),
|
||||
proxy_logging_obj=mock_proxy_logging_obj,
|
||||
proxy_config=MagicMock(spec=ProxyConfig),
|
||||
proxy_config=mock_proxy_config,
|
||||
route_type="acompletion",
|
||||
llm_router=self._router_with_free_and_paid_models(),
|
||||
)
|
||||
|
||||
persisted_body = returned_data["proxy_server_request"]["body"]
|
||||
|
|
@ -1905,6 +1910,7 @@ class TestProxyBaseLLMRequestProcessing:
|
|||
mock_general_settings = {}
|
||||
mock_user_api_key_dict = MagicMock(spec=UserAPIKeyAuth)
|
||||
mock_proxy_config = MagicMock(spec=ProxyConfig)
|
||||
mock_proxy_config._get_hierarchical_router_settings = AsyncMock(return_value=None)
|
||||
route_type = "acompletion"
|
||||
|
||||
(
|
||||
|
|
@ -1917,6 +1923,7 @@ class TestProxyBaseLLMRequestProcessing:
|
|||
proxy_logging_obj=mock_proxy_logging_obj,
|
||||
proxy_config=mock_proxy_config,
|
||||
route_type=route_type,
|
||||
llm_router=self._router_with_free_and_paid_models(),
|
||||
)
|
||||
|
||||
# Verify queue_time_seconds is set and non-negative. Ends at start_time
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue