grading-agent / utils.py
Hammad712's picture
Create utils.py
b0b0d13 verified
raw
history blame contribute delete
402 Bytes
import json
def extract_json_from_output(output_str: str) -> dict:
"""
Extracts a JSON object from a string containing extra text.
"""
start = output_str.find('{')
end = output_str.rfind('}')
if start == -1 or end == -1:
return None
json_str = output_str[start:end+1]
try:
return json.loads(json_str)
except json.JSONDecodeError:
return None