-
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 |
🐛 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: