mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-06 08:16:43 +00:00
fix(router): guard None model_info and deduplicate team index logic
- Guard against None model_info in sibling deployment check - Extract _update_team_model_index helper to eliminate duplication Made-with: Cursor
This commit is contained in:
parent
f5b7298854
commit
298df75066
2 changed files with 22 additions and 19 deletions
|
|
@ -491,7 +491,8 @@ async def _update_existing_team_model_assignment(
|
|||
d
|
||||
for d in response
|
||||
if d.model_name != db_model.model_name
|
||||
and d.model_info.get("team_public_model_name") == old_public_name
|
||||
and (d.model_info or {}).get("team_public_model_name")
|
||||
== old_public_name
|
||||
]
|
||||
|
||||
if not other_deployments_with_old_name:
|
||||
|
|
|
|||
|
|
@ -7173,6 +7173,24 @@ class Router:
|
|||
else:
|
||||
del self.team_model_to_deployment_indices[key]
|
||||
|
||||
def _update_team_model_index(self, model: dict, idx: int) -> None:
|
||||
"""
|
||||
Helper to update team_model_to_deployment_indices for a single deployment.
|
||||
|
||||
Parameters:
|
||||
- model: dict - the deployment to index
|
||||
- idx: int - the index in model_list
|
||||
"""
|
||||
team_id = model.get("model_info", {}).get("team_id")
|
||||
team_public_model_name = model.get("model_info", {}).get(
|
||||
"team_public_model_name"
|
||||
)
|
||||
if team_id and team_public_model_name:
|
||||
key = (team_id, team_public_model_name)
|
||||
if key not in self.team_model_to_deployment_indices:
|
||||
self.team_model_to_deployment_indices[key] = []
|
||||
self.team_model_to_deployment_indices[key].append(idx)
|
||||
|
||||
def _add_model_to_list_and_index_map(
|
||||
self, model: dict, model_id: Optional[str] = None
|
||||
) -> None:
|
||||
|
|
@ -7202,15 +7220,7 @@ class Router:
|
|||
self.model_name_to_deployment_indices[model_name].append(idx)
|
||||
|
||||
# Update team_model index for O(1) team-scoped lookup
|
||||
team_id = model.get("model_info", {}).get("team_id")
|
||||
team_public_model_name = model.get("model_info", {}).get(
|
||||
"team_public_model_name"
|
||||
)
|
||||
if team_id and team_public_model_name:
|
||||
key = (team_id, team_public_model_name)
|
||||
if key not in self.team_model_to_deployment_indices:
|
||||
self.team_model_to_deployment_indices[key] = []
|
||||
self.team_model_to_deployment_indices[key].append(idx)
|
||||
self._update_team_model_index(model, idx)
|
||||
|
||||
def upsert_deployment(self, deployment: Deployment) -> Optional[Deployment]:
|
||||
"""
|
||||
|
|
@ -8051,15 +8061,7 @@ class Router:
|
|||
self.model_name_to_deployment_indices[model_name] = []
|
||||
self.model_name_to_deployment_indices[model_name].append(idx)
|
||||
|
||||
team_id = model.get("model_info", {}).get("team_id")
|
||||
team_public_model_name = model.get("model_info", {}).get(
|
||||
"team_public_model_name"
|
||||
)
|
||||
if team_id and team_public_model_name:
|
||||
key = (team_id, team_public_model_name)
|
||||
if key not in self.team_model_to_deployment_indices:
|
||||
self.team_model_to_deployment_indices[key] = []
|
||||
self.team_model_to_deployment_indices[key].append(idx)
|
||||
self._update_team_model_index(model, idx)
|
||||
|
||||
def _build_model_id_to_deployment_index_map(self, model_list: list):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue