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.
Add master_json_fix_method module for unified JSON handling
Merwane Hamadifec25cd6903a
diff --git a/autogpt/json_fixes/master_json_fix_method.py b/autogpt/json_fixes/master_json_fix_method.pynew file mode 100644index 0000000000..7a2cf3cc81--- /dev/null+++ b/autogpt/json_fixes/master_json_fix_method.py@@ -0,0 +1,28 @@+from typing import Any, Dict++from autogpt.config import Config+from autogpt.logs import logger+from autogpt.speech import say_text+CFG = Config()+++def fix_json_using_multiple_techniques(assistant_reply: str) -> Dict[Any, Any]:+ from autogpt.json_fixes.parsing import attempt_to_fix_json_by_finding_outermost_brackets++ from autogpt.json_fixes.parsing import fix_and_parse_json++ # Parse and print Assistant response+ assistant_reply_json = fix_and_parse_json(assistant_reply)+ if assistant_reply_json == {}:+ assistant_reply_json = attempt_to_fix_json_by_finding_outermost_brackets(+ assistant_reply+ )++ if assistant_reply_json != {}:+ return assistant_reply_json++ logger.error("Error: The following AI output couldn't be converted to a JSON:\n", assistant_reply)+ if CFG.speak_mode:+ say_text("I have received an invalid JSON response from the OpenAI API.")++ return {}