AutoGPT: Make core.prompting.utils:json_loads slightly more robust

This commit is contained in:
Reinier van der Leer
2023-10-17 19:47:25 -07:00
parent 7a7e1578d3
commit cd0df40a4f

View File

@@ -18,6 +18,7 @@ def json_loads(json_str: str):
# Can hopefully just replace with a call to ast.literal_eval (the function api still
# sometimes returns json strings with minor issues like trailing commas).
try:
json_str = json_str[json_str.index("{"):json_str.rindex("}")]
return ast.literal_eval(json_str)
except json.decoder.JSONDecodeError as e:
try: