NeonChat v1.0 — Lokaler RP-Chatbot
Features: - FastAPI Backend + Ollama Integration - Character System (JSON-basiert, einfach zu erstellen) - Kurzzeitgedächtnis (SQLite, letzte 20 Nachrichten) - Langzeitgedächtnis (automatische Zusammenfassungen alle 20 Nachrichten) - Moderne Web-UI (dunkles Theme, Neon-Accents) - Character-Erstellungs-Seite im Browser - Beispiel-Character: Mara (Barista, zynisch, warmherzig) - Unzensiert (lokal, keine Cloud) - Gedächtnis-Panel (Ein- und Ausblenden) - Vergessen-Funktion (Gedächtnis löschen)
This commit is contained in:
@@ -0,0 +1,219 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>NeonChat — {{ character.name }}</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
:root {
|
||||
--bg: #0a0a0f; --surface: #15151f; --surface2: #1e1e2e;
|
||||
--border: #252535; --text: #e0e0e8; --muted: #6b6b80;
|
||||
--accent: #8338ec; --accent2: #ff006e; --user: #3a86ff;
|
||||
}
|
||||
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column; }
|
||||
|
||||
/* Header */
|
||||
header { display: flex; align-items: center; gap: 14px; padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
|
||||
.avatar { font-size: 2rem; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; background: var(--surface2); border-radius: 50%; }
|
||||
.char-name { font-size: 1.2rem; font-weight: 600; }
|
||||
.char-desc { font-size: 0.8rem; color: var(--muted); }
|
||||
.header-actions { margin-left: auto; display: flex; gap: 8px; }
|
||||
.btn { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); cursor: pointer; font-size: 0.85rem; transition: all 0.15s; }
|
||||
.btn:hover { border-color: var(--accent); }
|
||||
.btn-danger:hover { border-color: var(--accent2); color: var(--accent2); }
|
||||
|
||||
/* Chat */
|
||||
.chat-container { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
|
||||
.msg { max-width: 75%; padding: 12px 16px; border-radius: 16px; line-height: 1.6; font-size: 0.95rem; white-space: pre-wrap; word-break: break-word; }
|
||||
.msg-user { align-self: flex-end; background: var(--user); color: white; border-bottom-right-radius: 4px; }
|
||||
.msg-bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
|
||||
.msg-system { align-self: center; background: transparent; color: var(--muted); font-size: 0.85rem; font-style: italic; }
|
||||
.msg-greeting { align-self: flex-start; background: var(--surface); border: 1px solid var(--accent); border-bottom-left-radius: 4px; }
|
||||
.typing { align-self: flex-start; color: var(--muted); font-size: 0.9rem; padding: 8px 16px; }
|
||||
.typing::after { content: '●●●'; animation: blink 1.2s infinite; letter-spacing: 3px; }
|
||||
@keyframes blink { 0%,100% { opacity: 0.2; } 50% { opacity: 1; } }
|
||||
|
||||
/* Input */
|
||||
.input-area { padding: 16px 20px; background: var(--surface); border-top: 1px solid var(--border); }
|
||||
.input-row { display: flex; gap: 10px; max-width: 1200px; margin: 0 auto; }
|
||||
textarea { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; color: var(--text); font-size: 0.95rem; font-family: inherit; resize: none; outline: none; transition: border 0.15s; max-height: 120px; }
|
||||
textarea:focus { border-color: var(--accent); }
|
||||
textarea::placeholder { color: var(--muted); }
|
||||
.send-btn { background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; border-radius: 12px; padding: 0 24px; color: white; font-size: 1rem; cursor: pointer; transition: opacity 0.15s; font-weight: 600; }
|
||||
.send-btn:hover { opacity: 0.9; }
|
||||
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
|
||||
/* Memory Panel */
|
||||
.memory-panel { position: fixed; top: 0; right: -400px; width: 380px; height: 100vh; background: var(--surface); border-left: 1px solid var(--border); padding: 20px; overflow-y: auto; transition: right 0.3s; z-index: 100; }
|
||||
.memory-panel.open { right: 0; }
|
||||
.memory-panel h3 { margin-bottom: 12px; font-size: 1rem; color: var(--accent); }
|
||||
.memory-panel h4 { margin: 16px 0 8px; font-size: 0.85rem; color: var(--muted); }
|
||||
.memory-entry { padding: 8px 12px; background: var(--surface2); border-radius: 8px; margin-bottom: 6px; font-size: 0.85rem; line-height: 1.5; }
|
||||
.summary-text { color: var(--text); line-height: 1.6; font-size: 0.85rem; }
|
||||
.memory-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.5); z-index: 99; display: none; }
|
||||
.memory-overlay.show { display: block; }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.msg { max-width: 90%; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<a href="/" style="color: var(--muted); text-decoration: none; font-size: 1.3rem;">←</a>
|
||||
<div class="avatar">{{ character.avatar }}</div>
|
||||
<div>
|
||||
<div class="char-name">{{ character.name }}</div>
|
||||
<div class="char-desc">{{ character.description[:60] }}{% if character.description|length > 60 %}...{% endif %}</div>
|
||||
</div>
|
||||
<div class="header-actions">
|
||||
<button class="btn" onclick="toggleMemory()">🧠 Gedächtnis</button>
|
||||
<button class="btn btn-danger" onclick="clearMemory()">🗑️ Vergessen</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="chat-container" id="chat">
|
||||
{% if character.greeting and not history %}
|
||||
<div class="msg msg-greeting">{{ character.greeting }}</div>
|
||||
{% endif %}
|
||||
{% for h in history %}
|
||||
<div class="msg {{ 'msg-user' if h.role == 'user' else 'msg-bot' }}">{{ h.content }}</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="input-area">
|
||||
<div class="input-row">
|
||||
<textarea id="input" placeholder="Nachricht an {{ character.name }}..." rows="1" onkeydown="handleKey(event)"></textarea>
|
||||
<button class="send-btn" id="send" onclick="sendMessage()">→</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Memory Panel -->
|
||||
<div class="memory-overlay" id="overlay" onclick="toggleMemory()"></div>
|
||||
<div class="memory-panel" id="memoryPanel">
|
||||
<h3>🧠 Gedächtnis — {{ character.name }}</h3>
|
||||
<h4>Langzeit (Zusammenfassungen)</h4>
|
||||
<div id="longTerm">{{ long_term or '<i style="color:var(--muted)">Noch keine Erinnerungen</i>' }}</div>
|
||||
<h4>Kurzzeit (letzte Nachrichten)</h4>
|
||||
<div id="shortTerm">Lädt...</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const charName = "{{ character.name }}";
|
||||
const chat = document.getElementById('chat');
|
||||
const input = document.getElementById('input');
|
||||
const sendBtn = document.getElementById('send');
|
||||
let isSending = false;
|
||||
|
||||
// Auto-scroll
|
||||
chat.scrollTop = chat.scrollHeight;
|
||||
|
||||
// Auto-resize textarea
|
||||
input.addEventListener('input', () => {
|
||||
input.style.height = 'auto';
|
||||
input.style.height = Math.min(input.scrollHeight, 120) + 'px';
|
||||
});
|
||||
|
||||
function handleKey(e) {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
sendMessage();
|
||||
}
|
||||
}
|
||||
|
||||
async function sendMessage() {
|
||||
const msg = input.value.trim();
|
||||
if (!msg || isSending) return;
|
||||
isSending = true;
|
||||
sendBtn.disabled = true;
|
||||
|
||||
// User message
|
||||
const userDiv = document.createElement('div');
|
||||
userDiv.className = 'msg msg-user';
|
||||
userDiv.textContent = msg;
|
||||
chat.appendChild(userDiv);
|
||||
input.value = '';
|
||||
input.style.height = 'auto';
|
||||
chat.scrollTop = chat.scrollHeight;
|
||||
|
||||
// Typing indicator
|
||||
const typing = document.createElement('div');
|
||||
typing.className = 'typing';
|
||||
typing.textContent = '';
|
||||
chat.appendChild(typing);
|
||||
|
||||
try {
|
||||
const resp = await fetch(`/api/chat/${encodeURIComponent(charName)}`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({message: msg})
|
||||
});
|
||||
const data = await resp.json();
|
||||
typing.remove();
|
||||
const botDiv = document.createElement('div');
|
||||
botDiv.className = 'msg msg-bot';
|
||||
botDiv.textContent = data.response;
|
||||
chat.appendChild(botDiv);
|
||||
chat.scrollTop = chat.scrollHeight;
|
||||
} catch(e) {
|
||||
typing.remove();
|
||||
const errDiv = document.createElement('div');
|
||||
errDiv.className = 'msg msg-system';
|
||||
errDiv.textContent = '⚠️ Verbindungsfehler';
|
||||
chat.appendChild(errDiv);
|
||||
}
|
||||
|
||||
isSending = false;
|
||||
sendBtn.disabled = false;
|
||||
input.focus();
|
||||
}
|
||||
|
||||
function toggleMemory() {
|
||||
const panel = document.getElementById('memoryPanel');
|
||||
const overlay = document.getElementById('overlay');
|
||||
if (panel.classList.contains('open')) {
|
||||
panel.classList.remove('open');
|
||||
overlay.classList.remove('show');
|
||||
} else {
|
||||
panel.classList.add('open');
|
||||
overlay.classList.add('show');
|
||||
loadMemory();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMemory() {
|
||||
try {
|
||||
const resp = await fetch(`/api/memory/${encodeURIComponent(charName)}`);
|
||||
const data = await resp.json();
|
||||
const shortDiv = document.getElementById('shortTerm');
|
||||
shortDiv.innerHTML = '';
|
||||
if (data.short_term && data.short_term.length > 0) {
|
||||
data.short_term.forEach(m => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'memory-entry';
|
||||
div.textContent = `${m.role === 'user' ? 'Du' : charName}: ${m.content}`;
|
||||
shortDiv.appendChild(div);
|
||||
});
|
||||
} else {
|
||||
shortDiv.innerHTML = '<i style="color:var(--muted)">Keine aktuellen Nachrichten</i>';
|
||||
}
|
||||
} catch(e) {
|
||||
document.getElementById('shortTerm').textContent = 'Fehler beim Laden';
|
||||
}
|
||||
}
|
||||
|
||||
async function clearMemory() {
|
||||
if (!confirm(`Gedächtnis von ${charName} wirklich löschen?`)) return;
|
||||
await fetch(`/api/memory/clear/${encodeURIComponent(charName)}`, {method: 'POST'});
|
||||
chat.innerHTML = '';
|
||||
if ("{{ character.greeting }}") {
|
||||
const g = document.createElement('div');
|
||||
g.className = 'msg msg-greeting';
|
||||
g.textContent = "{{ character.greeting }}";
|
||||
chat.appendChild(g);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user