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.
Update json_parser.py
Andres Caicedo621f18eba79f
diff --git a/scripts/json_parser.py b/scripts/json_parser.pyindex 5153f71b04..e827b75336 100644--- a/scripts/json_parser.py+++ b/scripts/json_parser.py@@ -1,6 +1,7 @@import jsonfrom call_ai_function import call_ai_functionfrom config import Config+cfg = Config()def fix_and_parse_json(json_str: str, try_to_fix_with_gpt: bool = True):@@ -37,15 +38,18 @@ def fix_and_parse_json(json_str: str, try_to_fix_with_gpt: bool = True):json_str = json_str[:last_brace_index+1]return json.loads(json_str)except Exception as e:+if try_to_fix_with_gpt:print(f"Warning: Failed to parse AI output, attempting to fix.\n If you see this warning frequently, it's likely that your prompt is confusing the AI. Try changing it up slightly.")# Now try to fix this up using the ai_functionsai_fixed_json = fix_json(json_str, json_schema, False)+if ai_fixed_json != "failed":return json.loads(ai_fixed_json)else:print(f"Failed to fix ai output, telling the AI.") # This allows the AI to react to the error message, which usually results in it correcting its ways.return json_str+else:raise e@@ -59,15 +63,18 @@ def fix_json(json_str: str, schema: str, debug=False) -> str:# If it doesn't already start with a "`", add one:if not json_str.startswith("`"):json_str = "```json\n" + json_str + "\n```"+result_string = call_ai_function(function_string, args, description_string, model=cfg.fast_llm_model)+if debug:print("------------ JSON FIX ATTEMPT ---------------")print(f"Original JSON: {json_str}")print("-----------")print(f"Fixed JSON: {result_string}")print("----------- END OF FIX ATTEMPT ----------------")+try:return json.loads(result_string)except: