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