Spaces:
Paused
Paused
File size: 2,189 Bytes
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 53 54 55 56 57 58 59 60 61 | import re
import json
from log import log
def parse_llm_blocks(response_text):
blocks = {
"answer": "",
"intent": "NONE",
"params": {},
"missing": [],
"action_json": {}
}
try:
answer_match = re.search(r"#ANSWER:\s*(.+)", response_text)
if answer_match:
blocks["answer"] = answer_match.group(1).strip()
else:
log(f"⚠️ ANSWER blok bulunamadı. Ham içerik: {response_text}")
intent_match = re.search(r"#INTENT:\s*(.+)", response_text)
if intent_match:
blocks["intent"] = intent_match.group(1).strip()
else:
log(f"⚠️ INTENT blok bulunamadı. Ham içerik: {response_text}")
params_match = re.search(r"#PARAMS:\s*(\{.*?\})", response_text)
if params_match:
try:
blocks["params"] = json.loads(params_match.group(1))
except json.JSONDecodeError:
log(f"⚠️ PARAMS JSON parse hatası: {params_match.group(1)}")
blocks["params"] = {}
else:
log(f"⚠️ PARAMS blok bulunamadı. Ham içerik: {response_text}")
missing_match = re.search(r"#MISSING:\s*(\[[^\]]*\])", response_text)
if missing_match:
try:
blocks["missing"] = json.loads(missing_match.group(1))
except json.JSONDecodeError:
log(f"⚠️ MISSING JSON parse hatası: {missing_match.group(1)}")
blocks["missing"] = []
else:
log(f"⚠️ MISSING blok bulunamadı. Ham içerik: {response_text}")
action_match = re.search(r"#ACTION_JSON:\s*(\{.*?\})", response_text)
if action_match:
try:
blocks["action_json"] = json.loads(action_match.group(1))
except json.JSONDecodeError:
log(f"⚠️ ACTION_JSON parse hatası: {action_match.group(1)}")
blocks["action_json"] = {}
else:
log(f"⚠️ ACTION_JSON blok bulunamadı. Ham içerik: {response_text}")
except Exception as e:
log(f"❌ parse_llm_blocks() genel hatası: {e}")
return blocks
|