fix: память только в браузере, сервер ничего не хранит
This commit is contained in:
+7
-6
@@ -52,7 +52,7 @@
|
||||
|
||||
let mediaRecorder, chunks = [], userBlob = null;
|
||||
let isRecording = false, micAnalyser = null, micAnimId = null;
|
||||
let audioContext = null, sessionSid = null;
|
||||
let audioContext = null, chatHistory = [];
|
||||
let thinkStart = 0, thinkTimer = null;
|
||||
|
||||
// История — массив {q, a, time}
|
||||
@@ -191,13 +191,15 @@
|
||||
const cRes = await fetch('/api/chat', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ model: 'gpt-oss-120b', message: text, sid: sessionSid }),
|
||||
body: JSON.stringify({ model: 'gpt-oss-120b', message: text, history: chatHistory }),
|
||||
signal: (() => { const a = new AbortController(); setTimeout(() => a.abort(), 120000); return a.signal; })(),
|
||||
});
|
||||
stopThinkTimer();
|
||||
const cData = await cRes.json();
|
||||
if (cData.sid) sessionSid = cData.sid;
|
||||
const resp = cData.response || cData.error || 'Ошибка';
|
||||
chatHistory.push({ role: 'user', content: text });
|
||||
chatHistory.push({ role: 'assistant', content: resp });
|
||||
if (chatHistory.length > 40) chatHistory = chatHistory.slice(-40);
|
||||
chat.innerHTML += '<div class="bot">🤖 ' + fmt(resp) + '</div>';
|
||||
chat.scrollTop = chat.scrollHeight;
|
||||
setStatus('✅ Готово — ' + ((Date.now() - thinkStart) / 1000).toFixed(1) + 'с');
|
||||
@@ -223,9 +225,8 @@
|
||||
}
|
||||
function stopThinkTimer() { if (thinkTimer) { clearInterval(thinkTimer); thinkTimer = null; } }
|
||||
|
||||
document.getElementById('btnReset').onclick = async () => {
|
||||
await fetch('/api/reset', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sid: sessionSid }) });
|
||||
sessionSid = null; chat.innerHTML = ''; setStatus('🧹 Очищено');
|
||||
document.getElementById('btnReset').onclick = () => {
|
||||
chatHistory = []; chat.innerHTML = ''; setStatus('🧹 Очищено');
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user