mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
Handles incorrect AI formatting in a more forgiving way.
This commit is contained in:
@@ -15,9 +15,19 @@ cfg = Config()
|
|||||||
def get_command(response):
|
def get_command(response):
|
||||||
try:
|
try:
|
||||||
response_json = fix_and_parse_json(response)
|
response_json = fix_and_parse_json(response)
|
||||||
|
|
||||||
|
if "command" not in response_json:
|
||||||
|
return "Error:" , "Missing 'command' object in JSON"
|
||||||
|
|
||||||
command = response_json["command"]
|
command = response_json["command"]
|
||||||
|
|
||||||
|
if "name" not in command:
|
||||||
|
return "Error:", "Missing 'name' field in 'command' object"
|
||||||
|
|
||||||
command_name = command["name"]
|
command_name = command["name"]
|
||||||
arguments = command["args"]
|
|
||||||
|
# Use an empty dictionary if 'args' field is not present in 'command' object
|
||||||
|
arguments = command.get("args", {})
|
||||||
|
|
||||||
if not arguments:
|
if not arguments:
|
||||||
arguments = {}
|
arguments = {}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ def print_assistant_thoughts(assistant_reply):
|
|||||||
# Parse and print Assistant response
|
# Parse and print Assistant response
|
||||||
assistant_reply_json = fix_and_parse_json(assistant_reply)
|
assistant_reply_json = fix_and_parse_json(assistant_reply)
|
||||||
|
|
||||||
|
try:
|
||||||
assistant_thoughts = assistant_reply_json.get("thoughts")
|
assistant_thoughts = assistant_reply_json.get("thoughts")
|
||||||
if assistant_thoughts:
|
if assistant_thoughts:
|
||||||
assistant_thoughts_text = assistant_thoughts.get("text")
|
assistant_thoughts_text = assistant_thoughts.get("text")
|
||||||
@@ -67,6 +68,8 @@ def print_assistant_thoughts(assistant_reply):
|
|||||||
assistant_thoughts_plan = None
|
assistant_thoughts_plan = None
|
||||||
assistant_thoughts_criticism = None
|
assistant_thoughts_criticism = None
|
||||||
assistant_thoughts_speak = None
|
assistant_thoughts_speak = None
|
||||||
|
except Exception as e:
|
||||||
|
assistant_thoughts_text = "The AI's response was unreadable."
|
||||||
|
|
||||||
print_to_console(
|
print_to_console(
|
||||||
f"{ai_name.upper()} THOUGHTS:",
|
f"{ai_name.upper()} THOUGHTS:",
|
||||||
|
|||||||
Reference in New Issue
Block a user