brsh 3.3.1 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/Readme.md +2 -2
- package/dist/wbt.es.js +133 -115
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +3 -3
- package/dist/wbt.min.js.map +1 -1
- package/lib/wbt/packages/wllama.js +34 -5
- package/package.json +1 -1
- package/test/wbt.test.js +34 -1
|
@@ -4,7 +4,29 @@ const Command = require('../../Command');
|
|
|
4
4
|
const ReplCommand = require('../../ReplCommand');
|
|
5
5
|
const { readBytesFromFs, writeBytesToFs, loadModule } = require('../utils');
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Pre-configured friendly aliases for lightweight instruct models compatible with Wllama in-browser runtime.
|
|
9
|
+
*/
|
|
10
|
+
const MODEL_ALIASES = {
|
|
11
|
+
smol: 'https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf',
|
|
12
|
+
smollm: 'https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf',
|
|
13
|
+
smollm2: 'https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf',
|
|
14
|
+
'smol-135m': 'https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf',
|
|
15
|
+
'smol-360m': 'https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf',
|
|
16
|
+
'smollm-360m': 'https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf',
|
|
17
|
+
'smollm2-360m': 'https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf',
|
|
18
|
+
'smol-1.7b': 'https://huggingface.co/bartowski/SmolLM2-1.7B-Instruct-GGUF/resolve/main/SmolLM2-1.7B-Instruct-Q4_K_M.gguf',
|
|
19
|
+
qwen: 'https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf',
|
|
20
|
+
'qwen2.5': 'https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf',
|
|
21
|
+
'qwen-0.5b': 'https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf',
|
|
22
|
+
'qwen2.5-0.5b': 'https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf',
|
|
23
|
+
'qwen-1.5b': 'https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct-GGUF/resolve/main/qwen2.5-1.5b-instruct-q4_k_m.gguf',
|
|
24
|
+
'qwen2.5-1.5b': 'https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct-GGUF/resolve/main/qwen2.5-1.5b-instruct-q4_k_m.gguf',
|
|
25
|
+
stories: 'https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf',
|
|
26
|
+
stories15m: 'https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories15M.gguf'
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const DEFAULT_MODEL_URL = MODEL_ALIASES.smol;
|
|
8
30
|
const DEFAULT_WASM_URL = 'https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/src/wasm/wllama.wasm';
|
|
9
31
|
const DEFAULT_PERSIST_DIR = '/var/cache/wllama';
|
|
10
32
|
|
|
@@ -77,7 +99,7 @@ function resolveModelSpec(rawSpec, hfRepo = null, hfFile = null, hfQuant = null)
|
|
|
77
99
|
};
|
|
78
100
|
}
|
|
79
101
|
|
|
80
|
-
|
|
102
|
+
let spec = (rawSpec || '').trim();
|
|
81
103
|
if (!spec) {
|
|
82
104
|
return {
|
|
83
105
|
kind: 'url',
|
|
@@ -86,6 +108,11 @@ function resolveModelSpec(rawSpec, hfRepo = null, hfFile = null, hfQuant = null)
|
|
|
86
108
|
};
|
|
87
109
|
}
|
|
88
110
|
|
|
111
|
+
const lower = spec.toLowerCase();
|
|
112
|
+
if (MODEL_ALIASES[lower]) {
|
|
113
|
+
spec = MODEL_ALIASES[lower];
|
|
114
|
+
}
|
|
115
|
+
|
|
89
116
|
if (/^hf:\/\//i.test(spec) || /^hf:/i.test(spec)) {
|
|
90
117
|
const stripped = spec.replace(/^hf:(\/\/)?/i, '');
|
|
91
118
|
// Support `hf:owner/repo:Q4_K_M`
|
|
@@ -649,8 +676,8 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
649
676
|
}
|
|
650
677
|
|
|
651
678
|
if (positional.length > 0) {
|
|
652
|
-
// If no `-m` model was provided and first positional token looks like
|
|
653
|
-
if (!model && !hfRepo && (subcommand === 'pull' || /\.gguf(\?.*)?$/i.test(positional[0]) || /^hf:/i.test(positional[0]) || /^https?:\/\//i.test(positional[0]))) {
|
|
679
|
+
// If no `-m` model was provided and first positional token looks like an alias, .gguf path, URL, or hf spec (or subcommand is pull)
|
|
680
|
+
if (!model && !hfRepo && (subcommand === 'pull' || MODEL_ALIASES[positional[0].toLowerCase()] || /\.gguf(\?.*)?$/i.test(positional[0]) || /^hf:/i.test(positional[0]) || /^https?:\/\//i.test(positional[0]))) {
|
|
654
681
|
model = positional.shift();
|
|
655
682
|
}
|
|
656
683
|
if (subcommand === 'pull' && positional.length > 0 && !persistPath) {
|
|
@@ -1117,7 +1144,7 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1117
1144
|
' wllama bench Run ggml WebGPU/CPU backend ops test',
|
|
1118
1145
|
'',
|
|
1119
1146
|
'Options:',
|
|
1120
|
-
' -m, --model=MODEL Path in brsh
|
|
1147
|
+
' -m, --model=MODEL Path in brsh fs, URL, HF spec, or alias (default: smol [SmolLM2-135M]; also: qwen)',
|
|
1121
1148
|
' --hf=REPO Hugging Face model repository (e.g. Qwen/Qwen2.5-0.5B-Instruct-GGUF)',
|
|
1122
1149
|
' --quant=QUANT Hugging Face GGUF quantization (default: Q4_K_M)',
|
|
1123
1150
|
' --persist[=PATH] Persist pulled remote model into brsh filesystem (default: /var/cache/wllama/)',
|
|
@@ -1284,3 +1311,5 @@ module.exports.getDefaultPersistPath = getDefaultPersistPath;
|
|
|
1284
1311
|
module.exports.DEFAULT_PERSIST_DIR = DEFAULT_PERSIST_DIR;
|
|
1285
1312
|
module.exports.resolveModelSpec = resolveModelSpec;
|
|
1286
1313
|
module.exports.formatDownloadProgress = formatDownloadProgress;
|
|
1314
|
+
module.exports.DEFAULT_MODEL_URL = DEFAULT_MODEL_URL;
|
|
1315
|
+
module.exports.MODEL_ALIASES = MODEL_ALIASES;
|
package/package.json
CHANGED
package/test/wbt.test.js
CHANGED
|
@@ -6,7 +6,7 @@ const require = createRequire(import.meta.url);
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const Wbt = require('../lib/wbt/index.js');
|
|
9
|
-
const { wllamaInstances } = require('../lib/wbt/packages/wllama.js');
|
|
9
|
+
const { wllamaInstances, DEFAULT_MODEL_URL, MODEL_ALIASES, resolveModelSpec } = require('../lib/wbt/packages/wllama.js');
|
|
10
10
|
|
|
11
11
|
const NANO_WASM_PATH = path.resolve(import.meta.dirname, '../../nano-wasm/dist/nano.wasm');
|
|
12
12
|
const NANO_WASM_BYTES = (() => {
|
|
@@ -1294,6 +1294,39 @@ describe('WBT Wllama v3 WASM & WebGPU package (`wllama`, `llama`, `llama-cli`)',
|
|
|
1294
1294
|
expect(modelsRes.output.join('\n')).toContain('/var/cache/wllama/Qwen2.5-0.5B-Instruct-GGUF-Q4_K_M.gguf');
|
|
1295
1295
|
expect(modelsRes.output.join('\n')).toContain('persisted (fs)');
|
|
1296
1296
|
});
|
|
1297
|
+
|
|
1298
|
+
it('defaults to SmolLM2 model and supports friendly model aliases like smol and qwen', async () => {
|
|
1299
|
+
// Verify default model URL is SmolLM2-135M rather than stories
|
|
1300
|
+
expect(DEFAULT_MODEL_URL).toContain('SmolLM2-135M-Instruct');
|
|
1301
|
+
expect(DEFAULT_MODEL_URL).not.toContain('stories');
|
|
1302
|
+
|
|
1303
|
+
// Verify resolveModelSpec helper maps empty input to SmolLM2 default
|
|
1304
|
+
const defaultSpec = resolveModelSpec();
|
|
1305
|
+
expect(defaultSpec.url).toBe(DEFAULT_MODEL_URL);
|
|
1306
|
+
expect(defaultSpec.url).toContain('SmolLM2-135M-Instruct-Q4_K_M.gguf');
|
|
1307
|
+
|
|
1308
|
+
// Verify smol and qwen aliases
|
|
1309
|
+
const smolSpec = resolveModelSpec('smol');
|
|
1310
|
+
expect(smolSpec.url).toBe(MODEL_ALIASES.smol);
|
|
1311
|
+
const qwenSpec = resolveModelSpec('qwen');
|
|
1312
|
+
expect(qwenSpec.url).toBe(MODEL_ALIASES.qwen);
|
|
1313
|
+
expect(qwenSpec.url).toContain('qwen2.5-0.5b-instruct-q4_k_m.gguf');
|
|
1314
|
+
|
|
1315
|
+
// Run wllama with no -m flag (uses default SmolLM2 model)
|
|
1316
|
+
const defaultRes = await run(shell, 'wllama -p "Default model prompt"');
|
|
1317
|
+
expect(defaultRes.exitCode).toBe(0);
|
|
1318
|
+
expect(defaultRes.output.join('\n')).toContain('Reply(WebGPU,turns=1): Default model prompt');
|
|
1319
|
+
|
|
1320
|
+
// Run wllama pull using alias 'qwen'
|
|
1321
|
+
const pullQwenRes = await run(shell, 'wllama pull qwen -q');
|
|
1322
|
+
expect(pullQwenRes.exitCode).toBe(0);
|
|
1323
|
+
expect(shell.context.fs.exists('/var/cache/wllama/qwen2.5-0.5b-instruct-q4_k_m.gguf')).toBe(true);
|
|
1324
|
+
|
|
1325
|
+
// Run wllama using alias 'qwen' with -m
|
|
1326
|
+
const qwenRes = await run(shell, 'wllama -m qwen -p "Hello Qwen"');
|
|
1327
|
+
expect(qwenRes.exitCode).toBe(0);
|
|
1328
|
+
expect(qwenRes.output.join('\n')).toContain('Reply(WebGPU,turns=1): Hello Qwen');
|
|
1329
|
+
});
|
|
1297
1330
|
});
|
|
1298
1331
|
|
|
1299
1332
|
describe('WBT GNU nano WASM package (nano / nano-wasm)', () => {
|