mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +00:00
(QA / testing) - Add unit testing for key model access checks (#7999)
* fix _model_matches_any_wildcard_pattern_in_list * fix docstring
This commit is contained in:
parent
c2fa213ae2
commit
d9dcfccdf6
2 changed files with 107 additions and 4 deletions
|
@ -874,6 +874,11 @@ async def can_key_call_model(
|
|||
|
||||
verbose_proxy_logger.debug(f"model: {model}; allowed_models: {filtered_models}")
|
||||
|
||||
if _model_matches_any_wildcard_pattern_in_list(
|
||||
model=model, allowed_model_list=filtered_models
|
||||
):
|
||||
return True
|
||||
|
||||
all_model_access: bool = False
|
||||
|
||||
if (
|
||||
|
@ -1076,9 +1081,8 @@ def _team_model_access_check(
|
|||
pass
|
||||
elif model and "*" in model:
|
||||
pass
|
||||
elif any(
|
||||
is_model_allowed_by_pattern(model=model, allowed_model_pattern=team_model)
|
||||
for team_model in team_object.models
|
||||
elif _model_matches_any_wildcard_pattern_in_list(
|
||||
model=model, allowed_model_list=team_object.models
|
||||
):
|
||||
pass
|
||||
else:
|
||||
|
@ -1104,3 +1108,23 @@ def is_model_allowed_by_pattern(model: str, allowed_model_pattern: str) -> bool:
|
|||
return bool(re.match(pattern, model))
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def _model_matches_any_wildcard_pattern_in_list(
|
||||
model: str, allowed_model_list: list
|
||||
) -> bool:
|
||||
"""
|
||||
Returns True if a model matches any wildcard pattern in a list.
|
||||
|
||||
eg.
|
||||
- model=`bedrock/us.amazon.nova-micro-v1:0`, allowed_models=`bedrock/*` returns True
|
||||
- model=`bedrock/us.amazon.nova-micro-v1:0`, allowed_models=`bedrock/us.*` returns True
|
||||
- model=`bedrockzzzz/us.amazon.nova-micro-v1:0`, allowed_models=`bedrock/*` returns False
|
||||
"""
|
||||
return any(
|
||||
"*" in allowed_model_pattern
|
||||
and is_model_allowed_by_pattern(
|
||||
model=model, allowed_model_pattern=allowed_model_pattern
|
||||
)
|
||||
for allowed_model_pattern in allowed_model_list
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue