Fix improper conversion of list[Audio | File | Image] helpers

Fix improper conversion of list[Audio | File | Image] helpers
This commit is contained in:
William Easton 2025-10-03 16:01:49 -05:00 committed by GitHub
commit 5edbe57cb6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -546,13 +546,12 @@ def _convert_to_content(
# If any item is a ContentBlock, convert non-ContentBlock items to TextContent
# without aggregating them
if any(isinstance(item, ContentBlock) for item in result):
if any(isinstance(item, ContentBlock | Image | Audio | File) for item in result):
return [
_convert_to_single_content_block(item, serializer)
if not isinstance(item, ContentBlock)
else item
for item in result
]
# If none of the items are ContentBlocks, aggregate all items into a single TextContent
return [TextContent(type="text", text=_serialize_with_fallback(result, serializer))]

View file

@ -1087,6 +1087,9 @@ class TestConvertResultToContent:
converted = _convert_to_content(result)
assert converted == expected
converted = _convert_to_content([result, result])
assert converted == expected * 2
def test_convert_mixed_content(self):
result = [
"hello",