diff --git a/ai_planner.py b/ai_planner.py index c67cc99..ef8a6fc 100644 --- a/ai_planner.py +++ b/ai_planner.py @@ -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 배열(`[ ... ]`)로 응답하는 경우를 허용