-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSONDecodeError: AI sometimes produces JSON with a code block format #1854
Comments
I solved this problem by adding these lines in Lines 168 to 173 in f40a2e7
...
+ 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: Lines 142 to 145 in f40a2e7
|
@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 |
🐛 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.The text was updated successfully, but these errors were encountered: