diff --git a/main.py b/main.py index 8bd9ed6..2f538e2 100644 --- a/main.py +++ b/main.py @@ -163,6 +163,11 @@ def save_message(session_id: str, character: str, role: str, content: str): conn.commit() conn.close() +def save_portrait_message(session_id: str, character: str, image_path: str): + """Speichert ein generiertes Portrait als Bot-Nachricht mit Bild-Marker.""" + content = f"[PORTRAIT]{image_path}[/PORTRAIT]" + save_message(session_id, character, "assistant", content) + def needs_summary(session_id: str, character: str) -> bool: conn = sqlite3.connect(str(DB_PATH)) cur = conn.execute( @@ -268,6 +273,9 @@ REGELN: messages = [{"role": "system", "content": system}] for msg in short_term: + # Skip portrait messages — they're images, not text for the LLM + if msg["content"] and msg["content"].startswith("[PORTRAIT]"): + continue if msg["role"] == "user": messages.append({"role": "user", "content": msg["content"]}) else: @@ -572,6 +580,11 @@ async def api_generate_portrait(name: str, request: Request): image_path = generate_portrait(name, char, custom_prompt) if image_path: _portrait_jobs[job_id] = {"status": "done", "image": image_path, "error": None} + # Save portrait to chat history so it survives reload + try: + save_portrait_message(session_id, name, image_path) + except Exception as e: + print(f"Portrait save failed (non-fatal): {e}") else: _portrait_jobs[job_id] = {"status": "error", "image": None, "error": "Generierung fehlgeschlagen"} diff --git a/static/avatars/mara.png b/static/avatars/mara.png index 0c9d6b6..58a1277 100644 Binary files a/static/avatars/mara.png and b/static/avatars/mara.png differ diff --git a/templates/chat.html b/templates/chat.html index ebd949a..bcf0543 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -82,7 +82,14 @@