ciyidogan commited on
Commit
e25edcf
·
verified ·
1 Parent(s): edc8519

Create parse_llm_blocks.py

Browse files
Files changed (1) hide show
  1. parse_llm_blocks.py +25 -0
parse_llm_blocks.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import json
3
+
4
+ def parse_llm_blocks(response_text):
5
+ blocks = {
6
+ "intent": "NONE",
7
+ "params": {},
8
+ "missing": [],
9
+ "action_json": {}
10
+ }
11
+ intent_match = re.search(r"#INTENT:\s*(.+)", response_text)
12
+ params_match = re.search(r"#PARAMS:\s*(\{.*?\})", response_text)
13
+ missing_match = re.search(r"#MISSING:\s*(\[[^\]]*\])", response_text)
14
+ action_match = re.search(r"#ACTION_JSON:\s*(\{.*?\})", response_text)
15
+
16
+ if intent_match:
17
+ blocks["intent"] = intent_match.group(1).strip()
18
+ if params_match:
19
+ blocks["params"] = json.loads(params_match.group(1))
20
+ if missing_match:
21
+ blocks["missing"] = json.loads(missing_match.group(1))
22
+ if action_match:
23
+ blocks["action_json"] = json.loads(action_match.group(1))
24
+
25
+ return blocks