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)
|
result = result.replace(de, en)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Build prompt
|
# Build prompt — use established Danbooru tags for NoobAI-XL
|
||||||
parts = [
|
parts = [
|
||||||
f"upper body, {style_prefix}{gender_tag}",
|
f"cowboy shot, {style_prefix}{gender_tag.strip()}",
|
||||||
f"{age} years old",
|
f"{age} years old",
|
||||||
]
|
]
|
||||||
if build:
|
if build:
|
||||||
@@ -206,7 +206,7 @@ def build_prompt_from_appearance(character: dict, context: str = "") -> str:
|
|||||||
parts.append(context)
|
parts.append(context)
|
||||||
|
|
||||||
prompt = ", ".join(parts)
|
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
|
return prompt
|
||||||
|
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ templates = Jinja2Templates(directory=str(BASE_DIR / "templates"))
|
|||||||
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
|
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
|
||||||
|
|
||||||
def set_session_cookie(response, sid: str):
|
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)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
async def index(request: Request, session_id: str = Cookie(None, alias=SESSION_COOKIE_NAME)):
|
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() {
|
async function loadHistory() {
|
||||||
try {
|
try {
|
||||||
const resp = await fetch(`/api/history/${encodeURIComponent(charFilename)}`);
|
const resp = await fetch(`/api/history/${encodeURIComponent(charFilename)}`);
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (data.history && data.history.length > 0) {
|
if (data.history && data.history.length > 0) {
|
||||||
// Only reload if we have more messages than currently shown
|
// Count current messages (exclude greeting)
|
||||||
const currentMsgs = chat.querySelectorAll('.msg').length;
|
const currentMsgs = chat.querySelectorAll('.msg-user, .msg-bot').length;
|
||||||
if (data.history.length > currentMsgs || currentMsgs === 0) {
|
// Only append messages we don't already have
|
||||||
chat.innerHTML = '';
|
if (data.history.length > currentMsgs) {
|
||||||
if ("{{ character.greeting }}") {
|
// Keep existing DOM, only append missing messages
|
||||||
const g = document.createElement('div');
|
for (let i = currentMsgs; i < data.history.length; i++) {
|
||||||
g.className = 'msg msg-greeting';
|
const h = data.history[i];
|
||||||
g.textContent = "{{ character.greeting }}";
|
|
||||||
chat.appendChild(g);
|
|
||||||
}
|
|
||||||
data.history.forEach(h => {
|
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
div.className = `msg ${h.role === 'user' ? 'msg-user' : 'msg-bot'}`;
|
div.className = `msg ${h.role === 'user' ? 'msg-user' : 'msg-bot'}`;
|
||||||
div.textContent = h.content;
|
div.textContent = h.content;
|
||||||
chat.appendChild(div);
|
chat.appendChild(div);
|
||||||
});
|
}
|
||||||
chat.scrollTop = chat.scrollHeight;
|
chat.scrollTop = chat.scrollHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,8 +284,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load history on page load (fixes reconnect issue)
|
// Load history on page load ONLY if server didn't render any
|
||||||
// Only if we don't already have history from server-side rendering
|
|
||||||
{% if not history %}
|
{% if not history %}
|
||||||
loadHistory();
|
loadHistory();
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user