mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-20 12:34:17 +02:00
Fix improper conversion of list[Audio | File | Image] helpers
Fix improper conversion of list[Audio | File | Image] helpers
This commit is contained in:
commit
5edbe57cb6
2 changed files with 4 additions and 2 deletions
|
|
@ -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))]
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue