v2.5.4 — Portrait-Bilder bleiben beim Reload erhalten
- Portrait wird als [PORTRAIT]path[/PORTRAIT] in DB gespeichert - Serverseitiges Jinja2-Rendering zeigt Bild beim Reload - JS loadHistory() rendert PORTRAIT-Marker als <img> - Ollama bekommt keine PORTRAIT-Nachrichten (skip in build_prompt)
This commit is contained in:
@@ -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"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user