v2.5.1 — Chat-Verlauf bleibt beim Reload erhalten
- loadHistory() leert Chat nicht mehr (chat.innerHTML = '' entfernt) - Nur fehlende Nachrichten werden angehängt, bestehende bleiben - Cookie mit path=/ für konsistente Session über alle Routen - cowboy shot statt upper body (besserer Danbooru-Tag für NoobAI-XL) - very aesthetic, absurdres als Quality-Tags
This commit is contained in:
@@ -181,9 +181,9 @@ def build_prompt_from_appearance(character: dict, context: str = "") -> str:
|
||||
result = result.replace(de, en)
|
||||
return result
|
||||
|
||||
# Build prompt
|
||||
# Build prompt — use established Danbooru tags for NoobAI-XL
|
||||
parts = [
|
||||
f"upper body, {style_prefix}{gender_tag}",
|
||||
f"cowboy shot, {style_prefix}{gender_tag.strip()}",
|
||||
f"{age} years old",
|
||||
]
|
||||
if build:
|
||||
@@ -206,7 +206,7 @@ def build_prompt_from_appearance(character: dict, context: str = "") -> str:
|
||||
parts.append(context)
|
||||
|
||||
prompt = ", ".join(parts)
|
||||
prompt += ", looking at viewer, detailed face, high quality, masterpiece, best quality, simple background"
|
||||
prompt += ", looking at viewer, detailed face, masterpiece, best quality, very aesthetic, absurdres"
|
||||
|
||||
return prompt
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ templates = Jinja2Templates(directory=str(BASE_DIR / "templates"))
|
||||
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
|
||||
|
||||
def set_session_cookie(response, sid: str):
|
||||
response.set_cookie(SESSION_COOKIE_NAME, sid, max_age=SESSION_DURATION, httponly=False, samesite="lax")
|
||||
response.set_cookie(SESSION_COOKIE_NAME, sid, max_age=SESSION_DURATION, httponly=False, samesite="lax", path="/")
|
||||
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request, session_id: str = Cookie(None, alias=SESSION_COOKIE_NAME)):
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 971 KiB |
+10
-15
@@ -258,28 +258,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Load history on reconnect (fixes the "conversation is somewhere else" bug)
|
||||
// Load history on reconnect — preserves existing messages
|
||||
async function loadHistory() {
|
||||
try {
|
||||
const resp = await fetch(`/api/history/${encodeURIComponent(charFilename)}`);
|
||||
const data = await resp.json();
|
||||
if (data.history && data.history.length > 0) {
|
||||
// Only reload if we have more messages than currently shown
|
||||
const currentMsgs = chat.querySelectorAll('.msg').length;
|
||||
if (data.history.length > currentMsgs || currentMsgs === 0) {
|
||||
chat.innerHTML = '';
|
||||
if ("{{ character.greeting }}") {
|
||||
const g = document.createElement('div');
|
||||
g.className = 'msg msg-greeting';
|
||||
g.textContent = "{{ character.greeting }}";
|
||||
chat.appendChild(g);
|
||||
}
|
||||
data.history.forEach(h => {
|
||||
// Count current messages (exclude greeting)
|
||||
const currentMsgs = chat.querySelectorAll('.msg-user, .msg-bot').length;
|
||||
// Only append messages we don't already have
|
||||
if (data.history.length > currentMsgs) {
|
||||
// Keep existing DOM, only append missing messages
|
||||
for (let i = currentMsgs; i < data.history.length; i++) {
|
||||
const h = data.history[i];
|
||||
const div = document.createElement('div');
|
||||
div.className = `msg ${h.role === 'user' ? 'msg-user' : 'msg-bot'}`;
|
||||
div.textContent = h.content;
|
||||
chat.appendChild(div);
|
||||
});
|
||||
}
|
||||
chat.scrollTop = chat.scrollHeight;
|
||||
}
|
||||
}
|
||||
@@ -288,8 +284,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Load history on page load (fixes reconnect issue)
|
||||
// Only if we don't already have history from server-side rendering
|
||||
// Load history on page load ONLY if server didn't render any
|
||||
{% if not history %}
|
||||
loadHistory();
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user