Fix exclusion of content helpers if they are in a list

This commit is contained in:
William Easton 2025-10-03 15:02:26 -05:00
commit 664b67d26f
No known key found for this signature in database
2 changed files with 5 additions and 3 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, (Image, Audio, File)) 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 isinstance(item, (Image, Audio, File))
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",