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.
Fix various JSON input bugs in correction
Samuel Reed434f27fb51f1
diff --git a/scripts/json_parser.py b/scripts/json_parser.pyindex e96c43f664..5524425559 100644--- a/scripts/json_parser.py+++ b/scripts/json_parser.py@@ -26,7 +26,7 @@ JSON_SCHEMA = """"""-def fix_and_parse_json(+def fix_and_parse_json(json_str: str,try_to_fix_with_gpt: bool = True) -> Union[str, Dict[Any, Any]]:@@ -35,8 +35,8 @@ def fix_and_parse_json(json_str = json_str.replace('\t', '')return json.loads(json_str)except json.JSONDecodeError as _: # noqa: F841- json_str = correct_json(json_str)try:+ json_str = correct_json(json_str)return json.loads(json_str)except json.JSONDecodeError as _: # noqa: F841pass@@ -53,6 +53,7 @@ def fix_and_parse_json(last_brace_index = json_str.rindex("}")json_str = json_str[:last_brace_index+1]return json.loads(json_str)+ # Can throw a ValueError if there is no "{" or "}" in the json_strexcept (json.JSONDecodeError, ValueError) as e: # noqa: F841if try_to_fix_with_gpt:print("Warning: Failed to parse AI output, attempting to fix."