Spaces:
Paused
Paused
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 | |