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