cs-ai-sakura-dev / src /utils /json_cleaner.py
lifedebugger's picture
Deploy files from GitHub repository
bc216e0
import json
from typing import Dict
def clean_response(res:str):
try:
raw = res.strip()
# bersihin block fencing kalau ada
if raw.startswith("```"):
import re
raw = re.sub(r"^```[a-zA-Z]*\n?", "", raw)
raw = re.sub(r"\n?```$", "", raw)
j_res = json.loads(raw)
return j_res
except Exception as e:
return None