Skip to content

Commit

Permalink
fix assistant thoughts failure on string type
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefissa committed Apr 4, 2023
1 parent 4839a0d commit 82da7f1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def print_assistant_thoughts(assistant_reply):
# Parse and print Assistant response
assistant_reply_json = fix_and_parse_json(assistant_reply)

# Check if assistant_reply_json is a string and attempt to parse it into a JSON object
if isinstance(assistant_reply_json, str):
try:
assistant_reply_json = json.loads(assistant_reply_json)
except json.JSONDecodeError as e:
print_to_console("Error: Invalid JSON\n", Fore.RED, assistant_reply)
assistant_reply_json = {}

assistant_thoughts_reasoning = None
assistant_thoughts_plan = None
assistant_thoughts_speak = None
Expand Down Expand Up @@ -90,10 +98,6 @@ def print_assistant_thoughts(assistant_reply):
except json.decoder.JSONDecodeError:
print_to_console("Error: Invalid JSON\n", Fore.RED, assistant_reply)

# All other errors, return "Error: + error message"
except Exception as e:
call_stack = traceback.format_exc()
print_to_console("Error: \n", Fore.RED, call_stack)


def load_variables(config_file="config.yaml"):
Expand Down

0 comments on commit 82da7f1

Please sign in to comment.