Spaces:
Running on Zero
Running on Zero
Download src/model-utils.js from fffiloni/cabin-local: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/fffiloni/cabin-local/resolve/main/src/model-utils.js
- Command line
-
hf download hf://spaces/fffiloni/cabin-local/src/model-utils.js
-
curl -L -o model-utils.js https://huggingface.co/spaces/fffiloni/cabin-local/resolve/main/src/model-utils.js
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)}]; | |
| } | |