mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
Merge 565592a80a into 6085538b33
This commit is contained in:
commit
ebc979412a
2 changed files with 39 additions and 2 deletions
|
|
@ -52,7 +52,7 @@ class AlertingHangingRequestCheck:
|
|||
|
||||
async def add_request_to_hanging_request_check(
|
||||
self,
|
||||
request_data: dict | None = None,
|
||||
request_data: dict[str, Any] | None = None,
|
||||
):
|
||||
"""
|
||||
Add a request to the hanging request cache. This is the list of request_ids that gets periodicall checked for hanging requests
|
||||
|
|
@ -60,7 +60,14 @@ class AlertingHangingRequestCheck:
|
|||
if request_data is None:
|
||||
return
|
||||
|
||||
request_metadata: Final = get_litellm_metadata_from_kwargs(kwargs=request_data)
|
||||
# The proxy registers the request before the call, so the key metadata is
|
||||
# still at the top level of the request body, not under `litellm_params`.
|
||||
request_metadata: Final = (
|
||||
get_litellm_metadata_from_kwargs(kwargs=request_data)
|
||||
or request_data.get("litellm_metadata")
|
||||
or request_data.get("metadata")
|
||||
or {}
|
||||
)
|
||||
model: Final = request_data.get("model", "")
|
||||
api_base: str | None = None
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,36 @@ class TestAlertingHangingRequestCheck:
|
|||
assert cached_data.request_id == "test_request_123"
|
||||
assert cached_data.model == "gpt-4"
|
||||
assert cached_data.api_base == "https://api.openai.com/v1"
|
||||
assert cached_data.key_alias == "test_key"
|
||||
assert cached_data.team_alias == "test_team"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_request_to_hanging_request_check_reads_litellm_metadata(
|
||||
self, hanging_request_checker
|
||||
):
|
||||
"""
|
||||
Routes that store proxy metadata under `litellm_metadata` (e.g. /v1/messages)
|
||||
must still populate the key and team alias of the alert.
|
||||
"""
|
||||
request_data = {
|
||||
"litellm_call_id": "litellm_metadata_request",
|
||||
"model": "claude-sonnet",
|
||||
"litellm_metadata": {
|
||||
"user_api_key_alias": "test_key",
|
||||
"user_api_key_team_alias": "test_team",
|
||||
},
|
||||
}
|
||||
|
||||
await hanging_request_checker.add_request_to_hanging_request_check(request_data)
|
||||
|
||||
cached_data = (
|
||||
await hanging_request_checker.hanging_request_cache.async_get_cache(
|
||||
key="litellm_metadata_request"
|
||||
)
|
||||
)
|
||||
|
||||
assert cached_data.key_alias == "test_key"
|
||||
assert cached_data.team_alias == "test_team"
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_request_to_hanging_request_check_none_request_data(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue