mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-14 23:21:35 +00:00
fix: format files for ruff and add direct remove_deployment test for code coverage
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
8f5e2d2cb9
commit
7b0959f0c3
3 changed files with 20 additions and 11 deletions
|
|
@ -418,9 +418,8 @@ def get_logging_payload(kwargs, response_obj, start_time, end_time) -> SpendLogs
|
|||
completion_tokens=usage.get("completion_tokens", standard_logging_completion_tokens),
|
||||
request_tags=request_tags,
|
||||
end_user=end_user_id or "",
|
||||
api_base=litellm_params.get("api_base", "") or (
|
||||
standard_logging_payload.get("api_base", "") if standard_logging_payload is not None else ""
|
||||
),
|
||||
api_base=litellm_params.get("api_base", "")
|
||||
or (standard_logging_payload.get("api_base", "") if standard_logging_payload is not None else ""),
|
||||
model_group=_model_group,
|
||||
model_id=_model_id,
|
||||
mcp_namespaced_tool_name=mcp_namespaced_tool_name,
|
||||
|
|
|
|||
|
|
@ -81,10 +81,7 @@ class PatternMatchRouter:
|
|||
model_id: the deployment's model_info.id to remove
|
||||
"""
|
||||
for regex in list(self.patterns.keys()):
|
||||
self.patterns[regex] = [
|
||||
d for d in self.patterns[regex]
|
||||
if d.get("model_info", {}).get("id") != model_id
|
||||
]
|
||||
self.patterns[regex] = [d for d in self.patterns[regex] if d.get("model_info", {}).get("id") != model_id]
|
||||
if not self.patterns[regex]:
|
||||
del self.patterns[regex]
|
||||
|
||||
|
|
|
|||
|
|
@ -842,19 +842,32 @@ def test_delete_deployment_cleans_up_pattern_router():
|
|||
"""Wildcard deployments must be removed from pattern_router when deleted,
|
||||
otherwise the stale deployment (with old API key) keeps being returned
|
||||
for wildcard-matched requests."""
|
||||
from litellm.router_utils.pattern_match_deployments import PatternMatchRouter
|
||||
|
||||
pattern_router = PatternMatchRouter()
|
||||
pattern_router.add_pattern(
|
||||
"anthropic/*",
|
||||
{
|
||||
"model_name": "anthropic/*",
|
||||
"litellm_params": {"model": "anthropic/*"},
|
||||
"model_info": {"id": "deployment-wildcard-123"},
|
||||
},
|
||||
)
|
||||
assert pattern_router.route("anthropic/claude-opus-4-7") is not None
|
||||
pattern_router.remove_deployment(model_id="deployment-wildcard-123")
|
||||
assert pattern_router.route("anthropic/claude-opus-4-7") is None
|
||||
|
||||
router = Router(
|
||||
model_list=[
|
||||
{
|
||||
"model_name": "anthropic/*",
|
||||
"litellm_params": {"model": "anthropic/*", "api_key": "sk-old-key"},
|
||||
"model_info": {"id": "deployment-wildcard-123"},
|
||||
"model_info": {"id": "deployment-wildcard-456"},
|
||||
}
|
||||
]
|
||||
)
|
||||
assert router.pattern_router.route("anthropic/claude-opus-4-7") is not None
|
||||
|
||||
router.delete_deployment(id="deployment-wildcard-123")
|
||||
|
||||
router.delete_deployment(id="deployment-wildcard-456")
|
||||
assert len(router.model_list) == 0
|
||||
assert router.pattern_router.route("anthropic/claude-opus-4-7") is None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue