@@ -472,20 +472,29 @@ def _prepare_message(self, role: str, content: str | list) -> tuple[dict, list]:
472
472
else :
473
473
raise ValueError (
474
474
f"Invalid content type: { type (content )} . "
475
- "The content must be a string or a list containing text and assets "
476
- "or a list of dict items with explicit types."
475
+ + "The content must be a string or a list containing text and assets "
476
+ + "or a list of dict items with explicit types."
477
477
)
478
478
479
479
def _extract_assets_from_content (self , content : list ) -> list :
480
480
"""Process a list of dict items."""
481
481
assets = []
482
+
482
483
for item in content :
484
+ if len (item ) > 2 :
485
+ raise ValueError (
486
+ f"Found item with multiple keys: { item } . "
487
+ + "Each item in the content list must be a dictionary with a 'type' key and a single asset key. "
488
+ + "To include multiple assets, use separate dictionary items. "
489
+ + "For example: [{{'type': 'image', 'image': image1}}, {{'type': 'image', 'image': image2}}]. "
490
+ )
491
+
483
492
if "type" not in item :
484
493
raise ValueError (
485
494
"Each item in the content list must be a dictionary with a 'type' key. "
486
- "Valid types are 'text', 'image', 'video', or 'audio'. "
487
- f "For instance {{'type': 'text', 'text': 'your message'}}. "
488
- f"Found item without 'type' key: { item } "
495
+ + "Valid types are 'text', 'image', 'video', or 'audio'. "
496
+ + "For instance {{'type': 'text', 'text': 'your message'}}. "
497
+ + f"Found item without 'type' key: { item } "
489
498
)
490
499
if item ["type" ] == "text" :
491
500
continue
@@ -494,7 +503,7 @@ def _extract_assets_from_content(self, content: list) -> list:
494
503
if asset_key not in item :
495
504
raise ValueError (
496
505
f"Item with type '{ asset_key } ' must contain a '{ asset_key } ' key. "
497
- f"Found item: { item } "
506
+ + f"Found item: { item } "
498
507
)
499
508
if isinstance (item [asset_key ], (Image , Video , Audio )):
500
509
assets .append (item [asset_key ])
0 commit comments