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
This commit is contained in:
Taylor Brown
2023-04-02 17:34:11 -05:00
parent 2b5a7cc485
commit dca5b78bfe
3 changed files with 30 additions and 1 deletions

12
scripts/json_parser.py Normal file
View File

@@ -0,0 +1,12 @@
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