feat: GLM 응답 content 비어있을 때 경고 메시지 추가 및 JSON 파싱 실패 처리 개선

- GLM 응답의 content가 비어있을 경우 경고 메시지를 출력하도록 로직 추가
- JSON 파싱 시 raw가 비어있을 경우 ValueError를 발생시켜 오류 처리를 강화
- 관련 문서 및 README.md에 변경 사항 반영
This commit is contained in:
kswdev0
2026-03-26 11:04:38 +09:00
parent 0a46e16e5b
commit b014df06b8

View File

@@ -313,6 +313,18 @@ class AIPlanner:
t_json0 = time.perf_counter()
data = json.loads(raw_text)
content = data["choices"][0]["message"]["content"].strip()
if not content:
# content가 비어있으면 이후 JSON 파서가 원인 파악이 어렵다.
# GLM_DEBUG=1에서 raw 응답 일부를 함께 보여준다.
if _glm_debug_enabled():
finish_reason = data.get("choices", [{}])[0].get("finish_reason")
print(
"[경고] GLM 응답 content 비어있음 | "
f"finish_reason={finish_reason!r} | "
f"raw_preview={raw_text[:600]!r}"
)
else:
print("[경고] GLM 응답 content가 비어있습니다. (GLM_DEBUG=1 시 raw_preview 출력)")
t_json_done = time.perf_counter()
dt_total = time.perf_counter() - t_total0
@@ -359,6 +371,9 @@ class AIPlanner:
return self._plan_from_actions_array(loaded)
except json.JSONDecodeError:
pass
if not text:
raise ValueError("JSON 파싱 실패: raw가 비어있습니다.")
start = text.find("{")
if start == -1:
# GLM이 상단 레벨에서 JSON 배열(`[ ... ]`)로 응답하는 경우를 허용