mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
fix up json parsing (#875)
This commit is contained in:
parent
fab2259d3a
commit
cc6626ff0d
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user