diff --git a/src/report_generator.py b/src/report_generator.py index 8558f85..789a57c 100644 --- a/src/report_generator.py +++ b/src/report_generator.py @@ -150,10 +150,44 @@ LAGEBILD: try: result, usage = await call_claude(prompt, tools=None, model=CLAUDE_MODEL_FAST) - # In HTML-Liste umwandeln - lines = [line.strip().lstrip("- ").lstrip("* ") for line in result.strip().split("\n") if line.strip().startswith(("-", "*"))] + # Robuster Parser: Akzeptiert JSON, Markdown-Listen oder Freitext + lines = [] + text = result.strip() + + # Fall 1: JSON-Antwort (Haiku gibt manchmal JSON zurück) + if text.startswith("{"): + try: + data = json.loads(text) + for key in data: + if isinstance(data[key], list): + for item in data[key]: + clean = str(item).strip().lstrip("- ").lstrip("* ") + if clean: + lines.append(clean) + break + except json.JSONDecodeError: + pass + + # Fall 2: Markdown Bullet Points if not lines: - lines = [result.strip()] + for line in text.split("\n"): + stripped = line.strip() + if stripped.startswith(("- ", "* ")): + clean = stripped.lstrip("- ").lstrip("* ").strip() + if clean: + lines.append(clean) + + # Fall 3: Nummerierte Liste (1. 2. 3.) + if not lines: + for line in text.split("\n"): + m = re.match(r"^\d+\.\s+(.+)", line.strip()) + if m: + lines.append(m.group(1).strip()) + + # Fallback: Ganzen Text als einen Punkt + if not lines: + lines = [text[:500]] + html = "" return html except Exception as e: