fix(discord_bot): unified prompt JSON '{' parsing fallback

This commit is contained in:
2026-03-23 20:43:41 +09:00
parent e5a52f68ab
commit c59c934ff5
5 changed files with 25 additions and 17 deletions

View File

@@ -183,6 +183,18 @@ def _parse_unified_response(raw: str) -> dict:
except json.JSONDecodeError:
break
# 2.5) JSON 시작 중괄호 누락 복구
raw_s = raw.strip()
if raw_s.startswith('"mode"'):
if not raw_s.startswith("{"):
raw_s = "{" + raw_s
if not raw_s.endswith("}"):
raw_s = raw_s + "}"
try:
return json.loads(raw_s, strict=False)
except json.JSONDecodeError:
pass
# 3) 파싱 실패 → chat 모드 폴백
logger.warning(f"unified 응답 JSON 파싱 실패: {raw[:200]}")
return {"mode": "chat", "response": raw}