fix(discord_bot): unified prompt JSON '{' parsing fallback
This commit is contained in:
@@ -74,6 +74,7 @@ Discord 메시지
|
|||||||
|
|
||||||
## 최근 마일스톤
|
## 최근 마일스톤
|
||||||
|
|
||||||
|
- **2026-03-23**: discord_bot unified prompt JSON 문법 누락 대응 로직 추가
|
||||||
- **2026-03-22**: debate-agent idle-state 처리 — 대기 규칙 + slug 탐색 + list-debates + handler 시그널 개선
|
- **2026-03-22**: debate-agent idle-state 처리 — 대기 규칙 + slug 탐색 + list-debates + handler 시그널 개선
|
||||||
- **2026-03-21**: debate-agent 분산 토론 시스템 — Wiki.js 기반 통신, AG 프로젝트 스캐폴딩, handler 리팩토링
|
- **2026-03-21**: debate-agent 분산 토론 시스템 — Wiki.js 기반 통신, AG 프로젝트 스캐폴딩, handler 리팩토링
|
||||||
- **2026-03-20**: AI Debate Room v2 — 파일 기반 자동 토론 + Flash 합의 판정 + Wiki.js 동기화
|
- **2026-03-20**: AI Debate Room v2 — 파일 기반 자동 토론 + Flash 합의 판정 + Wiki.js 동기화
|
||||||
|
|||||||
@@ -183,3 +183,9 @@
|
|||||||
- **원인**: Gemini에게 제목 요약 요청 시 `"신용리스크를 측정하는..."` 처럼 따옴표 포함 응답 → `WikiClient.slugify()`가 따옴표 미제거
|
- **원인**: Gemini에게 제목 요약 요청 시 `"신용리스크를 측정하는..."` 처럼 따옴표 포함 응답 → `WikiClient.slugify()`가 따옴표 미제거
|
||||||
- **해결**: (1) 프롬프트를 영문 2-3단어 키워드로 변경, (2) `.strip('"\'')` + `re.sub(r'[^\w\s-]', '')` 로 특수문자 제거, (3) slug 30자 제한
|
- **해결**: (1) 프롬프트를 영문 2-3단어 키워드로 변경, (2) `.strip('"\'')` + `re.sub(r'[^\w\s-]', '')` 로 특수문자 제거, (3) slug 30자 제한
|
||||||
- **주의**: AI 응답을 slug/경로/파일명에 사용 시 **반드시 특수문자 sanitize** 필수. 따옴표, 괄호, 마크다운 기호 등 모두 제거
|
- **주의**: AI 응답을 slug/경로/파일명에 사용 시 **반드시 특수문자 sanitize** 필수. 따옴표, 괄호, 마크다운 기호 등 모두 제거
|
||||||
|
|
||||||
|
### [2026-03-23] unified prompt — JSON 여는 중괄호 누락
|
||||||
|
- **증상**: Gemini 응답에 `{"mode": ...}` 대신 `"mode": ...}`로 출력되어 JSON 파싱이 실패하고 chat 롤백됨
|
||||||
|
- **원인**: 통합 프롬프트 특성상 LLM이 가끔 첫 `{`를 생략하거나 코드문법 없이 바로 출력함
|
||||||
|
- **해결**: `api/discord_bot.py` 의 `_parse_unified_response` 에 `{` 누락 시 `{...}` 로 감싸 재파싱하는 fallback 추가
|
||||||
|
- **주의**: LLM의 JSON 출력 포맷이 항상 완벽할 것이라 가정하지 말고 방어적 파싱 로직 적용 필수
|
||||||
|
|||||||
@@ -8,25 +8,11 @@ sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="repla
|
|||||||
sys.path.insert(0, ".")
|
sys.path.insert(0, ".")
|
||||||
|
|
||||||
from core.gemini_caller import GeminiCaller
|
from core.gemini_caller import GeminiCaller
|
||||||
|
from api.discord_bot import _parse_unified_response
|
||||||
|
|
||||||
def extract_mode(raw):
|
def extract_mode(raw):
|
||||||
start = raw.find("{")
|
parsed = _parse_unified_response(raw)
|
||||||
if start == -1:
|
return parsed.get("mode", "?")
|
||||||
return "NO_JSON"
|
|
||||||
depth = 0
|
|
||||||
for i in range(start, len(raw)):
|
|
||||||
if raw[i] == "{":
|
|
||||||
depth += 1
|
|
||||||
elif raw[i] == "}":
|
|
||||||
depth -= 1
|
|
||||||
if depth == 0:
|
|
||||||
try:
|
|
||||||
p = json.loads(raw[start : i + 1])
|
|
||||||
return p.get("mode", "?")
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
return "PARSE_ERR"
|
|
||||||
return "NO_CLOSE"
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|||||||
@@ -183,6 +183,18 @@ def _parse_unified_response(raw: str) -> dict:
|
|||||||
except json.JSONDecodeError:
|
except json.JSONDecodeError:
|
||||||
break
|
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 모드 폴백
|
# 3) 파싱 실패 → chat 모드 폴백
|
||||||
logger.warning(f"unified 응답 JSON 파싱 실패: {raw[:200]}")
|
logger.warning(f"unified 응답 JSON 파싱 실패: {raw[:200]}")
|
||||||
return {"mode": "chat", "response": raw}
|
return {"mode": "chat", "response": raw}
|
||||||
|
|||||||
3
docs/devlog/2026-03-23.md
Normal file
3
docs/devlog/2026-03-23.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
| # | 시간 | 작업 | 커밋 | 상태 |
|
||||||
|
|----|------|------|------|------|
|
||||||
|
| 001 | 20:42 | api/discord_bot.py 통함 프롬프트 JSON 파싱 '{' 누락 버그 수정 | `TBD` | ✅ |
|
||||||
Reference in New Issue
Block a user