π OpenHands: AI-Driven Development
fix up json parsing (#875)
Robert Brennancc6626ff0da9
diff --git a/agenthub/monologue_agent/utils/json.py b/agenthub/monologue_agent/utils/json.pyindex e75941ea77..f8a82fc45f 100644--- a/agenthub/monologue_agent/utils/json.py+++ b/agenthub/monologue_agent/utils/json.py@@ -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)diff --git a/agenthub/monologue_agent/utils/prompts.py b/agenthub/monologue_agent/utils/prompts.pyindex f083b9ebc5..c58cb2dd9e 100644--- a/agenthub/monologue_agent/utils/prompts.py+++ b/agenthub/monologue_agent/utils/prompts.py@@ -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