Files
Auto-GPT/scripts/json_parser.py
Taylor Brown dca5b78bfe Add missing json_parser.py and add alternative requirements
This adds fix_and_parse_json
Also, add requirements-alternative.txt to help install reqs in a different environment
2023-04-02 17:34:11 -05:00

12 lines
371 B
Python

import dirtyjson
from ai_functions import fix_json
def fix_and_parse_json(json_str: str, try_to_fix_with_gpt: bool = True):
try:
return dirtyjson.loads(json_str)
except Exception as e:
if try_to_fix_with_gpt:
# Now try to fix this up using the ai_functions
return fix_json(json_str, None, True)
else:
raise e