Significant-Gravitas / AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
https://agpt.co
MIT License
166.3k stars 44.01k forks source link

Invalid JSON #21

Closed jaumebalust closed 1 year ago

jaumebalust commented 1 year ago

It doesn't work?

image
jaumebalust commented 1 year ago

is it a gpt-4 only modell?

Torantulino commented 1 year ago

Interesting... Would you mind providing me with some more information?

The current version does use GPT4, but if you didn't have access I'd expect you to get a different error than that, unless you modified the code?

If not, how many times have you seen this error, was it just a freak event or does it happen every time?

sck-at-ucy commented 1 year ago

I am getting the exact same error every time. Does not work.

jaumebalust commented 1 year ago

I installed it today. The requirements.txt had problems and wouldn’t install all the dependencies, there is a conflict with docker and request. It also requested a “six” module, but maybe because I played with it.

After getting it installed, I changed the model to gpt3.5. And kept getting the error message. The only file I changed are the requirements and the references to model gpt-4.

On Sun, 2 Apr 2023 at 14:03, sck-at-ucy @.***> wrote:

I am getting the exact same error every time. Does not work.

— Reply to this email directly, view it on GitHub https://github.com/Torantulino/Auto-GPT/issues/21#issuecomment-1493313140, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPP4HT47JC6YOZCYEZYMMDW7FTIDANCNFSM6AAAAAAWQGNCSU . You are receiving this because you authored the thread.Message ID: @.***>

-- Jaume Balust

Torantulino commented 1 year ago

@jaumebalust You may be experiencing this error because you wrote "For Example: " in your AI Role input.

This is directly injected into the prompt so may cause the AI to act up and not respond with valid JSON.

jaumebalust commented 1 year ago

Ok. I will try to “harden” the prompt so that the model remembers to reply with a JSON

On Sun, 2 Apr 2023 at 14:57, Toran Bruce Richards @.***> wrote:

@jaumebalust https://github.com/jaumebalust You may be experiencing this error because you wrote "For Example: " in your AI Role input.

This is directly injected into the prompt so may cause the AI to act up and not respond with valid JSON.

— Reply to this email directly, view it on GitHub https://github.com/Torantulino/Auto-GPT/issues/21#issuecomment-1493325163, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPP4HWCNIPORCOV63HOITTW7FZVBANCNFSM6AAAAAAWQGNCSU . You are receiving this because you were mentioned.Message ID: @.***>

-- Jaume Balust

Torantulino commented 1 year ago

I changed the model to gpt3.5. And kept getting the error message. The only file I changed are the requirements and the references to model gpt-4.

Oh! This is definitely the cause. I haven't implemented GPT3.5 support yet, Auto-GPT currently only works with gpt4. However, numerous people right here are working on support for GPT3.5 and even other models, hang tight!

https://github.com/Torantulino/Auto-GPT/issues/12#issuecomment-1492761196

chernobog24 commented 1 year ago

I fixed this issue. Just change the starting prompt to "Begin. note only respond in JSON. Come up with your own campaign that follows your goals." instead of "NEXT COMMAND" or something to that effect. And harden the prompt a bit should get the results you need.

adustyugov commented 1 year ago

some problems with escaping in string values. looks like due to prompts(initial or generated ones). we should add checks and escaping for strings

heikog commented 1 year ago

I fixed this issue. Just change the starting prompt to "Begin. note only respond in JSON. Come up with your own campaign that follows your goals." instead of "NEXT COMMAND" or something to that effect. And harden the prompt a bit should get the results you need.

can you elaborate how what you did exactly?

DataBassGit commented 1 year ago

The load_prompt function reads the prompt.txt file from the data subdirectory. If the script is not able to access the file, the most likely reason is that the working directory of the script execution is not set correctly.

To resolve this issue, you can modify the load_prompt function to use an absolute path instead of a relative path. You can achieve this by constructing the absolute path using the os module:

import os

