File size: 1,318 Bytes
a914cec
 
9f7fb7f
 
 
 
 
 
 
a914cec
 
 
 
 
 
 
 
 
 
9f7fb7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a914cec
 
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import re
import json

def extract_block(tag, text):
    pattern = rf"{tag}:(.*?)(?=\n#|$)"
    match = re.search(pattern, text, re.DOTALL)
    if match:
        return match.group(1).strip()
    return None

def parse_llm_blocks(response_text):
    blocks = {
        "answer": "",
        "intent": "NONE",
        "params": {},
        "missing": [],
        "action_json": {}
    }

    # Ana etiket bloklarını sırayla çek
    answer_raw = extract_block(r"#ANSWER", response_text)
    intent_raw = extract_block(r"#INTENT", response_text)
    params_raw = extract_block(r"#PARAMS", response_text)
    missing_raw = extract_block(r"#MISSING", response_text)
    action_raw = extract_block(r"#ACTION_JSON", response_text)

    if answer_raw:
        blocks["answer"] = answer_raw

    if intent_raw:
        blocks["intent"] = intent_raw

    if params_raw:
        try:
            blocks["params"] = json.loads(params_raw)
        except Exception:
            blocks["params"] = {}

    if missing_raw:
        try:
            blocks["missing"] = json.loads(missing_raw)
        except Exception:
            blocks["missing"] = []

    if action_raw:
        try:
            blocks["action_json"] = json.loads(action_raw)
        except Exception:
            blocks["action_json"] = {}

    return blocks