Handles incorrect AI formatting in a more forgiving way.

This commit is contained in:
Toran Bruce Richards
2023-04-03 11:30:06 +01:00
parent 41daf07219
commit 099a5e1090
2 changed files with 27 additions and 14 deletions

View File

@@ -15,9 +15,19 @@ cfg = Config()
def get_command(response):
try:
response_json = fix_and_parse_json(response)
if "command" not in response_json:
return "Error:" , "Missing 'command' object in JSON"
command = response_json["command"]
if "name" not in command:
return "Error:", "Missing 'name' field in 'command' object"
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:
arguments = {}