diff --git a/src/routers/incidents.py b/src/routers/incidents.py index f77778a..d69663d 100644 --- a/src/routers/incidents.py +++ b/src/routers/incidents.py @@ -186,6 +186,30 @@ Erstelle eine knappe, informative Beschreibung mit: Schreibe NUR die Beschreibung als Fliesstext (3-5 Zeilen). Keine Erklaerungen davor oder danach.""" +def _json_to_text(obj, depth=0): + """Konvertiert verschachteltes JSON in lesbaren Fliesstext.""" + parts = [] + if isinstance(obj, str): + return obj + if isinstance(obj, list): + for item in obj: + if isinstance(item, str): + parts.append(f"- {item}") + elif isinstance(item, dict): + parts.append(_json_to_text(item, depth + 1)) + return "\n".join(parts) + if isinstance(obj, dict): + for key, val in obj.items(): + if isinstance(val, str): + parts.append(val) + elif isinstance(val, list): + parts.append(_json_to_text(val, depth + 1)) + elif isinstance(val, dict): + parts.append(_json_to_text(val, depth + 1)) + return "\n".join(parts) + return str(obj) + + _enhance_logger = logging.getLogger("osint.enhance") @@ -206,17 +230,13 @@ async def enhance_description( result, usage = await call_claude(prompt, tools=None, model=CLAUDE_MODEL_FAST) # call_claude erzwingt bei tools=None JSON-Output — - # Haiku wrapped den Text dann in ein JSON-Objekt + # Haiku wrapped den Text dann in ein JSON-Objekt (oft verschachtelt) text = result.strip() try: import json as _json parsed = _json.loads(text) if isinstance(parsed, dict): - # Erstes String-Feld extrahieren (description, text, content etc.) - for val in parsed.values(): - if isinstance(val, str) and len(val) > 20: - text = val - break + text = _json_to_text(parsed) except (ValueError, TypeError): pass # Kein JSON — text direkt verwenden