mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(router): return read-only deployment views from deployment id grant filters
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
b6bc274510
commit
fc193fd3d8
3 changed files with 14 additions and 12 deletions
|
|
@ -13480,7 +13480,9 @@ def _add_team_models_to_all_models(
|
|||
for model_id in _granted_deployment_ids(
|
||||
models=team_object.models, llm_router=llm_router, team_id=team_object.team_id
|
||||
):
|
||||
team_models.setdefault(model_id, set()).add(team_object.team_id)
|
||||
team_models.setdefault(model_id, set()).add( # mutable-ok: fills the dict[str, set[str]] accumulator
|
||||
team_object.team_id
|
||||
)
|
||||
return team_models
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -12702,7 +12702,7 @@ class Router:
|
|||
model: str,
|
||||
healthy_deployments: Sequence[Mapping[str, object]],
|
||||
request_kwargs: Mapping[str, object] | None,
|
||||
) -> list[Mapping[str, object]]:
|
||||
) -> Sequence[Mapping[str, object]]:
|
||||
"""
|
||||
Restrict candidate deployments to the deployment IDs granted on the key or team.
|
||||
|
||||
|
|
@ -12711,7 +12711,7 @@ class Router:
|
|||
whose granted deployments are all unavailable yields no candidates rather than widening.
|
||||
"""
|
||||
if not healthy_deployments or request_kwargs is None:
|
||||
return list(healthy_deployments)
|
||||
return healthy_deployments
|
||||
return self._restrict_deployments_to_caller_grants(
|
||||
model=model,
|
||||
deployments=healthy_deployments,
|
||||
|
|
@ -12723,12 +12723,12 @@ class Router:
|
|||
model: str,
|
||||
deployments: Sequence[Mapping[str, object]],
|
||||
user_api_key_auth: object,
|
||||
) -> list[Mapping[str, object]]:
|
||||
) -> Sequence[Mapping[str, object]]:
|
||||
if not deployments or not isinstance(user_api_key_auth, CallerModelGrants):
|
||||
return list(deployments)
|
||||
return deployments
|
||||
|
||||
model_group_ids: Final = frozenset(self.get_model_ids(model_name=model))
|
||||
key_grants: Final = self._grant_strings(user_api_key_auth.models) - {"all-team-models"}
|
||||
key_grants: Final = self._grant_strings(user_api_key_auth.models) - frozenset({"all-team-models"})
|
||||
team_grants: Final = self._grant_strings(user_api_key_auth.team_models)
|
||||
key_scoped: Final = self._restrict_to_granted_deployment_ids(
|
||||
model=model, deployments=deployments, grants=key_grants, model_group_ids=model_group_ids
|
||||
|
|
@ -12760,13 +12760,13 @@ class Router:
|
|||
deployments: Sequence[Mapping[str, object]],
|
||||
grants: frozenset[str],
|
||||
model_group_ids: frozenset[str],
|
||||
) -> list[Mapping[str, object]]:
|
||||
) -> Sequence[Mapping[str, object]]:
|
||||
if model in grants or "*" in grants or "all-proxy-models" in grants:
|
||||
return list(deployments)
|
||||
return deployments
|
||||
granted_ids: Final = grants & model_group_ids
|
||||
if not granted_ids:
|
||||
return list(deployments)
|
||||
return [deployment for deployment in deployments if cls._deployment_ids((deployment,)) & granted_ids]
|
||||
return deployments
|
||||
return tuple(deployment for deployment in deployments if cls._deployment_ids((deployment,)) & granted_ids)
|
||||
|
||||
async def async_get_healthy_deployments(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -16938,7 +16938,7 @@ def test_deployment_id_grant_does_not_widen_when_granted_deployment_is_unavailab
|
|||
healthy_deployments=healthy_openai_only,
|
||||
request_kwargs={"metadata": {"user_api_key_auth": scoped_key}},
|
||||
)
|
||||
== []
|
||||
== ()
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -17008,7 +17008,7 @@ def test_restrict_deployments_to_caller_grants_applies_key_then_team_scope():
|
|||
router._restrict_deployments_to_caller_grants(
|
||||
model="gpt-4", deployments=(), user_api_key_auth=UserAPIKeyAuth(api_key="k", models=["azure-gpt-4-id"])
|
||||
)
|
||||
== []
|
||||
== ()
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue