-
Notifications
You must be signed in to change notification settings - Fork 44.4k
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
fix json parser #697
fix json parser #697
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rough, but it looks functional. Also, you should functionally mark this pull request as a draft instead of simply having "draft" as a namesake. The button is in the right panel under reviewers.
I will try to refactor this a little further into the already existing json cleaner method. |
If it's not ready yet you can mark it as a draft PR using GitHub |
After I download your file and replace original
I only wrote four goals. If I use exactly the same goals with the actual |
try git pull on the master branch, the issue comes from chat.py, not my code. |
cfg.debug is one param too much for the chat method. not sure who changed it, as my git blame is broken in vscode |
Removing the branch made it rocksolid now. An array from google seemed to have crashed it now. |
@Artemonim try again. I think I resolved most issues now. |
Is it a correct response?
|
well (input in Russian but I assume the same problem in English) Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for Математический решатель с автогенератором...
Input:пожалуйста, повтори свой запрос
SYSTEM: Human feedback: пожалуйста, повтори свой запрос
Error: Invalid JSON in assistant thoughts
Хорошо, для того чтобы создать рабочую папку и файл, который будем использовать для сохранения математических задач и их решений, используется следующий JSON запрос: ``` { "thoughts": { "text": "Я должен создать папку 'Math' и файл 'workbook.markdown'. Это позволит мне добавлять и хранить математические задачи и их решения. Я собираюсь сохранять формулы в формате ASCII-математика.", "reasoning": "Создание папки и файла позволит мне логически организовать мои файлы и сохранять информацию в одном месте. Это позволит мне быстро находить нужные файлы, а также легко делиться ими с другими.", "plan": "- Создать папку 'Math'. \\n- В этой папке создать файл 'workbook.markdown'.", "criticism": "Я должен был выполнить это раньше.", "speak": "Я создам папку 'Math' и файл 'workbook.markdown' внутри нее." }, "command": { "name": "create_directory", "args": { "directory": "Math" } } } ```
Attempting to fix JSON by finding outermost brackets
Error:
Traceback (most recent call last): File "Auto-GPT/scripts/main.py", line 95, in print_assistant_thoughts assistant_reply_json = fix_and_parse_json(assistant_reply) File "D:\YandexDisk\Work\Auto-ChatGPT\Auto-GPT\scripts\json_parser.py", line 38, in fix_and_parse_json json_str = correct_json(json_str) File "D:\YandexDisk\Work\Auto-ChatGPT\Auto-GPT\scripts\json_utils.py", line 125, in correct_json if balanced_str := balance_braces(json_str): File "D:\YandexDisk\Work\Auto-ChatGPT\Auto-GPT\s
cripts\json_utils.py", line 79, in balance_braces raise e File "D:\YandexDisk\Work\Auto-ChatGPT\Auto-GPT\scripts\json_utils.py", line 76, in balance_braces json.loa
ds(json_string) File "C:\ProgramData\miniconda3\envs\py3.8\lib\json\__init__.py", line 357, in loads return _default_decoder.decode(s) File "C:\ProgramData\minicond
a3\envs\py3.8\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\ProgramData\miniconda3\envs\py3.8\lib\json\decode
r.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char
0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "Auto-GPT/scripts/main.py", line 98, in print_assist
ant_thoughts assistant_reply_json = attempt_to_fix_json_by_finding_outermost_brackets(assistant_reply) File "Auto-GPT/scripts/main.py", line 68, in attempt_to_fix_j
son_by_finding_outermost_brackets json_pattern = re.compile(r"\{(?:[^{}]|(?R))*\}") File "C:\ProgramData\miniconda3\envs\py3.8\lib\re.py", line 252, in compile retu
rn _compile(pattern, flags) File "C:\ProgramData\miniconda3\envs\py3.8\lib\re.py", line 304, in _compile p = sre_compile.compile(pattern, flags) File "C:\ProgramDat
a\miniconda3\envs\py3.8\lib\sre_compile.py", line 764, in compile p = sre_parse.parse(p, flags) File "C:\ProgramData\miniconda3\envs\py3.8\lib\sre_parse.py", line 9
48, in parse p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0) File "C:\ProgramData\miniconda3\envs\py3.8\lib\sre_parse.py", line 443, in _parse_sub itemsa
ppend(_parse(source, state, verbose, nested + 1, File "C:\ProgramData\miniconda3\envs\py3.8\lib\sre_parse.py", line 834, in _parse p = _parse_sub(source, state, sub
_verbose, nested + 1) File "C:\ProgramData\miniconda3\envs\py3.8\lib\sre_parse.py", line 443, in _parse_sub itemsappend(_parse(source, state, verbose, nested + 1, F
ile "C:\ProgramData\miniconda3\envs\py3.8\lib\sre_parse.py", line 823, in _parse raise source.error("unknown extension ?" + char, re.error: unknown extension ?R at position 12 After that the program did not stop and asks for confirmation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with regards to whitespace and unrelated changes
@Artemonim The printed error is intentional. Also don't forget to pull the latest branch of mine for testing. Talking of the devil, I got the same error now, regex is off, one sec. |
That happens not everytime when "Apparently json was fixed.". Hmmm... |
Maybe this attemptive fix can be added into the fix_and_parse_json or something. Something like "Summarize last 5-10 history entries" and feed it into a new gpt instance, as once it starts doing those broken json messages, it will continue to do so. @Torantulino Any ideas? I have to work now, so will be away for half a day. |
I've merge #697 into the present master and that happened after 14 minutes of work
translation:
context: It was trying to log: 11:22:35,324 AutoGPT INFO Error:
: Traceback (most recent call last):
File "Auto-GPT/scripts/main.py", line 104, in print_assistant_thoughts
assistant_reply_json = fix_and_parse_json(assistant_reply)
File "D:\YandexDisk\Work\Auto-ChatGPT\Auto-GPT\scripts\json_parser.py", line 51, in fix_and_parse_json
brace_index = json_str.index("{")
ValueError: substring not found |
@Artemonim That is a different bug. |
If so, then it seems your current fixes are working right |
I just told my bot "Note: GPT-3.5 agents frequently send extraneous text with JSON messages" and I have seen only one invalid json error in the past 30 minutes since. It had been more like 1 every 5 sec. |
@Torantulino |
I just pulled and now getting:
|
#858 fixes it |
Spoke too soon.
|
I added my fixes. |
Is this planned to be merged soon? |
Yes, this PR is one of the few remaining PRs in the Batch 2, we were going to merge it today, but suffered from the delegation process. Now there are 2 guys with write permissions, but they are getting used to the flow. And @Torantulino probably needs some time to finally sleep. Give them some time to adapt. We may still break it before the merge though, but there are like 3 PRs left in that old batch, and you are one of them. |
Okay, seems great :) |
This bug fix is also needed for summary_memory.py Auto-GPT\autogpt\memory_management\summary_memory.py It is also problematic that a JSONDecodeError causes the process to terminate immediately |
Open a PR plz |
…/github_actions/codecov/codecov-action-3 Bump codecov/codecov-action from 1 to 3
…eedback-json-error fix json parser
Background
Using gpt-3.5 the responses contain some nonsense text around the json.
This is a messy fix, don't merge before it's clean.
But you can use these changes rn to get around the issue.
Changes
added another json clean function that finds the first and last bracket and also notifies the user via speech about the issue, if it happened, as this one is important to observe and I do not want it to be a final fix.
Documentation
Test Plan
PR Quality Checklist