Skip to content

Commit

Permalink
Added even more fixes (out of what I just encountered while testing)
Browse files Browse the repository at this point in the history
It seems that cut of json can be corrected and sometimes the model is to
lazy to add not just one curly brace but two. I think it does not "cost"
a lot to try them all out. But the expeptions get massive that way :)
  • Loading branch information
oderwat committed Nov 7, 2023
1 parent f6648c8 commit dbf29c1
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions memgpt/local_llm/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,26 @@ def clean_json(raw_llm_output, messages=None, functions=None):
data = json.loads(raw_llm_output + "}")
except json.JSONDecodeError:
try:
repaired = repair_json_string(raw_llm_output)
printd("trying my repair json:", repaired)
data = json.loads(repaired)
printd("trying adding }}")
data = json.loads(raw_llm_output + "}}")
except json.JSONDecodeError:
try:
repaired = repair_json_string(raw_llm_output)
printd("trying my repair json:", repaired)
data = json.loads(repaired)
printd('trying adding "}}')
data = json.loads(raw_llm_output + '"}}')
except json.JSONDecodeError:
try:
printd("trying first_json")
data = extract_first_json(raw_llm_output + "}")
except:
raise
repaired = repair_json_string(raw_llm_output)
printd("trying my repair json:", repaired)
data = json.loads(repaired)
except json.JSONDecodeError:
try:
repaired = repair_json_string(raw_llm_output)
printd("trying my repair json:", repaired)
data = json.loads(repaired)
except json.JSONDecodeError:
try:
printd("trying first_json")
data = extract_first_json(raw_llm_output + "}")
except:
raise
return data

0 comments on commit dbf29c1

Please sign in to comment.