mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
[Bug Fix] Tags as metadata dicts were raising exceptions (#15625)
* fix get_tags_from_request_body
* Revert "fix get_tags_from_request_body"
This reverts commit 1c044dad99.
* fix get_tags_from_request_body
* test_get_tags_from_request_body_with_dict_tags
This commit is contained in:
parent
59f41a4df8
commit
a1a1b688c8
2 changed files with 39 additions and 3 deletions
|
|
@ -263,8 +263,17 @@ def get_tags_from_request_body(request_body: dict) -> List[str]:
|
|||
"""
|
||||
metadata_variable_name = get_metadata_variable_name_from_kwargs(request_body)
|
||||
metadata = request_body.get(metadata_variable_name, {})
|
||||
tags_in_metadata: List[str] = metadata.get("tags", [])
|
||||
tags_in_request_body: List[str] = request_body.get("tags", [])
|
||||
combined_tags: List[str] = tags_in_metadata + tags_in_request_body
|
||||
tags_in_metadata: Any = metadata.get("tags", [])
|
||||
tags_in_request_body: Any = request_body.get("tags", [])
|
||||
combined_tags: List[str] = []
|
||||
|
||||
######################################
|
||||
# Only combine tags if they are lists
|
||||
######################################
|
||||
if isinstance(tags_in_metadata, list):
|
||||
combined_tags.extend(tags_in_metadata)
|
||||
if isinstance(tags_in_request_body, list):
|
||||
combined_tags.extend(tags_in_request_body)
|
||||
######################################
|
||||
return [tag for tag in combined_tags if isinstance(tag, str)]
|
||||
|
||||
|
|
|
|||
|
|
@ -382,3 +382,30 @@ def test_get_tags_from_request_body_no_tags():
|
|||
result = get_tags_from_request_body(request_body=request_body)
|
||||
|
||||
assert result == []
|
||||
|
||||
|
||||
def test_get_tags_from_request_body_with_dict_tags():
|
||||
"""
|
||||
Test that function handles dict tags gracefully without crashing.
|
||||
When tags is a dict instead of a list, it should be ignored and return empty list.
|
||||
"""
|
||||
request_body = {
|
||||
"model": "aws/anthropic/bedrock-claude-3-5-sonnet-v1",
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "aloha"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"tags": {
|
||||
"litellm_id": "litellm_ratelimit_test",
|
||||
"llm_id": "llmid_ratelimit_test"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = get_tags_from_request_body(request_body=request_body)
|
||||
|
||||
assert result == []
|
||||
assert isinstance(result, list)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue