Open FoliageOwO opened 1 month ago
I solved this problem by adding these lines in mem0/memory/main.py
:
...
+ import re
...
function_calling_prompt = get_update_memory_messages(retrieved_old_memory, new_retrieved_facts)
new_memories_with_actions = self.llm.generate_response(
messages=[{"role": "user", "content": function_calling_prompt}],
response_format={"type": "json_object"},
)
+ search_result = re.search("(```json)((.*\n)+)(```)", new_memories_with_actions)
+ if search_result:
+ new_memories_with_actions = search_result.group(2).strip()
new_memories_with_actions = json.loads(new_memories_with_actions)
EDIT:
The issue will not occur only at the json.loads()
line I mentioned before, but also here:
@FoliageOwO can you please raise a PR for this?
@FoliageOwO can you please raise a PR for this?
@prateekchhikara Hi, I just created a new PR #1860, please review it when you get a second.
@FoliageOwO can you please raise a PR for this?
@prateekchhikara Hi, I just created a new PR #1860, please review it when you get a second.
When will this bug be fixed o(╥﹏╥)o
@hhhhhge 等 PR 被合并并发布到新的 Release 版本后,所有人就都可以用上了。如果你目前要紧急解决这个问题的话,可以手动克隆我的 fork 仓库到 pip 安装的包的目录,也可以根据我的 commit 手动修改本地包源码。目前的 PR 并能代表最终 Release,我的方案可能不是最好的,也许可能会被其他贡献者改进,但是可以暂时用来应急。
For those who can't wait for the PR approval and releasing process: you can clone my fork repository to your pip packages folder, or manually edit local mem0
source codes according to my commit.
🐛 Describe the bug
I was creating a memory, following the official document.
But I did get confused at this error:
which is occurred at the line
After checking what on earth are the
new_memories_with_actions
, I found that the AI did respond a JSON content, but with triple backticks (the code block format), just like this (I'm usingdiff
because the triple backticks will not show at the time):which surely will get
json.loads()
crashed.Is anything wrong?
EDIT: BTW I think it was the model that caused the issue of generating bad content, so I need to declare that I was using
Qwen
(the model by Alibaba Cloud), notgpt-4
orgpt-4o
or something that was mentioned in the official document.