mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
chore(typing): use PEP585/PEP604 syntax on the lines touched by this PR
Upstream's new ruff-strict-budget gate (be4fa702e7) caps UP006
(typing.List/Dict/Set → list/dict/set) and UP045 (typing.Optional → X |
None) per delta-vs-base. Our PR added 35 UP006 and 6 UP045 over the cap.
Mechanical conversion on the exact lines the gate listed; no behavior
change. Files touched: litellm/proxy/auth/model_checks.py (get_user_models
+ filter_models_by_user_access signatures + a Set[str] annotation),
litellm/proxy/utils.py (the three filter helpers' signatures + two
inline `model_access_groups` annotations + a `proxy_model_list`
annotation), litellm/proxy/proxy_server.py (non_admin_all_models
signature + two Optional[List[str]] locals at model_info_v1 and
model_info_v2 sites).
Forward-ref Optional["Router"] / Optional["PrismaClient"] /
Optional["ProxyLogging"] / Optional["DualCache"] left alone because
they're already excluded by UP045 (forward-ref strings don't trigger
the rule on the current ruff config).
Local verification:
- scripts/ruff_strict_gate.py --base <staging>: OK
- scripts/type_discipline_gate.py --base <staging>: OK
- scripts/check_any_discipline.py --changed --base <staging>: OK
- scripts/budget_ratchet_check.py --base <staging>: OK
- 71/71 tests/test_litellm/proxy/discovery_endpoints/ +
tests/test_litellm/proxy/proxy_server/test_routes_model_info.py
This commit is contained in:
parent
da700843cb
commit
be9bca5186
3 changed files with 28 additions and 28 deletions
|
|
@ -164,7 +164,7 @@ def get_team_models(
|
|||
- Empty list if no models set
|
||||
- If model_access_groups is provided, only return models that are in the access groups
|
||||
"""
|
||||
all_models_set: Set[str] = set()
|
||||
all_models_set: set[str] = set()
|
||||
if len(team_models) > 0:
|
||||
all_models_set.update(team_models)
|
||||
if SpecialModelNames.all_team_models.value in all_models_set:
|
||||
|
|
@ -194,11 +194,11 @@ def get_team_models(
|
|||
|
||||
|
||||
def get_user_models(
|
||||
user_models: List[str],
|
||||
proxy_model_list: List[str],
|
||||
model_access_groups: Dict[str, List[str]],
|
||||
include_model_access_groups: Optional[bool] = False,
|
||||
) -> List[str]:
|
||||
user_models: list[str],
|
||||
proxy_model_list: list[str],
|
||||
model_access_groups: dict[str, list[str]],
|
||||
include_model_access_groups: bool | None = False,
|
||||
) -> list[str]:
|
||||
"""
|
||||
Returns:
|
||||
- List of model name strings allowed by `LiteLLM_UserTable.models`
|
||||
|
|
@ -211,7 +211,7 @@ def get_user_models(
|
|||
listing path so it stays consistent with `can_user_call_model` at
|
||||
inference time (see BerriAI/litellm#26420).
|
||||
"""
|
||||
all_models_set: Set[str] = set()
|
||||
all_models_set: set[str] = set()
|
||||
if len(user_models) > 0:
|
||||
all_models_set.update(user_models)
|
||||
if SpecialModelNames.all_proxy_models.value in all_models_set:
|
||||
|
|
@ -233,9 +233,9 @@ def get_user_models(
|
|||
|
||||
|
||||
def filter_models_by_user_access(
|
||||
models: List[str],
|
||||
user_allowed_models: List[str],
|
||||
) -> List[str]:
|
||||
models: list[str],
|
||||
user_allowed_models: list[str],
|
||||
) -> list[str]:
|
||||
"""
|
||||
Return the subset of `models` that the user is allowed to see, given
|
||||
the (already-expanded) `user_allowed_models` list. Supports exact
|
||||
|
|
@ -248,7 +248,7 @@ def filter_models_by_user_access(
|
|||
"""
|
||||
exact = {m for m in user_allowed_models if "*" not in m}
|
||||
patterns = [m for m in user_allowed_models if "*" in m]
|
||||
out: List[str] = []
|
||||
out: list[str] = []
|
||||
for m in models:
|
||||
if m in exact:
|
||||
out.append(m)
|
||||
|
|
|
|||
|
|
@ -11431,11 +11431,11 @@ def _check_if_model_is_team_model(
|
|||
|
||||
|
||||
async def non_admin_all_models(
|
||||
all_models: List[Dict],
|
||||
all_models: list[dict],
|
||||
llm_router: Router,
|
||||
user_api_key_dict: UserAPIKeyAuth,
|
||||
prisma_client: Optional[PrismaClient],
|
||||
) -> Tuple[List[Dict], Optional[List[str]]]:
|
||||
prisma_client: PrismaClient | None,
|
||||
) -> tuple[list[dict], list[str] | None]:
|
||||
"""
|
||||
Check if model is in db
|
||||
|
||||
|
|
@ -11467,7 +11467,7 @@ async def non_admin_all_models(
|
|||
prisma_client=prisma_client,
|
||||
)
|
||||
|
||||
user_models: Optional[List[str]] = None
|
||||
user_models: list[str] | None = None
|
||||
if user_api_key_dict.user_id:
|
||||
try:
|
||||
user_row = await UserRepository(prisma_client).table.find_unique(
|
||||
|
|
@ -12653,7 +12653,7 @@ async def model_info_v2(
|
|||
# the user's `models` list here so the filter step below can
|
||||
# forward it as `user_models_override` and skip a second
|
||||
# `get_user_object` call on cache miss.
|
||||
user_models_for_filter: Optional[List[str]] = None
|
||||
user_models_for_filter: list[str] | None = None
|
||||
if user_models_only:
|
||||
all_models, user_models_for_filter = await non_admin_all_models(
|
||||
all_models=all_models,
|
||||
|
|
|
|||
|
|
@ -6454,14 +6454,14 @@ async def get_available_models_for_user(
|
|||
|
||||
|
||||
async def _apply_user_models_filter(
|
||||
all_models: List[str],
|
||||
all_models: list[str],
|
||||
user_api_key_dict: "UserAPIKeyAuth",
|
||||
model_access_groups: Dict[str, List[str]],
|
||||
model_access_groups: dict[str, list[str]],
|
||||
prisma_client: Optional["PrismaClient"],
|
||||
proxy_logging_obj: Optional["ProxyLogging"],
|
||||
user_api_key_cache: Optional["DualCache"],
|
||||
user_models_override: Optional[List[str]] = None,
|
||||
) -> List[str]:
|
||||
user_models_override: list[str] | None = None,
|
||||
) -> list[str]:
|
||||
"""
|
||||
Intersect `all_models` with `LiteLLM_UserTable.models` (Personal
|
||||
Models) for the user behind `user_api_key_dict`.
|
||||
|
|
@ -6549,14 +6549,14 @@ async def _apply_user_models_filter(
|
|||
|
||||
|
||||
async def apply_user_models_filter_to_deployments(
|
||||
deployments: List[Dict[str, Any]],
|
||||
deployments: list[dict[str, Any]],
|
||||
user_api_key_dict: "UserAPIKeyAuth",
|
||||
llm_router: Optional["Router"],
|
||||
prisma_client: Optional["PrismaClient"],
|
||||
proxy_logging_obj: Optional["ProxyLogging"],
|
||||
user_api_key_cache: Optional["DualCache"],
|
||||
user_models_override: Optional[List[str]] = None,
|
||||
) -> List[Dict[str, Any]]:
|
||||
user_models_override: list[str] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Apply the `LiteLLM_UserTable.models` (Personal Models) filter to a
|
||||
deployment-shaped list (`List[Dict]` with `model_name` keys), reusing
|
||||
|
|
@ -6582,7 +6582,7 @@ async def apply_user_models_filter_to_deployments(
|
|||
return deployments
|
||||
|
||||
if llm_router is None:
|
||||
model_access_groups: Dict[str, List[str]] = {}
|
||||
model_access_groups: dict[str, list[str]] = {}
|
||||
else:
|
||||
model_access_groups = llm_router.get_model_access_groups()
|
||||
|
||||
|
|
@ -6604,10 +6604,10 @@ async def apply_user_models_filter_to_deployments(
|
|||
|
||||
|
||||
async def apply_key_team_models_filter_to_deployments(
|
||||
deployments: List[Dict[str, Any]],
|
||||
deployments: list[dict[str, Any]],
|
||||
user_api_key_dict: "UserAPIKeyAuth",
|
||||
llm_router: Optional["Router"],
|
||||
) -> List[Dict[str, Any]]:
|
||||
) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Bound deployments by the calling key's `models` and the key's
|
||||
team's `team_models`. Mirrors the listing-path filter that
|
||||
|
|
@ -6633,8 +6633,8 @@ async def apply_key_team_models_filter_to_deployments(
|
|||
return deployments
|
||||
|
||||
if llm_router is None:
|
||||
proxy_model_list: List[str] = []
|
||||
model_access_groups: Dict[str, List[str]] = {}
|
||||
proxy_model_list: list[str] = []
|
||||
model_access_groups: dict[str, list[str]] = {}
|
||||
else:
|
||||
proxy_model_list = llm_router.get_model_names()
|
||||
model_access_groups = llm_router.get_model_access_groups()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue