From 79d51e0bdd143385cdd27ca0fafba48f9732c565 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 25 Nov 2024 15:31:56 -0800 Subject: [PATCH] add doc string --- litellm/proxy/auth/auth_checks.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index d5485fdc0..b47cb19a5 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -886,6 +886,21 @@ async def can_key_call_model( def _model_is_within_list_of_allowed_models( model: str, allowed_models: List[str] ) -> bool: + """ + Checks if a model is within a list of allowed models (includes pattern matching checks) + + Args: + model (str): The model to check (e.g., "custom_engine/model-123") + allowed_models (List[str]): List of allowed model patterns (e.g., ["custom_engine/*", "azure/gpt-4", "claude-sonnet"]) + + Returns: + bool: True if + - len(allowed_models) == 0 + - "*" in allowed_models (means all models are allowed) + - "all-proxy-models" in allowed_models (means all models are allowed) + - model is in allowed_models list + - model matches any allowed pattern + """ # Check for universal access patterns if len(allowed_models) == 0: return True @@ -895,13 +910,13 @@ def _model_is_within_list_of_allowed_models( return True if model in allowed_models: return True - if model_matches_patterns(model=model, allowed_models=allowed_models) is True: + if _model_matches_patterns(model=model, allowed_models=allowed_models) is True: return True return False -def model_matches_patterns(model: str, allowed_models: List[str]) -> bool: +def _model_matches_patterns(model: str, allowed_models: List[str]) -> bool: """ Helper function to check if a model matches any of the allowed model patterns.