mirror of
https://github.com/ml-explore/mlx-examples.git
synced 2025-08-22 04:56:49 +08:00
chore: optimize the messagef content processing
This commit is contained in:
parent
74ae24b883
commit
07f3d7d6bb
@ -133,15 +133,15 @@ def process_message_content(messages):
|
|||||||
processed_messages = []
|
processed_messages = []
|
||||||
for message in messages:
|
for message in messages:
|
||||||
message_copy = message.copy()
|
message_copy = message.copy()
|
||||||
if "content" in message_copy:
|
if "content" in message_copy and isinstance(message_copy["content"], list):
|
||||||
flattened_text = ""
|
text_fragments = [
|
||||||
if isinstance(message_copy["content"], list):
|
fragment["text"]
|
||||||
for content_fragment in message_copy["content"]:
|
for fragment in message_copy["content"]
|
||||||
if content_fragment["type"] == "text" and "text" in content_fragment:
|
if fragment.get("type") == "text"
|
||||||
flattened_text += content_fragment["text"]
|
]
|
||||||
else:
|
if len(text_fragments) != len(message_copy["content"]):
|
||||||
raise ValueError("Only 'text' content type is supported.")
|
raise ValueError("Only 'text' content type is supported.")
|
||||||
message_copy["content"] = flattened_text
|
message_copy["content"] = "".join(text_fragments)
|
||||||
processed_messages.append(message_copy)
|
processed_messages.append(message_copy)
|
||||||
return processed_messages
|
return processed_messages
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user