cabin-local / src /model-utils.js
fffiloni's picture
Center the project on llama.cpp in CarPlay and switch web and iOS to English
df37169 verified
Raw History Blame Contribute Delete
1.05 kB
export function assertModel(model, size, digest) {
if (size !== model.bytes) throw new Error('The model file is incomplete. Download it again.');
if (digest !== model.sha256) throw new Error('SHA-256 does not match. The file was removed.');
}
export function recentMessages(history, question) {
const system = {role:'system', content:'You are Cabin, a local voice assistant. Answer directly in English in no more than two short sentences, without Markdown. If you do not know, say so. You have no access to the Internet, navigation or vehicle controls. Do not invent real-time information.'};
// Bound prompt growth: keep whole user/assistant pairs, max 1400 characters of history.
const retained = []; let chars = 0;
for (let i = history.length - 2; i >= 0; i -= 2) {
const pair = history.slice(i, i + 2);
const length = pair.reduce((n,m)=>n+m.content.length,0);
if (chars + length > 1400) break;
retained.unshift(...pair); chars += length;
}
return [system, ...retained, {role:'user', content:question.slice(0,500)}];
}