Skip to content

Commit

Permalink
better json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonalaird committed Oct 6, 2024
1 parent dda1e64 commit 10c6332
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vision_agent/agent/agent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ def _strip_markdown_code(inp_str: str) -> str:

def extract_json(json_str: str) -> Dict[str, Any]:
json_str_mod = json_str.replace("\n", " ").strip()
json_str_mod = json_str_mod.replace("'", '"')
json_str_mod = json_str_mod.replace(": True", ": true").replace(
": False", ": false"
)

# sometimes the json is in single quotes
try:
return json.loads(json_str_mod.replace("'", '"')) # type: ignore
except json.JSONDecodeError:
pass

try:
return json.loads(json_str_mod) # type: ignore
except json.JSONDecodeError:
Expand Down

0 comments on commit 10c6332

Please sign in to comment.