Fix: Executive Summary Parser — akzeptiert JSON, Markdown und nummerierte Listen
Dieser Commit ist enthalten in:
@@ -150,10 +150,44 @@ LAGEBILD:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
result, usage = await call_claude(prompt, tools=None, model=CLAUDE_MODEL_FAST)
|
result, usage = await call_claude(prompt, tools=None, model=CLAUDE_MODEL_FAST)
|
||||||
# In HTML-Liste umwandeln
|
# Robuster Parser: Akzeptiert JSON, Markdown-Listen oder Freitext
|
||||||
lines = [line.strip().lstrip("- ").lstrip("* ") for line in result.strip().split("\n") if line.strip().startswith(("-", "*"))]
|
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:
|
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 = "<ul>\n" + "\n".join(f"<li>{line}</li>" for line in lines if line) + "\n</ul>"
|
html = "<ul>\n" + "\n".join(f"<li>{line}</li>" for line in lines if line) + "\n</ul>"
|
||||||
return html
|
return html
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
In neuem Issue referenzieren
Einen Benutzer sperren