brsh 3.10.4 → 3.10.5
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/dist/wbt.es.js +27 -25
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +2 -2
- package/dist/wbt.min.js.map +1 -1
- package/lib/wbt/packages/wllama.js +13 -14
- package/package.json +1 -1
- package/test/wbt.test.js +17 -0
|
@@ -185,9 +185,10 @@ class ProgressTracker {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
clear() {
|
|
188
|
+
const wasActive = this.active;
|
|
188
189
|
this.stopTimer();
|
|
189
190
|
this.active = false;
|
|
190
|
-
if (this.enabled && typeof this.onRender === 'function') {
|
|
191
|
+
if (wasActive && this.enabled && typeof this.onRender === 'function') {
|
|
191
192
|
this.onRender('');
|
|
192
193
|
}
|
|
193
194
|
}
|
|
@@ -1176,6 +1177,7 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1176
1177
|
|
|
1177
1178
|
const tracker = this._createTracker();
|
|
1178
1179
|
tracker.start('Running inference', { hint: 'evaluating prompt & preparing KV cache' });
|
|
1180
|
+
let firstToken = false;
|
|
1179
1181
|
|
|
1180
1182
|
try {
|
|
1181
1183
|
if (typeof this._wllama.createChatCompletion === 'function') {
|
|
@@ -1183,7 +1185,6 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1183
1185
|
|
|
1184
1186
|
if (res && typeof res[Symbol.asyncIterator] === 'function') {
|
|
1185
1187
|
let fullText = '';
|
|
1186
|
-
let firstToken = false;
|
|
1187
1188
|
for await (const chunk of res) {
|
|
1188
1189
|
const delta = chunk?.choices?.[0]?.delta?.content ?? chunk?.choices?.[0]?.text ?? '';
|
|
1189
1190
|
if (delta) {
|
|
@@ -1193,8 +1194,6 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1193
1194
|
if (this.interactive) {
|
|
1194
1195
|
this._replStatus = 'Streaming tokens...';
|
|
1195
1196
|
this._renderRepl();
|
|
1196
|
-
} else {
|
|
1197
|
-
this._clearStatus();
|
|
1198
1197
|
}
|
|
1199
1198
|
}
|
|
1200
1199
|
fullText += delta;
|
|
@@ -1204,7 +1203,7 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1204
1203
|
}
|
|
1205
1204
|
}
|
|
1206
1205
|
tracker.clear();
|
|
1207
|
-
if (!this.interactive) {
|
|
1206
|
+
if (!this.interactive && !firstToken) {
|
|
1208
1207
|
this._clearStatus();
|
|
1209
1208
|
}
|
|
1210
1209
|
return fullText;
|
|
@@ -1236,7 +1235,6 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1236
1235
|
const res = await this._wllama.createCompletion(compOpts);
|
|
1237
1236
|
if (res && typeof res[Symbol.asyncIterator] === 'function') {
|
|
1238
1237
|
let fullText = '';
|
|
1239
|
-
let firstToken = false;
|
|
1240
1238
|
for await (const chunk of res) {
|
|
1241
1239
|
const delta = chunk?.choices?.[0]?.text ?? chunk?.choices?.[0]?.delta?.content ?? '';
|
|
1242
1240
|
if (delta) {
|
|
@@ -1246,8 +1244,6 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1246
1244
|
if (this.interactive) {
|
|
1247
1245
|
this._replStatus = 'Streaming tokens...';
|
|
1248
1246
|
this._renderRepl();
|
|
1249
|
-
} else {
|
|
1250
|
-
this._clearStatus();
|
|
1251
1247
|
}
|
|
1252
1248
|
}
|
|
1253
1249
|
fullText += delta;
|
|
@@ -1257,7 +1253,7 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1257
1253
|
}
|
|
1258
1254
|
}
|
|
1259
1255
|
tracker.clear();
|
|
1260
|
-
if (!this.interactive) {
|
|
1256
|
+
if (!this.interactive && !firstToken) {
|
|
1261
1257
|
this._clearStatus();
|
|
1262
1258
|
}
|
|
1263
1259
|
return fullText;
|
|
@@ -1275,7 +1271,7 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1275
1271
|
return text;
|
|
1276
1272
|
} finally {
|
|
1277
1273
|
tracker.clear();
|
|
1278
|
-
if (!this.interactive) {
|
|
1274
|
+
if (!this.interactive && !firstToken) {
|
|
1279
1275
|
this._clearStatus();
|
|
1280
1276
|
}
|
|
1281
1277
|
}
|
|
@@ -1497,11 +1493,11 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1497
1493
|
|
|
1498
1494
|
const tracker = this._createTracker();
|
|
1499
1495
|
tracker.start('Running inference', { hint: 'evaluating prompt & preparing KV cache' });
|
|
1496
|
+
let streamedAny = false;
|
|
1500
1497
|
try {
|
|
1501
1498
|
const res = await this._wllama.createCompletion(compOpts);
|
|
1502
1499
|
let outText = '';
|
|
1503
1500
|
if (res && typeof res[Symbol.asyncIterator] === 'function') {
|
|
1504
|
-
let streamedAny = false;
|
|
1505
1501
|
for await (const chunk of res) {
|
|
1506
1502
|
const delta = chunk?.choices?.[0]?.text ?? chunk?.choices?.[0]?.delta?.content ?? '';
|
|
1507
1503
|
if (delta) {
|
|
@@ -1509,7 +1505,6 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1509
1505
|
streamedAny = true;
|
|
1510
1506
|
this._streamedStdout = true;
|
|
1511
1507
|
tracker.clear();
|
|
1512
|
-
this._clearStatus();
|
|
1513
1508
|
}
|
|
1514
1509
|
outText += delta;
|
|
1515
1510
|
if (this.stdout && typeof this.stdout.write === 'function') {
|
|
@@ -1519,7 +1514,9 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1519
1514
|
}
|
|
1520
1515
|
}
|
|
1521
1516
|
tracker.clear();
|
|
1522
|
-
|
|
1517
|
+
if (!streamedAny) {
|
|
1518
|
+
this._clearStatus();
|
|
1519
|
+
}
|
|
1523
1520
|
if (streamedAny && outText.length > 0 && !outText.endsWith('\n') && this.stdout && typeof this.stdout.write === 'function') {
|
|
1524
1521
|
this.stdout.write('\r\n');
|
|
1525
1522
|
}
|
|
@@ -1532,7 +1529,9 @@ function createWllamaCommand(pkgMeta = {}, wbtConfig = {}, binName = 'wllama') {
|
|
|
1532
1529
|
return;
|
|
1533
1530
|
} finally {
|
|
1534
1531
|
tracker.clear();
|
|
1535
|
-
|
|
1532
|
+
if (!streamedAny) {
|
|
1533
|
+
this._clearStatus();
|
|
1534
|
+
}
|
|
1536
1535
|
}
|
|
1537
1536
|
}
|
|
1538
1537
|
|
package/package.json
CHANGED
package/test/wbt.test.js
CHANGED
|
@@ -1276,6 +1276,23 @@ describe('WBT Wllama v3 WASM & WebGPU package (`wllama`, `llama`, `llama-cli`)',
|
|
|
1276
1276
|
expect(combinedStatus).toContain('Loading model (tinyllama.gguf) weights');
|
|
1277
1277
|
expect(combinedStatus).toContain('Running inference');
|
|
1278
1278
|
expect(combinedStatus).toMatch(/\[.*\]/);
|
|
1279
|
+
|
|
1280
|
+
// Ensure status clearing (\r\x1b[K) never fires after tokens start streaming to stdout
|
|
1281
|
+
for (const cmd of ['wllama -m /home/tinyllama.gguf -p "No clobber"', 'wllama -m /home/tinyllama.gguf --raw -p "Raw no clobber"']) {
|
|
1282
|
+
const timeline = [];
|
|
1283
|
+
const onTok = (t) => timeline.push({ stream: 'token', data: String(t) });
|
|
1284
|
+
const onErr = (c) => timeline.push({ stream: 'err', data: String(c) });
|
|
1285
|
+
shell.on('token', onTok);
|
|
1286
|
+
shell.stderr.on('data', onErr);
|
|
1287
|
+
await run(shell, cmd);
|
|
1288
|
+
shell.removeListener('token', onTok);
|
|
1289
|
+
shell.stderr.removeListener('data', onErr);
|
|
1290
|
+
|
|
1291
|
+
const firstTokenIdx = timeline.findIndex(e => e.stream === 'token');
|
|
1292
|
+
expect(firstTokenIdx).toBeGreaterThanOrEqual(0);
|
|
1293
|
+
const errAfterFirstToken = timeline.slice(firstTokenIdx + 1).filter(e => e.stream === 'err' && e.data.includes('\x1b[K'));
|
|
1294
|
+
expect(errAfterFirstToken).toEqual([]);
|
|
1295
|
+
}
|
|
1279
1296
|
});
|
|
1280
1297
|
|
|
1281
1298
|
it('supports Hugging Face model loading (--hf / hf:), embeddings (wllama embed), info, and bench', async () => {
|