From a754f91abfa0b57d3f9e23093c8f7e7f786a1de9 Mon Sep 17 00:00:00 2001 From: Marker689 Date: Sun, 10 May 2026 05:14:38 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=83=D1=81=D1=82=D0=BE=D0=B9=D1=87?= =?UTF-8?q?=D0=B8=D0=B2=D1=8B=D0=B9=20=D0=BF=D0=B0=D1=80=D1=81=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=20LLM-=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D0=B0=20=E2=80=94?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20mar?= =?UTF-8?q?kdown=20code=20blocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - llm.py: возвращён (нужен для structured output) - Добавлен fallback-парсинг для ответов обёрнутых в ```json - Устранён undefined-variable баг в except-блоке --- guarddog_nexus/llm.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/guarddog_nexus/llm.py b/guarddog_nexus/llm.py index 7170c7c..41f93e2 100644 --- a/guarddog_nexus/llm.py +++ b/guarddog_nexus/llm.py @@ -83,9 +83,24 @@ async def analyze_finding(finding_data: dict) -> dict | None: content = body["choices"][0]["message"]["content"] return json.loads(content) except (KeyError, IndexError, json.JSONDecodeError) as e: + raw = "" + try: + raw = body["choices"][0]["message"]["content"] + except (KeyError, IndexError): + raw = str(body)[:300] + # Some models wrap JSON in markdown code blocks + if isinstance(raw, str) and raw.strip().startswith("```"): + try: + stripped = raw.strip().strip("`").strip() + if stripped.startswith("json\n"): + stripped = stripped[5:] + return json.loads(stripped) + except json.JSONDecodeError: + pass log.warning( - "LLM response parse error for rule=%s: %s", + "LLM response parse error for rule=%s: %s — raw=%s", finding_data.get("rule"), e, + raw[:200] if isinstance(raw, str) else str(raw)[:200], ) return None