diff --git a/litellm/proxy/auth/model_checks.py b/litellm/proxy/auth/model_checks.py index a1aa4091d7e..b09c9c4e906 100644 --- a/litellm/proxy/auth/model_checks.py +++ b/litellm/proxy/auth/model_checks.py @@ -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) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 99f24e41e1d..993d81b8fb8 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -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, diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index beddf498dbd..ae62bf5a67c 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -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()