fix up json parsing (#875)

This commit is contained in:
Robert Brennan 2024-04-08 01:39:36 -05:00 committed by GitHub
parent fab2259d3a
commit cc6626ff0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 5 deletions

View File

@ -25,6 +25,11 @@ def loads(s, **kwargs):
"""
Create a JSON object from str
"""
s_repaired = repair_json(s)
return json.loads(s_repaired, **kwargs)
json_start = s.find("{")
json_end = s.rfind("}") + 1
if json_start == -1 or json_end == -1:
raise ValueError("Invalid response: no JSON found")
s = s[json_start:json_end]
s = repair_json(s)
return json.loads(s, **kwargs)

View File

@ -151,9 +151,6 @@ def parse_action_response(response: str) -> Action:
Returns:
- Action: The action that was found in the response string
"""
json_start = response.find("{")
json_end = response.rfind("}") + 1
response = response[json_start:json_end]
action_dict = json.loads(response)
if 'content' in action_dict:
# The LLM gets confused here. Might as well be robust