def load_prompt():
    try:
        # Get the current script's directory
        script_dir = os.path.dirname(os.path.realpath(__file__))

        # Construct the absolute path to the prompt.txt file
        prompt_file_path = os.path.join(script_dir, "data", "prompt.txt")

        # Load the prompt from data/prompt.txt
        with open(prompt_file_path, "r") as prompt_file:
            prompt = prompt_file.read()

        return prompt
    except FileNotFoundError:
        print("Error: Prompt file not found", flush=True)
        return ""

This modification should fix the issue with accessing the prompt.txt file. The os.path.dirname(os.path.realpath(file)) line retrieves the directory of the data.py script, and the os.path.join(script_dir, "data", "prompt.txt") line constructs the absolute path to the prompt.txt file.

DataBassGit commented 1 year ago

It’s the data.py module.


which file is that in? —

Torantulino commented 1 year ago

This JSON parsing is being fixed in #45

avelican commented 1 year ago

I also got an Error: Invalid JSON not sure if this is related: NEXT ACTION: COMMAND = Error: ARGUMENTS = Missing 'command' object in JSON

Welcome to Auto-GPT!  Enter the name of your AI and its role below. Entering nothing will load defaults.
Name your AI:  For example, 'Entrepreneur-GPT'
AI Name:
Entrepreneur-GPT here! I am at your service.
Describe your AI's role:  For example, 'an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.'
Entrepreneur-GPT is: Smart
Enter up to 5 goals for your AI:  For example: Increase net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'
Enter nothing to load defaults, enter nothing when finished.
Goal 1: Help me learn and master AI as quickly and enjoyably as possible. I am very curious, prefer to understand things from the bottom up, and I prefer project based learning.
Goal 2:
ENTREPRENEUR-GPT THOUGHTS: I'll start by searching the internet to see if there are any resources that can assist in my learning process.
REASONING: Since my goal is to learn AI as quickly and enjoyably as possible, I want to see if there are any resources available that cater to this way of learning. A quick search on Google should yield plenty of results to help me get started.
PLAN:
-  Conduct a Google search for resources that cater to project based learning.
-  Bookmark any promising sites/resources for future use
CRITICISM: I need to ensure that I am not blindly following any resource or advice without analyzing them critically. I should allocate enough time to each resource to see its quality and applicability to my goals.
NEXT ACTION:  COMMAND = google ARGUMENTS = {'input': 'how to learn AI from scratch with project based learning'}
Enter 'y' to authorise command or 'n' to exit program, or enter feedback for Entrepreneur-GPT...
Input:y

-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=
SYSTEM:  Command google returned: [ "https://www.springboard.com/blog/data-science/how-to-learn-ai/", "https://spencerauthor.com/pblandai/", "https://www.projectpro.io/article/artificial-intelligence-project-ideas/461", "https://elearningindustry.com/artificial-intelligence-and-the-rise-of-project-based-learning", "https://www.jetlearn.com/blog/ai-course-for-kids", "https://www.simplilearn.com/machine-learning-projects-for-beginners-article", "https://www.designsociety.org/publication/43483/THE+ONLINE+PBL+%28PROJECT-BASED+LEARNING%29+EDUCATION+SYSTEM+USING+AI+%28ARTIFICIAL+INTELLIGENCE%29", "https://github.com/practical-tutorials/project-based-learning", "http://steamcurriculum.weebly.com/scratch-based-machine-learning.html", "https://ietresearch.onlinelibrary.wiley.com/doi/full/10.1049/csy2.12050" ]
ENTREPRENEUR-GPT THOUGHTS: I'll start by exploring this Springboard blog post to see if it provides useful information that will help me start learning AI.
REASONING: The blog post seems promising for my needs, since it is an introductory guide that provides information and project examples for learning AI with Python. It also mentions 'Level-Up' project-based courses for Machine Learning and Artificial Intelligence, which sounds interesting to me.
PLAN:
-  Explore this Springboard blog post to see if it provides useful information that will help me start learning AI.
-  Note any projects or resources that will be particularly useful for my goal.
CRITICISM: While this seems like a promising resource, I shouldn't just follow this guide blindly. I should analyze its effectiveness critically and compare it to other resources before committing to its material. Moreover, I should stick to my goal of learning AI via a project-based approach and not drift away from it.
NEXT ACTION:  COMMAND = browse_website ARGUMENTS = {'url': 'https://www.springboard.com/blog/data-science/how-to-learn-ai/'}
Enter 'y' to authorise command or 'n' to exit program, or enter feedback for Entrepreneur-GPT...
Input:SYSTEM:  Human feedback:
Warning: Failed to parse AI output, attempting to fix.
 If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly.
Failed to fix ai output, telling the AI.
Error: Invalid JSON
 How can I assist you further?
ENTREPRENEUR-GPT THOUGHTS:
REASONING:
CRITICISM:
Warning: Failed to parse AI output, attempting to fix.
 If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly.
Failed to fix ai output, telling the AI.
NEXT ACTION:  COMMAND = Error: ARGUMENTS = Missing 'command' object in JSON
Enter 'y' to authorise command or 'n' to exit program, or enter feedback for Entrepreneur-GPT...
Input:n
Exiting...
avelican commented 1 year ago

Got an apparently unrelated error this time: NEXT ACTION: COMMAND = Error: ARGUMENTS = string indices must be integers, not 'str'

  python scripts/main.py
Welcome back!  Would you like me to return to being Entrepreneur-GPT?
Continue with the last settings?
Name:  Entrepreneur-GPT
Role:  Smart
Goals: ['Help me learn and master AI as quickly and enjoyably as possible. I am very curious, prefer to understand things from the bottom up,oject based learning.']
Continue (y/n): n
Welcome to Auto-GPT!  Enter the name of your AI and its role below. Entering nothing will load defaults.
Name your AI:  For example, 'Entrepreneur-GPT'
AI Name: Internet-Research-Assistant-GPT
Internet-Research-Assistant-GPT here! I am at your service.
Describe your AI's role:  For example, 'an AI designed to autonomously develop and run businesses with the sole goal of increasing your net w
Internet-Research-Assistant-GPT is: an AI designed to autonomously do internet research to give correct and detailed answers to questions.
Enter up to 5 goals for your AI:  For example: Increase net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'
Enter nothing to load defaults, enter nothing when finished.
Goal 1: Find out the similarities and differences between Auto-GPT and LangChain.
Goal 2: Explain the similarities and differences between Auto-GPT and LangChain based on what you learned.
Goal 3:
Warning: Failed to parse AI output, attempting to fix.
 If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly.
Failed to fix ai output, telling the AI.
Error: Invalid JSON
 Before I can determine a command to use, I need to know what you want me to do. What is your question or task?
INTERNET-RESEARCH-ASSISTANT-GPT THOUGHTS:
REASONING:
CRITICISM:
Warning: Failed to parse AI output, attempting to fix.
 If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly.
Failed to fix ai output, telling the AI.
NEXT ACTION:  COMMAND = Error: ARGUMENTS = string indices must be integers, not 'str'
Enter 'y' to authorise command or 'n' to exit program, or enter feedback for Internet-Research-Assistant-GPT...
Input:
2tYfX8sgnrx commented 1 year ago

I'm experiencing the JSON error as well. Though it doesn't seem to conflict with continuing to interpret properly, and still works fine as expected. Trying to improve how I communicate to avoid the error.

Louvivien commented 1 year ago

I have this problem as well. The first answer is ok and then I have the JSON problem everytime.

TheSeanLavery commented 1 year ago

@Louvivien for the AI's main prompt write

Only respond in JSON. rest_of_your_prompt_here

Louvivien commented 1 year ago

No when I add this at the beginning of my input, it does not solve the problem

