File size: 439 Bytes
ddd9009
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import re
import json

def clean_ai_response(text: str) -> str:
    if not text:
        return text
    text = re.sub(r"^```[a-zA-Z]*\n?", "", text.strip())
    text = re.sub(r"\n?```$", "", text.strip())
    return text.strip()

def parse_json_safe(text: str) -> dict:
    try:
        return json.loads(text)
    except Exception:
        return {"category": "Unknown", "priority": "Unknown", "action": "Parsing failed"}