Skip to content

Commit

Permalink
chore: check for JSON code markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Vedantsahai18 committed Jan 2, 2025
1 parent 2da2c39 commit 9cffe68
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions agents-api/agents_api/activities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ def safe_extract_json(string: str):
if len(string) > MAX_STRING_LENGTH:
msg = f"String exceeds maximum length of {MAX_STRING_LENGTH}"
raise ValueError(msg)
extracted_string = string[
string.find("```json") + 7 : string.find("```", string.find("```json") + 7)
]
# Check if the string contains JSON code block markers
if "```json" in string:
extracted_string = string[
string.find("```json") + 7 : string.find("```", string.find("```json") + 7)
]
else:
# If no markers, try to parse the whole string as JSON
extracted_string = string
return json.loads(extracted_string)


Expand Down

0 comments on commit 9cffe68

Please sign in to comment.