Input:Only respond in JSON. I will give you more inputs related to my business problems, you will need to save it. Do not start working until I have confirmed that I gave you all the inputs. SYSTEM: Human feedback: Only respond in JSON. I will give you more inputs related to my business problems, you will need to save it. Do not start working until I have confirmed that I gave you all the inputs. Warning: Failed to parse AI output, attempting to fix. If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly. Failed to fix ai output, telling the AI. Error: Invalid JSON Input: Understood. Please provide me with the inputs related to your business problem when you are ready. Error: Expecting value: line 1 column 1 (char 0) ASSISTANT-GPT THOUGHTS: REASONING: CRITICISM: Warning: Failed to parse AI output, attempting to fix. If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly. Failed to fix ai output, telling the AI. NEXT ACTION: COMMAND = Error: ARGUMENTS = Missing 'command' object in JSON Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for Assistant-GPT...

Input:Can you confirm you will always reply in JSON format? SYSTEM: Human feedback: Can you confirm you will always reply in JSON format? Warning: Failed to parse AI output, attempting to fix. If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly. Failed to fix ai output, telling the AI. Error: Invalid JSON Input: Yes, I will always respond in JSON format to ensure that my responses can be easily parsed and processed by machines. Error: Expecting value: line 1 column 1 (char 0) ASSISTANT-GPT THOUGHTS: REASONING: CRITICISM: Warning: Failed to parse AI output, attempting to fix. If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly. Failed to fix ai output, telling the AI.

I think it is related to this: https://github.com/openai/openai-python/issues/332

I get this error only with some AI. If I change the role and goals, I do not get the error. But for some AI and role it does not work.

avelican commented 1 year ago

Perhaps "only respond in JSON" could be added to the system message?

YaswanthDasamandam commented 1 year ago

It doesn't work?

image

I am also getting the same error

guypayeur commented 1 year ago

An other instance of this error: SYSTEM: Command write_to_file returned: File written to successfully. Warning: Failed to parse AI output, attempting to fix. If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly. Failed to fix ai output, telling the AI. Error: Invalid JSON { "thoughts": { "text": "Now that I have recorded information about the customs and traditions surrounding WorldPride, I need to develop recipe ideas for the event. ", "reasoning": "By coming up with new and innovative recipe ideas to incorporate into WorldPride celebrations, I can provide a unique food experience to those participating in the event. ", "plan": "- Use the \'read_file\' command to access the file about WorldPride customs and traditions. \n- Analyze the customs and traditions of the festival to come up with new recipe ideas that will align with them. \n- Record the recipe ideas and instructions in a new file using the \'write_to_file\' command. \n- Check the file to ensure that all the recipe ideas and instructions have been recorded accurately. \n- Exit the program. ", "criticism": "I need to make sure that the recipe ideas I come up with are unique, innovative, and properly aligned with the customs and traditions of WorldPride festival. Additionally, it is essential to ensure that the file is saved with the proper location and format.", "speak": "Now I will develop recipe ideas that correspond with the customs and traditions of WorldPride using the information collected earlier. After that, I will save the recipes in a file using the \'write_to_file\' command." }, "command": { "name": "read_file", "args": { "file": "worldpride_customs.txt" } } } CHEF-GPT THOUGHTS: REASONING: CRITICISM: Warning: Failed to parse AI output, attempting to fix. If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly. Failed to fix ai output, telling the AI. NEXT ACTION: COMMAND = Error: ARGUMENTS = string indices must be integers Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for chef-gpt... Input:y

TheRealVidex commented 1 year ago

Got the same error

Interoceptional commented 1 year ago

Getting the same error....

image

danielwe123 commented 1 year ago

Got the same error

psvensson commented 1 year ago

There might be several different things happening here. When I get 'Invalid JSON' it is always because of a prior problem, so that the returned value from ChatGPT-4 looks like this;

