File size: 401 Bytes
bc216e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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