mem0
mem0 copied to clipboard
parse_vision_messages fails to work correctly when encountering an array content.
🐛 Describe the bug
在非vision模式下,使用AsyncMemory await memory.add(messages) messages内容如下
[ {
"role" : "user",
"content" : "你好"
}, {
"role" : "user",
"content" : [ {
"type" : "text",
"text" : "For context:"
}, {
"type" : "text",
"text" : "xxxxxxx"
} ]
} ]
在openai官网,他可能是个 text array
https://platform.openai.com/docs/api-reference/chat/create
Hey @growmuye sorry for the trouble caused, can you share when and how exactly this error occurs?
Cause:
- The
parse_vision_messagesfunction doesn't handle array-type message content (e.g.[{'type': 'text', 'text': ...}]as allowed by OpenAI API). Instead, it expects a simple string, so parsing fails and downstream output files likememories/{idx}.txtare never created.
Solution:
- Update the parsing logic to flatten/join array-type content into a single string:
if isinstance(content, list):
content_str = ''.join([ch['text'] for ch in content if 'text' in ch])
else:
content_str = content
- After this change, the pipeline should process messages correctly and create the expected files.
Let me know if you want a PR or code sample for the fix!