mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(proxy): satisfy strict lint gates in model routability check
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
1b701901bc
commit
6882a2e88e
2 changed files with 19 additions and 11 deletions
|
|
@ -16,7 +16,6 @@ from typing import (
|
|||
Protocol,
|
||||
TypeAlias,
|
||||
TypeVar,
|
||||
cast,
|
||||
overload,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
|
@ -2105,7 +2104,7 @@ class ProxyBaseLLMRequestProcessing:
|
|||
if self._tags_before_guardrails is None:
|
||||
self._tags_before_guardrails = frozenset(get_tags_from_request_body(request_body=self.data))
|
||||
await raise_if_model_not_routable(
|
||||
data=cast(dict[str, object], self.data),
|
||||
data=self.data, # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType] # loosely typed
|
||||
llm_router=llm_router,
|
||||
user_model=user_model,
|
||||
route_type=route_type,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import asyncio
|
||||
from collections.abc import Mapping
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal, cast
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal
|
||||
|
||||
import httpx
|
||||
from fastapi import HTTPException, status
|
||||
|
|
@ -610,27 +610,36 @@ def _router_can_route(
|
|||
if not isinstance(model, str):
|
||||
return True
|
||||
|
||||
return _router_model_group_routable(model=model, llm_router=llm_router, data=data, route_type=route_type)
|
||||
|
||||
|
||||
def _router_model_group_routable(
|
||||
model: str,
|
||||
llm_router: LitellmRouter,
|
||||
data: Mapping[str, object],
|
||||
route_type: str,
|
||||
) -> bool:
|
||||
team_id: Final = get_team_id_from_data(dict(data))
|
||||
if team_id is not None and llm_router.map_team_model(model, team_id) is not None:
|
||||
return True
|
||||
|
||||
router_model_names: Final = cast(set[str], llm_router.model_names)
|
||||
is_proxy_admin_without_team: Final = team_id is None and _is_proxy_admin_request(dict(data))
|
||||
if (
|
||||
is_proxy_admin_without_team and model not in router_model_names and model in llm_router.team_public_model_names
|
||||
is_proxy_admin_without_team
|
||||
and model not in llm_router.model_names # pyright: ignore[reportUnknownMemberType] # bare set
|
||||
and model in llm_router.team_public_model_names
|
||||
) or llm_router.is_recognized_model(model):
|
||||
return True
|
||||
|
||||
if model in router_model_names:
|
||||
if model in llm_router.model_names: # pyright: ignore[reportUnknownMemberType] # bare set
|
||||
return False
|
||||
if llm_router.router_general_settings.pass_through_all_models:
|
||||
return True
|
||||
if (
|
||||
llm_router.default_deployment is not None
|
||||
or len(cast(dict[str, object], llm_router.pattern_router.patterns)) > 0
|
||||
):
|
||||
if llm_router.default_deployment is not None:
|
||||
return True
|
||||
if model in cast(list[str], llm_router.deployment_names):
|
||||
if llm_router.pattern_router.patterns: # pyright: ignore[reportUnknownMemberType] # untyped dict
|
||||
return True
|
||||
if model in llm_router.deployment_names: # pyright: ignore[reportUnknownMemberType] # bare list
|
||||
return True
|
||||
if route_type in _MODEL_OPTIONAL_FALLBACK_ROUTE_TYPES or route_type in _VIDEO_FALLBACK_ROUTE_TYPES:
|
||||
return True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue