mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(router): remove stale wildcard entries from pattern_router on upsert/delete
This commit is contained in:
parent
b5cfc2ca00
commit
eef10bf006
2 changed files with 47 additions and 0 deletions
|
|
@ -8380,6 +8380,8 @@ class Router:
|
|||
public_model_name for _, public_model_name in self.team_model_to_deployment_indices
|
||||
)
|
||||
|
||||
self.pattern_router.remove_deployment(model_id)
|
||||
|
||||
for team_id in list(self.team_pattern_routers.keys()):
|
||||
team_pattern_router = self.team_pattern_routers[team_id]
|
||||
team_pattern_router.remove_deployment(model_id)
|
||||
|
|
|
|||
|
|
@ -1707,6 +1707,51 @@ def test_get_model_access_groups_cache_invalidation_upsert_deployment():
|
|||
assert "updated-group" in result2
|
||||
|
||||
|
||||
def test_upsert_deployment_replaces_wildcard_pattern_router_entry():
|
||||
from litellm.types.router import Deployment, LiteLLM_Params
|
||||
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "anthropic/*",
|
||||
"litellm_params": {"model": "anthropic/*", "api_key": "old-key"},
|
||||
"model_info": {"id": "wildcard-deployment-id"},
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
upserted = router.upsert_deployment(
|
||||
Deployment(
|
||||
model_name="anthropic/*",
|
||||
litellm_params=LiteLLM_Params(model="anthropic/*", api_key="new-key"),
|
||||
model_info={"id": "wildcard-deployment-id"},
|
||||
)
|
||||
)
|
||||
|
||||
assert upserted is not None
|
||||
pattern_deployments = [
|
||||
deployment for deployments in router.pattern_router.patterns.values() for deployment in deployments
|
||||
]
|
||||
assert len(pattern_deployments) == 1
|
||||
assert pattern_deployments[0]["litellm_params"]["api_key"] == "new-key"
|
||||
|
||||
|
||||
def test_delete_deployment_removes_wildcard_pattern_router_entry():
|
||||
router = litellm.Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "anthropic/*",
|
||||
"litellm_params": {"model": "anthropic/*", "api_key": "old-key"},
|
||||
"model_info": {"id": "wildcard-deployment-id"},
|
||||
},
|
||||
]
|
||||
)
|
||||
|
||||
router.delete_deployment(id="wildcard-deployment-id")
|
||||
|
||||
assert router.pattern_router.patterns == {}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_acompletion_streaming_iterator():
|
||||
"""Test _acompletion_streaming_iterator for normal streaming and fallback behavior."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue