fix(backend): give the model its history back and its identity

Asked what the first message of the conversation was, the assistant answered
that it keeps no memory between interactions while the replayed context sat
right in front of it. Two causes, both measured on the real model. The system
prompt never said the history is its memory, nor who it is, so it fell back on
its training habit of denying recall. And Ollama's default context window
silently truncates from the beginning: on a 9194-token conversation only 4053
tokens were evaluated, so the oldest messages never reached the model at all.
The window is now requested explicitly (16384 by default) and the warm-up asks
for the same one, otherwise Ollama reloads the weights and throws the preheat
away. The prompt states the identity and forbids the false denial, while still
letting the assistant admit a message older than the replayed window.
This commit is contained in:
BlackAngelTV committed 2026-10-06 20:23:51 +02:00
1 parent 9226500a56
commit 9808b38198
5 files changed
+86 -2

No files matched your search

+46
View File
@@ -143,6 +143,25 @@ describe('streaming over SSE', () => {
);
});
// A weak model answers « je n'ai pas de mémoire » without being told what the
// replayed history is and who it is.
it('tells the model who it is and that the history is its memory', async () => {
const seen = srv.mock.requests.length;
const res = await fetch(`${srv.base}/api/chat/stream`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${user.token}` },
body: JSON.stringify({ message: 'Qui es-tu ?' }),
});
await readSse(res);
const system = lastMessagesSent(seen)[0];
assert.equal(system.role, 'system');
assert.match(system.content, /BlackAngelTV/, 'the identity must be stated');
assert.match(system.content, /historique .* mémoire/i, 'the history is the memory');
assert.match(system.content, /messages les plus anciens/, 'old turns count too');
assert.match(system.content, /jamais que tu n'as pas de mémoire/, 'no false denial');
});
it('stateless stream: works', async () => {
const res = await fetch(`${srv.base}/api/chat/stream`, {
method: 'POST',
@@ -157,6 +176,33 @@ describe('streaming over SSE', () => {
});
});
describe('system prompt override', () => {
let srv;
let user;
before(async () => {
srv = await startServer({ systemPrompt: 'Tu es un modèle de test.' });
user = await registerUser(srv.base, 'prompt@x.io');
});
after(async () => {
await srv.close();
});
it('JARVIS_SYSTEM_PROMPT replaces the built-in identity', async () => {
const res = await fetch(`${srv.base}/api/chat/stream`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${user.token}` },
body: JSON.stringify({ message: 'Bonjour' }),
});
await readSse(res);
const system = srv.mock.requests.at(-1).payload.messages[0];
assert.equal(system.content, 'Tu es un modèle de test.');
assert.doesNotMatch(system.content, /BlackAngelTV/);
});
});
describe('POST /api/chat (spec SSE contract)', () => {
let srv;
let user;