@browser-ai/web-llm 2.0.4 → 2.1.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/dist/index.d.mts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
|
|
2
|
-
import { AppConfig, InitProgressReport, MLCEngineConfig
|
|
2
|
+
import { AppConfig, InitProgressReport, MLCEngineConfig } from '@mlc-ai/web-llm';
|
|
3
3
|
export { InitProgressReport as WebLLMProgress, WebWorkerMLCEngineHandler } from '@mlc-ai/web-llm';
|
|
4
4
|
import { UIMessage } from 'ai';
|
|
5
5
|
|
|
@@ -64,6 +64,12 @@ type Availability =
|
|
|
64
64
|
| "downloading"
|
|
65
65
|
| "available";
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Callback type for receiving model download/initialization progress updates.
|
|
69
|
+
* @param progress - A value between 0 and 1 indicating completion.
|
|
70
|
+
*/
|
|
71
|
+
type DownloadProgressCallback = (progress: number) => void;
|
|
72
|
+
|
|
67
73
|
declare global {
|
|
68
74
|
interface Navigator {
|
|
69
75
|
gpu?: GPU;
|
|
@@ -134,18 +140,18 @@ declare class WebLLMLanguageModel implements LanguageModelV3 {
|
|
|
134
140
|
*
|
|
135
141
|
* @example
|
|
136
142
|
* ```typescript
|
|
137
|
-
* const
|
|
143
|
+
* const model = await model.createSessionWithProgress(
|
|
138
144
|
* (progress) => {
|
|
139
|
-
* console.log(`Download progress: ${Math.round(progress
|
|
145
|
+
* console.log(`Download progress: ${Math.round(progress * 100)}%`);
|
|
140
146
|
* }
|
|
141
147
|
* );
|
|
142
148
|
* ```
|
|
143
149
|
*
|
|
144
|
-
* @param
|
|
145
|
-
* @returns Promise resolving to
|
|
150
|
+
* @param onDownloadProgress Optional callback receiving progress values from 0 to 1
|
|
151
|
+
* @returns Promise resolving to the model instance
|
|
146
152
|
* @throws {LoadSettingError} When WebLLM is not available or model is unavailable
|
|
147
153
|
*/
|
|
148
|
-
createSessionWithProgress(
|
|
154
|
+
createSessionWithProgress(onDownloadProgress?: DownloadProgressCallback): Promise<WebLLMLanguageModel>;
|
|
149
155
|
/**
|
|
150
156
|
* Generates a streaming text response using WebLLM
|
|
151
157
|
* @param options
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult } from '@ai-sdk/provider';
|
|
2
|
-
import { AppConfig, InitProgressReport, MLCEngineConfig
|
|
2
|
+
import { AppConfig, InitProgressReport, MLCEngineConfig } from '@mlc-ai/web-llm';
|
|
3
3
|
export { InitProgressReport as WebLLMProgress, WebWorkerMLCEngineHandler } from '@mlc-ai/web-llm';
|
|
4
4
|
import { UIMessage } from 'ai';
|
|
5
5
|
|
|
@@ -64,6 +64,12 @@ type Availability =
|
|
|
64
64
|
| "downloading"
|
|
65
65
|
| "available";
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Callback type for receiving model download/initialization progress updates.
|
|
69
|
+
* @param progress - A value between 0 and 1 indicating completion.
|
|
70
|
+
*/
|
|
71
|
+
type DownloadProgressCallback = (progress: number) => void;
|
|
72
|
+
|
|
67
73
|
declare global {
|
|
68
74
|
interface Navigator {
|
|
69
75
|
gpu?: GPU;
|
|
@@ -134,18 +140,18 @@ declare class WebLLMLanguageModel implements LanguageModelV3 {
|
|
|
134
140
|
*
|
|
135
141
|
* @example
|
|
136
142
|
* ```typescript
|
|
137
|
-
* const
|
|
143
|
+
* const model = await model.createSessionWithProgress(
|
|
138
144
|
* (progress) => {
|
|
139
|
-
* console.log(`Download progress: ${Math.round(progress
|
|
145
|
+
* console.log(`Download progress: ${Math.round(progress * 100)}%`);
|
|
140
146
|
* }
|
|
141
147
|
* );
|
|
142
148
|
* ```
|
|
143
149
|
*
|
|
144
|
-
* @param
|
|
145
|
-
* @returns Promise resolving to
|
|
150
|
+
* @param onDownloadProgress Optional callback receiving progress values from 0 to 1
|
|
151
|
+
* @returns Promise resolving to the model instance
|
|
146
152
|
* @throws {LoadSettingError} When WebLLM is not available or model is unavailable
|
|
147
153
|
*/
|
|
148
|
-
createSessionWithProgress(
|
|
154
|
+
createSessionWithProgress(onDownloadProgress?: DownloadProgressCallback): Promise<WebLLMLanguageModel>;
|
|
149
155
|
/**
|
|
150
156
|
* Generates a streaming text response using WebLLM
|
|
151
157
|
* @param options
|
package/dist/index.js
CHANGED
|
@@ -1372,19 +1372,23 @@ var WebLLMLanguageModel = class {
|
|
|
1372
1372
|
*
|
|
1373
1373
|
* @example
|
|
1374
1374
|
* ```typescript
|
|
1375
|
-
* const
|
|
1375
|
+
* const model = await model.createSessionWithProgress(
|
|
1376
1376
|
* (progress) => {
|
|
1377
|
-
* console.log(`Download progress: ${Math.round(progress
|
|
1377
|
+
* console.log(`Download progress: ${Math.round(progress * 100)}%`);
|
|
1378
1378
|
* }
|
|
1379
1379
|
* );
|
|
1380
1380
|
* ```
|
|
1381
1381
|
*
|
|
1382
|
-
* @param
|
|
1383
|
-
* @returns Promise resolving to
|
|
1382
|
+
* @param onDownloadProgress Optional callback receiving progress values from 0 to 1
|
|
1383
|
+
* @returns Promise resolving to the model instance
|
|
1384
1384
|
* @throws {LoadSettingError} When WebLLM is not available or model is unavailable
|
|
1385
1385
|
*/
|
|
1386
|
-
async createSessionWithProgress(
|
|
1387
|
-
|
|
1386
|
+
async createSessionWithProgress(onDownloadProgress) {
|
|
1387
|
+
const adaptedCallback = onDownloadProgress ? (report) => {
|
|
1388
|
+
onDownloadProgress(report.progress);
|
|
1389
|
+
} : void 0;
|
|
1390
|
+
await this.getEngine(void 0, adaptedCallback);
|
|
1391
|
+
return this;
|
|
1388
1392
|
}
|
|
1389
1393
|
/**
|
|
1390
1394
|
* Generates a streaming text response using WebLLM
|