@nevescloud/pip 3.9.0 → 3.9.1
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/package.json +1 -1
- package/providers/local.esm.js +20 -1
package/package.json
CHANGED
package/providers/local.esm.js
CHANGED
|
@@ -257,9 +257,21 @@ export function createTransformersRenderer() {
|
|
|
257
257
|
return splitThinking(buffer).answer || buffer.trim();
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
// Background warm — starts the transformers.js import + tokenizer +
|
|
261
|
+
// model download without running inference. Hosts call this from
|
|
262
|
+
// requestIdleCallback after their page boots so the first user prompt
|
|
263
|
+
// doesn't pay the cold-start cost. Safe to call repeatedly; ensureLoaded
|
|
264
|
+
// is internally idempotent (returns the in-flight loadingPromise).
|
|
265
|
+
async function warm(turnEl) {
|
|
266
|
+
if (!config?.id) return;
|
|
267
|
+
try { await ensureLoaded(turnEl); }
|
|
268
|
+
catch { /* swallow — first real generate() will re-throw with the same error */ }
|
|
269
|
+
}
|
|
270
|
+
|
|
260
271
|
return {
|
|
261
272
|
setModel,
|
|
262
273
|
generate,
|
|
274
|
+
warm,
|
|
263
275
|
get currentModelId() { return config?.id || null; },
|
|
264
276
|
};
|
|
265
277
|
}
|
|
@@ -295,7 +307,7 @@ export function local({
|
|
|
295
307
|
const renderer = createTransformersRenderer();
|
|
296
308
|
if (model) renderer.setModel({ id: model, dtype, maxTokens, genParams, chatTemplate });
|
|
297
309
|
|
|
298
|
-
|
|
310
|
+
const provider = ({ messages, signal, system, tools, turnEl, setReplyText }) => (async function* () {
|
|
299
311
|
const effectiveSystem = system || systemPrompt || '';
|
|
300
312
|
const augmentedSystem = buildToolSystemPrompt(effectiveSystem, tools);
|
|
301
313
|
|
|
@@ -347,6 +359,13 @@ export function local({
|
|
|
347
359
|
if (error) throw error;
|
|
348
360
|
yield { type: 'turn_end', stopReason: sawToolUse ? 'tool_use' : 'end_turn' };
|
|
349
361
|
})();
|
|
362
|
+
|
|
363
|
+
// Surface the renderer's background warm() on the provider so hosts
|
|
364
|
+
// can trigger transformers.js import + weight download in idle time
|
|
365
|
+
// ahead of the first user message. Idempotent; no-op until setModel
|
|
366
|
+
// has run (covered above when `model` is passed).
|
|
367
|
+
provider.warm = (turnEl) => renderer.warm(turnEl);
|
|
368
|
+
return provider;
|
|
350
369
|
}
|
|
351
370
|
|
|
352
371
|
export { splitThinking };
|