My apologies, here is the correct version: { "thoughts": { "text": "....

And that is actually correct. JSON should not start with the string "My apologies, here is the correct version: ".

So this should be an easy fix, but I have just started peeking at this so don't know if this is configurable by me or must be fixed deeper inside something.

michaelfrey commented 1 year ago

same here using the --gpt3only option.

as soon as autogpt wants to get results from a webpage or google it will run into an json error

` ai_goals: check the market for handmade candles shut down when finished ai_name: test ai_role: market research

`

Ligul commented 1 year ago

Unfortunately gpt does not always stick to the right format when replying, sometimes adding something at the beginning, sometimes replying in plain text, and sometimes json is just broken. To try to restore the format in some cases I added this code after line 324 in main.py locally:

try:
    json.loads(assistant_reply)
except ValueError as e:
    if assistant_reply.count('{') == assistant_reply.count('}') == 0:
        # remove " and '
        assistant_reply = assistant_reply.replace('"', '').replace("'", '')
        assistant_reply = '{' \
                              '"thoughts": {' \
                                  '"text": "' + assistant_reply + '",' \
                                  '"reasoning": "",' \
                                  '"plan": "",' \
                                  '"criticism": "",' \
                                  '"speak": ""' \
                              '},' \
                              '"command": {' \
                                  '"name": "do_nothing", "args": {}' \
                              '}' \
                          '}'
    elif assistant_reply.count('{') == assistant_reply.count('}'):
        # remove everything before the first { and after the last }
        assistant_reply = assistant_reply[assistant_reply.find('{'):assistant_reply.rfind('}') + 1]
    else:
        while assistant_reply.count('{') != assistant_reply.count('}'):
            if assistant_reply.count('{') > assistant_reply.count('}'):
                # add a } to the end
                assistant_reply = assistant_reply + '}'
            else:
                # add a { to the beginning
                assistant_reply = '{' + assistant_reply

Maybe it will help someone

michaelfrey commented 1 year ago

Unfortunately gpt does not always stick to the right format when replying, sometimes adding something at the beginning, sometimes replying in plain text, and sometimes json is just broken. To try to restore the format in some cases I added this code after line 309 in main.py locally:

are you sure with line 309? if I add your code after line 310 i'll get this error message

Traceback (most recent call last): File "C:\GTP-Helpers\Auto-GPT\scripts\main.py", line 314, in json.loads(assistant_reply) ^^^^^^^^^^^^^^^ NameError: name 'assistant_reply' is not defined

Ligul commented 1 year ago

are you sure with line 309?

Sorry for the confusion, I checked the code in the repository and it's line 324. Maybe I changed something in the code before and forgot, or maybe this code was affected by a commit that was an hour ago. For anyone who is going to try this - paste my code here:

# Interaction Loop
while True:
    # Send message to AI, get response
    with Spinner("Thinking... "):
        assistant_reply = chat.chat_with_ai(
            prompt,
            user_input,
            full_message_history,
            memory,
            cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument

    # PASTE CODE HERE

    # Print Assistant thoughts
    print_assistant_thoughts(assistant_reply)

Also, here's a link to that line in the last commit at the time of this comment

michaelfrey commented 1 year ago

Sorry to bother you :-)

if I insert the code i get an error message immediately

sorry, i am a total noob regarding python :-)

S C:\GTP-Helpers\Auto-GPT> python scripts/main.py --gpt3only --continuous File "C:\GTP-Helpers\Auto-GPT\scripts\main.py", line 405 break ^^^^^ SyntaxError: 'break' outside loop

the code looks like this

` cfg.fast_token_limit) # TODO: This hardcodes the model to use GPT3.5. Make this an argument

try: json.loads(assistant_reply) except ValueError as e: if assistant_reply.count('{') == assistant_reply.count('}') == 0:

remove " and '

    assistant_reply = assistant_reply.replace('"', '').replace("'", '')
    assistant_reply = '{' \
                          '"thoughts": {' \
                              '"text": "' + assistant_reply + '",' \
                              '"reasoning": "",' \
                              '"plan": "",' \
                              '"criticism": "",' \
                              '"speak": ""' \
                          '},' \
                          '"command": {' \
                              '"name": "do_nothing", "args": {}' \
                          '}' \
                      '}'
elif assistant_reply.count('{') == assistant_reply.count('}'):
    # remove everything before the first { and after the last }
    assistant_reply = assistant_reply[assistant_reply.find('{'):assistant_reply.rfind('}') + 1]
else:
    while assistant_reply.count('{') != assistant_reply.count('}'):
        if assistant_reply.count('{') > assistant_reply.count('}'):
            # add a } to the end
            assistant_reply = assistant_reply + '}'
        else:
            # add a { to the beginning
            assistant_reply = '{' + assistant_reply

# Print Assistant thoughts`
Ligul commented 1 year ago

SyntaxError: 'break' outside loop

I think you put the code in without an indent. Because of this the interpreter thinks that this code is not in the loop body, but after it, and all further code of the loop is also no longer in the loop and with an extra indent. Select the whole pasted piece and press tab (each line should move 4 spaces to the right)

THIS IS RIGHT:

# All code in the loop
while True:
    # Some code before
    # PASTE CODE HERE
    # Some code after

THAT'S NOT RIGHT:

while True:
    # Some code before - This is the only line in the loop
# PASTE CODE HERE - This line is no longer in the loop, but after the loop
    # Some code after - This line is also not in the loop and the indent is wrong before it
JustinGuruTech commented 1 year ago

Unfortunately gpt does not always stick to the right format when replying, sometimes adding something at the beginning, sometimes replying in plain text, and sometimes json is just broken. To try to restore the format in some cases I added this code after line 324 in main.py locally:

try:
    json.loads(assistant_reply)
except ValueError as e:
    if assistant_reply.count('{') == assistant_reply.count('}') == 0:
        # remove " and '
        assistant_reply = assistant_reply.replace('"', '').replace("'", '')
        assistant_reply = '{' \
                              '"thoughts": {' \
                                  '"text": "' + assistant_reply + '",' \
                                  '"reasoning": "",' \
                                  '"plan": "",' \
                                  '"criticism": "",' \
                                  '"speak": ""' \
                              '},' \
                              '"command": {' \
                                  '"name": "do_nothing", "args": {}' \
                              '}' \
                          '}'
    elif assistant_reply.count('{') == assistant_reply.count('}'):
        # remove everything before the first { and after the last }
        assistant_reply = assistant_reply[assistant_reply.find('{'):assistant_reply.rfind('}') + 1]
    else:
        while assistant_reply.count('{') != assistant_reply.count('}'):
            if assistant_reply.count('{') > assistant_reply.count('}'):
                # add a } to the end
                assistant_reply = assistant_reply + '}'
            else:
                # add a { to the beginning
                assistant_reply = '{' + assistant_reply

Maybe it will help someone

This works great for me. From constant json errors to now continuous valuable output. You're a saint 🙏

michaelfrey commented 1 year ago

Hi Justin,

thanks a lot for your overwhelming support.

I pulled the latest source code updates a few hours ago and it seems to work. There have not been any json errors anymore in the past hours of messing around with autogpt

GoMightyAlgorythmGo commented 1 year ago

Invalid JSON are as old as the planet. For me they are a constant in AutoGPT dont bother as long as he can continue where he left off once he crashes or i exit him and continue later.

skagerberg commented 1 year ago

I'm getting loads of Invalid JSON errors in my project, which involves trying to read a local PDF file and extract particular text from it. Whenever it gets the error, it displays the problematic JSON in raw form, and then fails to carry out the task it describes. However, it seems unaware that it didn't carry out the task, and proceeds as if it worked. In my case, I got most of the errors when it was trying to correct a .py code file it generated.

codevbus commented 1 year ago

Still getting this error.

DanyPell commented 1 year ago
Attempting to fix JSON by finding outermost brackets 
Error: Invalid JSON, setting it to empty JSON now.
NEXT ACTION:  COMMAND = Error: ARGUMENTS = 'dict' object has no attribute 'replace'
Momomocheng commented 1 year ago

Unfortunately gpt does not always stick to the right format when replying, sometimes adding something at the beginning, sometimes replying in plain text, and sometimes json is just broken. To try to restore the format in some cases I added this code after line 324 in main.py locally:

try:
    json.loads(assistant_reply)
except ValueError as e:
    if assistant_reply.count('{') == assistant_reply.count('}') == 0:
        # remove " and '
        assistant_reply = assistant_reply.replace('"', '').replace("'", '')
        assistant_reply = '{' \
                              '"thoughts": {' \
                                  '"text": "' + assistant_reply + '",' \
                                  '"reasoning": "",' \
                                  '"plan": "",' \
                                  '"criticism": "",' \
                                  '"speak": ""' \
                              '},' \
                              '"command": {' \
                                  '"name": "do_nothing", "args": {}' \
                              '}' \
                          '}'
    elif assistant_reply.count('{') == assistant_reply.count('}'):
        # remove everything before the first { and after the last }
        assistant_reply = assistant_reply[assistant_reply.find('{'):assistant_reply.rfind('}') + 1]
    else:
        while assistant_reply.count('{') != assistant_reply.count('}'):
            if assistant_reply.count('{') > assistant_reply.count('}'):
                # add a } to the end
                assistant_reply = assistant_reply + '}'
            else:
                # add a { to the beginning
                assistant_reply = '{' + assistant_reply

Maybe it will help someone

it works!

jubalix commented 1 year ago

I also get this error

CRITICISM: I need to make sure that the information provided by Google Search is trustworthy by verifying it with other sources. Attempting to fix JSON by finding outermost brackets Apparently json was fixed.

and

"Error: Invalid JSON In order to generate the next command JSON, I need to know more about the current task. Can you provide me with more context and a description of what you would like to accomplish? Attempting to fix JSON by finding outermost brackets Error: Invalid JSON, setting it to empty JSON now."

jubalix commented 1 year ago

Unfortunately gpt does not always stick to the right format when replying, sometimes adding something at the beginning, sometimes replying in plain text, and sometimes json is just broken. To try to restore the format in some cases I added this code after line 324 in main.py locally:

try:
    json.loads(assistant_reply)
except ValueError as e:
    if assistant_reply.count('{') == assistant_reply.count('}') == 0:
        # remove " and '
        assistant_reply = assistant_reply.replace('"', '').replace("'", '')
        assistant_reply = '{' \
                              '"thoughts": {' \
                                  '"text": "' + assistant_reply + '",' \
                                  '"reasoning": "",' \
                                  '"plan": "",' \
                                  '"criticism": "",' \
                                  '"speak": ""' \
                              '},' \
                              '"command": {' \
                                  '"name": "do_nothing", "args": {}' \
                              '}' \
                          '}'
    elif assistant_reply.count('{') == assistant_reply.count('}'):
        # remove everything before the first { and after the last }
        assistant_reply = assistant_reply[assistant_reply.find('{'):assistant_reply.rfind('}') + 1]
    else:
        while assistant_reply.count('{') != assistant_reply.count('}'):
            if assistant_reply.count('{') > assistant_reply.count('}'):
                # add a } to the end
                assistant_reply = assistant_reply + '}'
            else:
                # add a { to the beginning
                assistant_reply = '{' + assistant_reply

Maybe it will help someone

it works!

I i treid it ---does not work, story of every time i try to do any programing or scripting etc always wierd erros and never works

ALPERDURUKAN commented 1 year ago

Same here, constantly receiving following output when running on Colab:

CRITICISM: 
Attempting to fix JSON by finding outermost brackets 
Error: Invalid JSON, setting it to empty JSON now.

NEXT ACTION:  COMMAND = Error: ARGUMENTS = 'dict' object has no attribute 'replace'
jellzone commented 1 year ago

same issue

MrPeterJin commented 1 year ago

same issue

henryxlin commented 1 year ago

Still getting this error.

tdaubs commented 1 year ago

Same here. Win 10 using --gpt3only

Drlordbasil commented 1 year ago

awaiting fix as well.

matt14e commented 1 year ago

Does this error only occur with GPT 3.5?

Leonop commented 1 year ago

Same issue here: Error: Invalid JSON, setting it to empty JSON now. Anyone knows why?

iliaamiri commented 1 year ago

I'm not familiar with the repo. but what if you ask chatGPT to fix the JSON for you again? and strictly mention to it to only respond in JSON.