feat(global): errors logs are logged as debug level and activated with program argument 'debug'

This commit is contained in:
Fabrice Hong
2023-04-08 01:05:08 +02:00
parent 0e004f5c14
commit 43c006d71c
5 changed files with 148 additions and 26 deletions

View File

@@ -76,7 +76,6 @@ def fix_and_parse_json(
def fix_json(json_str: str, schema: str) -> str:
"""Fix the given JSON string to make it parseable and fully compliant with the provided schema."""
# Try to fix the JSON using GPT:
function_string = "def fix_json(json_str: str, schema:str=None) -> str:"
args = [f"'''{json_str}'''", f"'''{schema}'''"]
@@ -92,12 +91,11 @@ def fix_json(json_str: str, schema: str) -> str:
result_string = call_ai_function(
function_string, args, description_string, model=cfg.fast_llm_model
)
if cfg.debug_mode:
print("------------ JSON FIX ATTEMPT ---------------")
print(f"Original JSON: {json_str}")
print("-----------")
print(f"Fixed JSON: {result_string}")
print("----------- END OF FIX ATTEMPT ----------------")
logger.log(content="------------ JSON FIX ATTEMPT ---------------", level=logging.DEBUG)
logger.log(content=f"Original JSON: {json_str}", level=logging.DEBUG)
logger.log(content="-----------", level=logging.DEBUG)
logger.log(content=f"Fixed JSON: {result_string}", level=logging.DEBUG)
logger.log(content="----------- END OF FIX ATTEMPT ----------------", level=logging.DEBUG)
try:
json.loads(result_string) # just check the validity