File size: 836 Bytes
cb61e8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re
import json

def parse_llm_blocks(response_text):
    blocks = {
        "intent": "NONE",
        "params": {},
        "missing": [],
        "action_json": {}
    }
    intent_match = re.search(r"#INTENT:\s*(.+)", response_text)
    params_match = re.search(r"#PARAMS:\s*(\{.*?\})", response_text)
    missing_match = re.search(r"#MISSING:\s*(\[[^\]]*\])", response_text)
    action_match = re.search(r"#ACTION_JSON:\s*(\{.*?\})", response_text)

    if intent_match:
        blocks["intent"] = intent_match.group(1).strip()
    if params_match:
        blocks["params"] = json.loads(params_match.group(1))
    if missing_match:
        blocks["missing"] = json.loads(missing_match.group(1))
    if action_match:
        blocks["action_json"] = json.loads(action_match.group(1))

    return blocks