mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
fix(auto_router): skip empty text blocks when joining Anthropic content
Filter out dict blocks with an empty or missing "text" value so that trailing spaces are not introduced in the joined message content. Updates the corresponding test assertion to match.
This commit is contained in:
parent
3e20cc6c52
commit
f3d2887add
2 changed files with 2 additions and 2 deletions
|
|
@ -123,7 +123,7 @@ class AutoRouter(CustomLogger):
|
|||
raw_content = user_message.get("content", "")
|
||||
# Handle Anthropic-style content blocks: [{"type": "text", "text": "..."}]
|
||||
if isinstance(raw_content, list):
|
||||
message_content = " ".join(block.get("text", "") for block in raw_content if isinstance(block, dict))
|
||||
message_content = " ".join(block.get("text", "") for block in raw_content if isinstance(block, dict) and block.get("text", ""))
|
||||
else:
|
||||
message_content = str(raw_content)
|
||||
route_choice: Optional[Union[RouteChoice, List[RouteChoice]]] = self.routelayer(text=message_content)
|
||||
|
|
|
|||
|
|
@ -232,6 +232,6 @@ class TestAutoRouter:
|
|||
)
|
||||
|
||||
# Assert: only dict blocks contribute; "text" defaults to "" when missing
|
||||
mock_routelayer.assert_called_once_with(text="What is the weather today? In Paris. ")
|
||||
mock_routelayer.assert_called_once_with(text="What is the weather today? In Paris.")
|
||||
assert result is not None
|
||||
assert result.messages == messages
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue