mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 14:34:23 +01:00
cleanup method
This commit is contained in:
@@ -49,68 +49,44 @@ def print_assistant_thoughts(assistant_reply):
|
|||||||
global ai_name
|
global ai_name
|
||||||
global cfg
|
global cfg
|
||||||
try:
|
try:
|
||||||
# Parse and print Assistant response
|
|
||||||
assistant_reply_json = fix_and_parse_json(assistant_reply)
|
assistant_reply_json = fix_and_parse_json(assistant_reply)
|
||||||
|
|
||||||
assistant_thoughts_reasoning = None
|
assistant_thoughts_reasoning = None
|
||||||
assistant_thoughts_plan = None
|
assistant_thoughts_plan = None
|
||||||
assistant_thoughts_speak = None
|
assistant_thoughts_speak = None
|
||||||
assistant_thoughts_criticism = None
|
assistant_thoughts_criticism = None
|
||||||
try:
|
assistant_thoughts = assistant_reply_json.get("thoughts", {})
|
||||||
assistant_thoughts = assistant_reply_json.get("thoughts")
|
assistant_thoughts_text = assistant_thoughts.get("text")
|
||||||
if assistant_thoughts:
|
|
||||||
assistant_thoughts_text = assistant_thoughts.get("text")
|
if assistant_thoughts:
|
||||||
assistant_thoughts_reasoning = assistant_thoughts.get("reasoning")
|
assistant_thoughts_reasoning = assistant_thoughts.get("reasoning")
|
||||||
assistant_thoughts_plan = assistant_thoughts.get("plan")
|
assistant_thoughts_plan = assistant_thoughts.get("plan")
|
||||||
assistant_thoughts_criticism = assistant_thoughts.get("criticism")
|
assistant_thoughts_criticism = assistant_thoughts.get("criticism")
|
||||||
assistant_thoughts_speak = assistant_thoughts.get("speak")
|
assistant_thoughts_speak = assistant_thoughts.get("speak")
|
||||||
else:
|
|
||||||
assistant_thoughts_text = None
|
print_to_console(f"{ai_name.upper()} THOUGHTS:", Fore.YELLOW, assistant_thoughts_text)
|
||||||
assistant_thoughts_reasoning = None
|
print_to_console("REASONING:", Fore.YELLOW, assistant_thoughts_reasoning)
|
||||||
assistant_thoughts_plan = None
|
|
||||||
assistant_thoughts_criticism = None
|
|
||||||
assistant_thoughts_speak = None
|
|
||||||
except Exception:
|
|
||||||
assistant_thoughts_text = "The AI's response was unreadable."
|
|
||||||
|
|
||||||
print_to_console(
|
|
||||||
f"{ai_name.upper()} THOUGHTS:",
|
|
||||||
Fore.YELLOW,
|
|
||||||
assistant_thoughts_text)
|
|
||||||
print_to_console(
|
|
||||||
"REASONING:",
|
|
||||||
Fore.YELLOW,
|
|
||||||
assistant_thoughts_reasoning)
|
|
||||||
if assistant_thoughts_plan:
|
if assistant_thoughts_plan:
|
||||||
print_to_console("PLAN:", Fore.YELLOW, "")
|
print_to_console("PLAN:", Fore.YELLOW, "")
|
||||||
if assistant_thoughts_plan:
|
if isinstance(assistant_thoughts_plan, list):
|
||||||
# If it's a list, join it into a string
|
assistant_thoughts_plan = "\n".join(assistant_thoughts_plan)
|
||||||
if isinstance(assistant_thoughts_plan, list):
|
elif isinstance(assistant_thoughts_plan, dict):
|
||||||
assistant_thoughts_plan = "\n".join(assistant_thoughts_plan)
|
assistant_thoughts_plan = str(assistant_thoughts_plan)
|
||||||
elif isinstance(assistant_thoughts_plan, dict):
|
|
||||||
assistant_thoughts_plan = str(assistant_thoughts_plan)
|
|
||||||
# Split the input_string using the newline character and dash
|
|
||||||
|
|
||||||
lines = assistant_thoughts_plan.split('\n')
|
lines = assistant_thoughts_plan.split('\n')
|
||||||
|
for line in lines:
|
||||||
|
line = line.lstrip("- ")
|
||||||
|
print_to_console("- ", Fore.GREEN, line.strip())
|
||||||
|
|
||||||
# Iterate through the lines and print each one with a bullet
|
print_to_console("CRITICISM:", Fore.YELLOW, assistant_thoughts_criticism)
|
||||||
# point
|
|
||||||
for line in lines:
|
|
||||||
# Remove any "-" characters from the start of the line
|
|
||||||
line = line.lstrip("- ")
|
|
||||||
print_to_console("- ", Fore.GREEN, line.strip())
|
|
||||||
print_to_console(
|
|
||||||
"CRITICISM:",
|
|
||||||
Fore.YELLOW,
|
|
||||||
assistant_thoughts_criticism)
|
|
||||||
|
|
||||||
# Speak the assistant's thoughts
|
|
||||||
if cfg.speak_mode and assistant_thoughts_speak:
|
if cfg.speak_mode and assistant_thoughts_speak:
|
||||||
speak.say_text(assistant_thoughts_speak)
|
speak.say_text(assistant_thoughts_speak)
|
||||||
|
|
||||||
except json.decoder.JSONDecodeError:
|
except json.decoder.JSONDecodeError:
|
||||||
print_to_console("Error: Invalid JSON\n", Fore.RED, assistant_reply)
|
print_to_console("Error: Invalid JSON\n", Fore.RED, assistant_reply)
|
||||||
# All other errors, return "Error: + error message"
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
call_stack = traceback.format_exc()
|
call_stack = traceback.format_exc()
|
||||||
print_to_console("Error: \n", Fore.RED, call_stack)
|
print_to_console("Error: \n", Fore.RED, call_stack)
|
||||||
|
|||||||
Reference in New Issue
Block a user