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.
Merge branch 'master' into fix-user-feedback-json-error
Wladastic1f9d66b74529
diff --cc scripts/main.pyindex cb28602675,3dfcaa157e..654434e8ba--- a/scripts/main.py+++ b/scripts/main.py@@@ -44,32 -57,9 +57,33 @@@ def print_to_consolemax_typing_speed = max_typing_speed * 0.95print()+def attempt_to_fix_json_by_finding_outermost_brackets(json_string):+ # Attempt to fix JSON by finding the outermost brackets+ # This is a hacky solution to fix JSON that is missing the outermost brackets+ # This is a common issue with the OpenAI API+ # This is not a perfect solution, but it works for the most common cases+ # it removes unnecessary text around the JSON+ if cfg.speak_mode:+ speak.say_text("I have received an invalid JSON response from the OpenAI API. Trying to fix it now.")+ print_to_console("Attempting to fix JSON by finding outermost brackets\n", Fore.RED,"")+ try:+ # Find the first bracket+ first_bracket_index = json_string.index("{")+ # Find the last bracket+ last_bracket_index = json_string.rindex("}")+ # Slice the string to get the JSON+ json_string = json_string[first_bracket_index:last_bracket_index + 1]+ if cfg.speak_mode:+ speak.say_text("Apparently I managed to fix it.")+ except json.JSONDecodeError as e:+ if cfg.speak_mode:+ speak.say_text("Didn't work. I will have to ignore this response then.")+ print_to_console("Error: Invalid JSON, setting it to empty JSON now.\n", Fore.RED, "")+ json_string = {}+ return json_stringdef print_assistant_thoughts(assistant_reply):+ """Prints the assistant's thoughts to the console"""global ai_nameglobal cfgtry: