webslm 0.7.0 → 0.9.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/README.md +85 -2
- package/dist/ai-sdk/embedding-model.d.ts +52 -0
- package/dist/ai-sdk/embedding-model.js +112 -0
- package/dist/ai-sdk/image-model.d.ts +53 -0
- package/dist/ai-sdk/image-model.js +148 -0
- package/dist/ai-sdk/index.d.ts +39 -0
- package/dist/ai-sdk/index.js +66 -11
- package/dist/client.d.ts +6 -0
- package/dist/client.js +8 -1
- package/dist/download.js +2 -2
- package/dist/engine.js +181 -0
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +1 -0
- package/dist/hub.d.ts +38 -3
- package/dist/hub.js +87 -8
- package/dist/image.d.ts +201 -0
- package/dist/image.js +353 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +4 -2
- package/dist/models.d.ts +19 -1
- package/dist/models.js +45 -6
- package/dist/native.d.ts +28 -0
- package/dist/protocol.d.ts +75 -2
- package/dist/simple.d.ts +4 -1
- package/dist/simple.js +9 -2
- package/dist/types.d.ts +39 -1
- package/dist/wasm.d.ts +2 -0
- package/native-manifest.json +29 -29
- package/package.json +1 -1
- package/wasm/relaxed/webslm_wasm.d.ts +70 -6
- package/wasm/relaxed/webslm_wasm.js +163 -18
- package/wasm/relaxed/webslm_wasm_bg.wasm +0 -0
- package/wasm/relaxed/webslm_wasm_bg.wasm.d.ts +10 -3
- package/wasm/simd/webslm_wasm.d.ts +70 -6
- package/wasm/simd/webslm_wasm.js +163 -18
- package/wasm/simd/webslm_wasm_bg.wasm +0 -0
- package/wasm/simd/webslm_wasm_bg.wasm.d.ts +10 -3
- package/wasm/threads/webslm_wasm.d.ts +71 -7
- package/wasm/threads/webslm_wasm.js +168 -23
- package/wasm/threads/webslm_wasm_bg.wasm +0 -0
- package/wasm/threads/webslm_wasm_bg.wasm.d.ts +11 -4
package/dist/protocol.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { SerializedError } from "./errors.js";
|
|
9
9
|
import type { Activations, AdapterMode, Backend, FileData, LoadProgress, LoraInfo, ModelInfo } from "./types.js";
|
|
10
|
+
import type { ImageModelInfo, ImagePhase, ImageQuant } from "./image.js";
|
|
10
11
|
import type { KvCacheType } from "./memory.js";
|
|
11
12
|
import type { WasmFlavour } from "./wasm-flavour.js";
|
|
12
13
|
/** A model source in a form that can be posted to a worker. */
|
|
@@ -36,6 +37,11 @@ export interface WireLoadOptions {
|
|
|
36
37
|
* machine's memory and GPU.
|
|
37
38
|
*/
|
|
38
39
|
readonly autoQuant?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* `quant` is the default, not the caller's choice: an encoder then loads
|
|
42
|
+
* in f32 (small models, embeddings compared across texts).
|
|
43
|
+
*/
|
|
44
|
+
readonly defaultQuant?: boolean;
|
|
39
45
|
/** `"auto"`, `"cpu"`, `"gpu"` or `"webgpu"`; the engine reports what it used. */
|
|
40
46
|
readonly device?: string;
|
|
41
47
|
/** `"auto"` (default), `"native"` or `"wasm"`. */
|
|
@@ -56,6 +62,25 @@ export interface WireLoadOptions {
|
|
|
56
62
|
readonly wasmFlavour?: WasmFlavour;
|
|
57
63
|
readonly threads?: number;
|
|
58
64
|
}
|
|
65
|
+
/** Load options of a text-to-image pipeline. */
|
|
66
|
+
export interface WireImageLoadOptions {
|
|
67
|
+
readonly quant: ImageQuant;
|
|
68
|
+
/** `"auto"`, `"cpu"`, `"gpu"` or `"webgpu"`. */
|
|
69
|
+
readonly device?: string;
|
|
70
|
+
readonly backend?: Backend;
|
|
71
|
+
readonly cacheDir?: string;
|
|
72
|
+
readonly wasmFlavour?: WasmFlavour;
|
|
73
|
+
readonly threads?: number;
|
|
74
|
+
}
|
|
75
|
+
/** Image options as sent to the engine (no signal). */
|
|
76
|
+
export interface WireImageOptions {
|
|
77
|
+
readonly width?: number;
|
|
78
|
+
readonly height?: number;
|
|
79
|
+
readonly steps?: number;
|
|
80
|
+
readonly guidance?: number;
|
|
81
|
+
readonly seed?: number;
|
|
82
|
+
readonly negativePrompt?: string;
|
|
83
|
+
}
|
|
59
84
|
/** Generation options as sent to the engine (no signal). */
|
|
60
85
|
export interface WireGenerateOptions {
|
|
61
86
|
readonly maxTokens?: number;
|
|
@@ -209,6 +234,25 @@ export type Request = WithId<{
|
|
|
209
234
|
readonly model: number;
|
|
210
235
|
readonly messages: readonly WireMessage[];
|
|
211
236
|
readonly templateKwargs: Readonly<Record<string, unknown>>;
|
|
237
|
+
} | {
|
|
238
|
+
readonly type: "embed";
|
|
239
|
+
readonly model: number;
|
|
240
|
+
readonly texts: readonly string[];
|
|
241
|
+
readonly options: {
|
|
242
|
+
readonly pooling?: string;
|
|
243
|
+
readonly normalize?: boolean;
|
|
244
|
+
};
|
|
245
|
+
} | {
|
|
246
|
+
readonly type: "loadImage";
|
|
247
|
+
readonly source: WireSource;
|
|
248
|
+
/** A standalone autoencoder replacing the pipeline's decoder. */
|
|
249
|
+
readonly decoder?: WireSource;
|
|
250
|
+
readonly options: WireImageLoadOptions;
|
|
251
|
+
} | {
|
|
252
|
+
readonly type: "generateImage";
|
|
253
|
+
readonly model: number;
|
|
254
|
+
readonly prompt: string;
|
|
255
|
+
readonly options: WireImageOptions;
|
|
212
256
|
} | {
|
|
213
257
|
readonly type: "unload";
|
|
214
258
|
readonly model: number;
|
|
@@ -248,6 +292,12 @@ export type Response = {
|
|
|
248
292
|
readonly id: number;
|
|
249
293
|
readonly done: number;
|
|
250
294
|
readonly total: number;
|
|
295
|
+
} | {
|
|
296
|
+
readonly type: "imageProgress";
|
|
297
|
+
readonly id: number;
|
|
298
|
+
readonly phase: ImagePhase;
|
|
299
|
+
readonly step: number;
|
|
300
|
+
readonly steps: number;
|
|
251
301
|
} | {
|
|
252
302
|
readonly type: "read";
|
|
253
303
|
readonly id: number;
|
|
@@ -255,16 +305,39 @@ export type Response = {
|
|
|
255
305
|
readonly path: string;
|
|
256
306
|
readonly start?: number;
|
|
257
307
|
readonly end?: number;
|
|
258
|
-
/**
|
|
259
|
-
|
|
308
|
+
/**
|
|
309
|
+
* `"adapter"` for files of the LoRA adapter, `"decoder"` for those of
|
|
310
|
+
* an image model's standalone decoder, absent for the model's own.
|
|
311
|
+
*/
|
|
312
|
+
readonly target?: "adapter" | "decoder";
|
|
260
313
|
};
|
|
261
314
|
/** Value of an `applyAdapter` result (`removeAdapter` resolves to it or `null`). */
|
|
262
315
|
export type WireLoraResult = LoraInfo;
|
|
316
|
+
/** Value of an `embed` result. */
|
|
317
|
+
export interface WireEmbedResult {
|
|
318
|
+
readonly data: Float32Array;
|
|
319
|
+
readonly dimensions: number;
|
|
320
|
+
readonly tokens: Uint32Array;
|
|
321
|
+
}
|
|
263
322
|
/** Value of a `load` result. */
|
|
264
323
|
export interface LoadResult {
|
|
265
324
|
readonly model: number;
|
|
266
325
|
readonly info: ModelInfo;
|
|
267
326
|
}
|
|
327
|
+
/** Value of a `loadImage` result. */
|
|
328
|
+
export interface ImageLoadResult {
|
|
329
|
+
readonly model: number;
|
|
330
|
+
readonly info: ImageModelInfo;
|
|
331
|
+
}
|
|
332
|
+
/** Value of a `generateImage` result. */
|
|
333
|
+
export interface WireImageResult {
|
|
334
|
+
readonly width: number;
|
|
335
|
+
readonly height: number;
|
|
336
|
+
readonly seed: number;
|
|
337
|
+
/** Row-major 8-bit RGBA pixels. */
|
|
338
|
+
readonly rgba: Uint8Array;
|
|
339
|
+
readonly timeMs: number;
|
|
340
|
+
}
|
|
268
341
|
/** Value of a `chat` or `generate` result. */
|
|
269
342
|
export interface WireGenerationResult {
|
|
270
343
|
readonly text: string;
|
package/dist/simple.d.ts
CHANGED
|
@@ -329,5 +329,8 @@ export declare function ask(prompt: string, options?: SharedAskOptions): Promise
|
|
|
329
329
|
* ```
|
|
330
330
|
*/
|
|
331
331
|
export declare function stream(prompt: string, options?: SharedStreamOptions): TextStream;
|
|
332
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Unloads every model loaded by the module-level {@link ask} and
|
|
334
|
+
* {@link stream} (and by `generateImage`).
|
|
335
|
+
*/
|
|
333
336
|
export declare function unloadAll(): Promise<void>;
|
package/dist/simple.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { AsyncQueue } from "./async-queue.js";
|
|
7
7
|
import { recommendedSampling } from "./curated.js";
|
|
8
8
|
import { WebslmError, abortError, isAborted, toWebslmError } from "./errors.js";
|
|
9
|
+
import { unloadImageModels } from "./image.js";
|
|
9
10
|
import { loadModel } from "./models.js";
|
|
10
11
|
/**
|
|
11
12
|
* The model {@link load}, {@link ask} and {@link stream} use when none is
|
|
@@ -580,9 +581,15 @@ export function stream(prompt, options = {}) {
|
|
|
580
581
|
await llm.runPrompt(context, prompt, rest);
|
|
581
582
|
}, rest);
|
|
582
583
|
}
|
|
583
|
-
/**
|
|
584
|
+
/**
|
|
585
|
+
* Unloads every model loaded by the module-level {@link ask} and
|
|
586
|
+
* {@link stream} (and by `generateImage`).
|
|
587
|
+
*/
|
|
584
588
|
export async function unloadAll() {
|
|
585
589
|
const pending = [...shared.values()];
|
|
586
590
|
shared.clear();
|
|
587
|
-
await Promise.all(
|
|
591
|
+
await Promise.all([
|
|
592
|
+
...pending.map((p) => p.then((llm) => llm.unload(), () => { })),
|
|
593
|
+
unloadImageModels(),
|
|
594
|
+
]);
|
|
588
595
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -184,7 +184,8 @@ export interface LoadModelOptions {
|
|
|
184
184
|
* per token, the most recent {@link LoadModelOptions.kvResidual} positions
|
|
185
185
|
* kept in f32): about 3 times less memory at 4096 positions, on the CPU
|
|
186
186
|
* and WebGPU, at a small cost in accuracy. Sliding-window and recurrent
|
|
187
|
-
* layers keep their own small states.
|
|
187
|
+
* layers keep their own small states. Encoders (embedding models) have
|
|
188
|
+
* no KV cache and ignore this and the other KV options.
|
|
188
189
|
*/
|
|
189
190
|
readonly kvCache?: KvCacheType;
|
|
190
191
|
/** Int8 KV cache: the most recent positions kept in f32 (default 128, rounded up to a multiple of 32). */
|
|
@@ -596,6 +597,38 @@ export interface ModelMemory {
|
|
|
596
597
|
readonly maxBuffer?: number;
|
|
597
598
|
}
|
|
598
599
|
/** Description of a loaded model. */
|
|
600
|
+
/** Pooling of the token vectors of a text into one embedding (sentence-transformers' modes). */
|
|
601
|
+
export type Pooling = "cls" | "mean" | "max" | "mean_sqrt_len_tokens" | "weightedmean" | "lasttoken";
|
|
602
|
+
/** The embeddings of an encoder, in {@link ModelInfo.embedding}. */
|
|
603
|
+
export interface EmbeddingInfo {
|
|
604
|
+
/** Length of an embedding. */
|
|
605
|
+
readonly dimensions: number;
|
|
606
|
+
/** Pooling modes, concatenated in this order (`1_Pooling/config.json`; mean for a plain checkpoint). */
|
|
607
|
+
readonly pooling: readonly Pooling[];
|
|
608
|
+
/** Whether vectors are L2-normalized (a `Normalize` module, or model2vec's `normalize`). */
|
|
609
|
+
readonly normalize: boolean;
|
|
610
|
+
/** Largest number of tokens read from a text; longer texts are cut. */
|
|
611
|
+
readonly maxLength?: number;
|
|
612
|
+
}
|
|
613
|
+
/** Options of {@link Model.embed}. */
|
|
614
|
+
export interface EmbedOptions {
|
|
615
|
+
/** Pooling instead of the model's (static models pool by mean only). */
|
|
616
|
+
readonly pooling?: Pooling;
|
|
617
|
+
/** L2-normalize the vectors, or not, instead of the model's setting. */
|
|
618
|
+
readonly normalize?: boolean;
|
|
619
|
+
readonly signal?: AbortSignal;
|
|
620
|
+
}
|
|
621
|
+
/** What {@link Model.embed} returns. */
|
|
622
|
+
export interface Embeddings {
|
|
623
|
+
/** One vector per text, in order (views on {@link Embeddings.data}). */
|
|
624
|
+
readonly vectors: readonly Float32Array[];
|
|
625
|
+
/** The vectors one after the other. */
|
|
626
|
+
readonly data: Float32Array;
|
|
627
|
+
/** Length of each vector. */
|
|
628
|
+
readonly dimensions: number;
|
|
629
|
+
/** Tokens read from each text (texts longer than the model's limit are cut). */
|
|
630
|
+
readonly tokens: readonly number[];
|
|
631
|
+
}
|
|
599
632
|
export interface ModelInfo {
|
|
600
633
|
/** Hub repository id, when loaded from the hub. */
|
|
601
634
|
readonly repo?: string;
|
|
@@ -644,6 +677,11 @@ export interface ModelInfo {
|
|
|
644
677
|
readonly images: boolean;
|
|
645
678
|
readonly videos: boolean;
|
|
646
679
|
};
|
|
680
|
+
/**
|
|
681
|
+
* What `embed` returns by default, for an encoder (an embedding model:
|
|
682
|
+
* BERT, ModernBERT, model2vec); absent for language models.
|
|
683
|
+
*/
|
|
684
|
+
readonly embedding?: EmbeddingInfo;
|
|
647
685
|
readonly stopTokens: readonly number[];
|
|
648
686
|
readonly tokenizer: {
|
|
649
687
|
readonly vocabSize: number;
|
package/dist/wasm.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface WasmExports {
|
|
|
11
11
|
version(): string;
|
|
12
12
|
/** `model_type` values the engine runs. */
|
|
13
13
|
supportedModelTypes(): string[];
|
|
14
|
+
/** `model_type` values of the encoders the engine embeds with. */
|
|
15
|
+
supportedEncoderTypes(): string[];
|
|
14
16
|
/** Parses a safetensors header (see `parseSafetensorsHeader`). */
|
|
15
17
|
parseSafetensorsHeader(bytes: Uint8Array): unknown;
|
|
16
18
|
/** Incremental SHA-256 (`finish()` returns the hex digest and resets). */
|
package/native-manifest.json
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.9.0",
|
|
3
3
|
"assets": {
|
|
4
4
|
"darwin-arm64": {
|
|
5
|
-
"file": "webslm-node-0.
|
|
6
|
-
"size":
|
|
7
|
-
"sha256": "
|
|
8
|
-
"nodeSha256": "
|
|
5
|
+
"file": "webslm-node-0.9.0-darwin-arm64.node.gz",
|
|
6
|
+
"size": 5591852,
|
|
7
|
+
"sha256": "cea8e35516345ba1f80999eb22d3dd52cffc1efae0392a2329ac1bb4fab3df20",
|
|
8
|
+
"nodeSha256": "d7a753a468e097bf55488b3377e5c7988fd00174beafba171d0d98155bfb4f8b"
|
|
9
9
|
},
|
|
10
10
|
"darwin-x64": {
|
|
11
|
-
"file": "webslm-node-0.
|
|
12
|
-
"size":
|
|
13
|
-
"sha256": "
|
|
14
|
-
"nodeSha256": "
|
|
11
|
+
"file": "webslm-node-0.9.0-darwin-x64.node.gz",
|
|
12
|
+
"size": 5888899,
|
|
13
|
+
"sha256": "258e2d3682207281ad01e432d8d5cc67b4acde1a5135f94bfdecf9c0cc3addcb",
|
|
14
|
+
"nodeSha256": "d475186c607d38b94f16bf5b907c793052c4930eb8fb1da66fcaf4d56f4eaa95"
|
|
15
15
|
},
|
|
16
16
|
"linux-x64-gnu": {
|
|
17
|
-
"file": "webslm-node-0.
|
|
18
|
-
"size":
|
|
19
|
-
"sha256": "
|
|
20
|
-
"nodeSha256": "
|
|
17
|
+
"file": "webslm-node-0.9.0-linux-x64-gnu.node.gz",
|
|
18
|
+
"size": 5918558,
|
|
19
|
+
"sha256": "e54006e5b99eec6b6b5c3ad3151b17b2b1c5fec82bbc752b10ed3042c5ebc504",
|
|
20
|
+
"nodeSha256": "bc889da6b28d8b6a5c67e0f27afd35c83e5140577eabb6b9dfe507a16676cd6d"
|
|
21
21
|
},
|
|
22
22
|
"linux-arm64-gnu": {
|
|
23
|
-
"file": "webslm-node-0.
|
|
24
|
-
"size":
|
|
25
|
-
"sha256": "
|
|
26
|
-
"nodeSha256": "
|
|
23
|
+
"file": "webslm-node-0.9.0-linux-arm64-gnu.node.gz",
|
|
24
|
+
"size": 5558757,
|
|
25
|
+
"sha256": "a905db5284c04c1be6c2c19f4c13955a0886e34764512a0dbdfb7ee74afb5ef9",
|
|
26
|
+
"nodeSha256": "b139332668606acd944db2d70ece7f02a3e2810047bece5e0e828932aa40bbd6"
|
|
27
27
|
},
|
|
28
28
|
"linux-x64-musl": {
|
|
29
|
-
"file": "webslm-node-0.
|
|
30
|
-
"size":
|
|
31
|
-
"sha256": "
|
|
32
|
-
"nodeSha256": "
|
|
29
|
+
"file": "webslm-node-0.9.0-linux-x64-musl.node.gz",
|
|
30
|
+
"size": 6321849,
|
|
31
|
+
"sha256": "118396973e958c1ed99e8a248abff85d3543e6bc34b54585fb0bd97ccb86b9c6",
|
|
32
|
+
"nodeSha256": "d637858c3b43c2da944600bb781652ba3550d059f02a36407c529d237ea670e2"
|
|
33
33
|
},
|
|
34
34
|
"linux-arm64-musl": {
|
|
35
|
-
"file": "webslm-node-0.
|
|
36
|
-
"size":
|
|
37
|
-
"sha256": "
|
|
38
|
-
"nodeSha256": "
|
|
35
|
+
"file": "webslm-node-0.9.0-linux-arm64-musl.node.gz",
|
|
36
|
+
"size": 6087963,
|
|
37
|
+
"sha256": "362cb975bc640c7822f80a3bb4407bc6218b39513560b52e37533a968422ee4a",
|
|
38
|
+
"nodeSha256": "af0b29f7688457466ad47788ad870783252ef4035efb0ee9dd537a73ed817615"
|
|
39
39
|
},
|
|
40
40
|
"win32-x64-msvc": {
|
|
41
|
-
"file": "webslm-node-0.
|
|
42
|
-
"size":
|
|
43
|
-
"sha256": "
|
|
44
|
-
"nodeSha256": "
|
|
41
|
+
"file": "webslm-node-0.9.0-win32-x64-msvc.node.gz",
|
|
42
|
+
"size": 6407894,
|
|
43
|
+
"sha256": "d0b1860d23e77fcbab0d4646189ac2ee44c0f683f312469c11f3d7289cf825da",
|
|
44
|
+
"nodeSha256": "2cbb741f1704cf540e311d5c21730e98102c54f6fd720df1c919611e95060ada"
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webslm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Run small language models in the browser and in Node, straight from their original Hugging Face checkpoints: a Rust engine compiled to WebAssembly, in a worker, with an offline cache.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Maxime Golfier",
|
|
@@ -49,9 +49,41 @@ export class Sha256Hasher {
|
|
|
49
49
|
update(bytes: Uint8Array): void;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* A loaded text-to-image pipeline.
|
|
54
|
+
*/
|
|
55
|
+
export class WasmImageModel {
|
|
56
|
+
private constructor();
|
|
57
|
+
free(): void;
|
|
58
|
+
[Symbol.dispose](): void;
|
|
59
|
+
/**
|
|
60
|
+
* Generates an image of `prompt`. `options_json`: `{ width?, height?,
|
|
61
|
+
* steps?, guidance?, seed?, negativePrompt? }` (see `ImageOptionsJs`).
|
|
62
|
+
* `on_progress(phase, step, steps)` is called before encoding the
|
|
63
|
+
* prompt, before each denoising step and before decoding; returning
|
|
64
|
+
* `false` stops the generation (it rejects with `"ABORTED"`).
|
|
65
|
+
* Resolves to `{ width, height, seed, rgba: Uint8Array }` (row-major
|
|
66
|
+
* 8-bit RGBA).
|
|
67
|
+
*/
|
|
68
|
+
generate(prompt: string, options_json: string, on_progress?: Function | null): Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Describes the pipeline (see [`ImageModelInfo`]).
|
|
71
|
+
*/
|
|
72
|
+
info(): any;
|
|
73
|
+
/**
|
|
74
|
+
* Loads a pipeline from `source`. `options_json`:
|
|
75
|
+
* `{ format?: "f16" | "f32" | "bf16" | "q8" | ..., device?: "cpu" |
|
|
76
|
+
* "webgpu" | "auto" }` (defaults: f16 weights, `auto`). `decoder`,
|
|
77
|
+
* when given, serves a standalone autoencoder (`config.json` and
|
|
78
|
+
* `diffusion_pytorch_model.safetensors`, e.g. `madebyollin/taesd`)
|
|
79
|
+
* that replaces the pipeline's decoder.
|
|
80
|
+
*/
|
|
81
|
+
static load(source: JsSource, options_json: string, decoder?: JsSource | null): Promise<WasmImageModel>;
|
|
82
|
+
}
|
|
83
|
+
|
|
52
84
|
/**
|
|
53
85
|
* A loaded checkpoint, with a default session used by `chat` and
|
|
54
|
-
* `generate`.
|
|
86
|
+
* `generate` (language models), or an encoder answering `embed`.
|
|
55
87
|
*/
|
|
56
88
|
export class WasmModel {
|
|
57
89
|
private constructor();
|
|
@@ -84,6 +116,17 @@ export class WasmModel {
|
|
|
84
116
|
* Decodes token ids into text.
|
|
85
117
|
*/
|
|
86
118
|
detokenize(ids: Uint32Array, skip_special_tokens: boolean): string;
|
|
119
|
+
/**
|
|
120
|
+
* Embeds texts with an encoder. `texts_json` is a JSON array of
|
|
121
|
+
* strings; `options_json`: `{ pooling?: "cls" | "mean" | "max" |
|
|
122
|
+
* "mean_sqrt_len_tokens" | "weightedmean" | "lasttoken", normalize?:
|
|
123
|
+
* boolean }` (defaults: the model's sentence-transformers settings).
|
|
124
|
+
* Resolves to `{ data: Float32Array, dimensions: number, tokens:
|
|
125
|
+
* number[] }`: the vectors one after the other, and the number of
|
|
126
|
+
* tokens read from each text (texts longer than the model's limit are
|
|
127
|
+
* cut). Rejects with `UNSUPPORTED_TASK` on a language model.
|
|
128
|
+
*/
|
|
129
|
+
embed(texts_json: string, options_json: string): Promise<any>;
|
|
87
130
|
/**
|
|
88
131
|
* Completes raw text in the default session; see
|
|
89
132
|
* [`WasmSession::generate`].
|
|
@@ -126,6 +169,9 @@ export class WasmModel {
|
|
|
126
169
|
* `format`, a pre-quantized checkpoint (a `Q8_0` GGUF file, a
|
|
127
170
|
* `webslm export` checkpoint) loads in its own format, its blocks
|
|
128
171
|
* unchanged; weights already in the load format skip `weightCache`.
|
|
172
|
+
*
|
|
173
|
+
* An encoder loads in f32 unless `format` says otherwise, and takes
|
|
174
|
+
* no `lora`.
|
|
129
175
|
*/
|
|
130
176
|
static load(source: JsSource, options_json: string, lora?: JsSource | null, weight_cache?: JsWeightCache | null): Promise<WasmModel>;
|
|
131
177
|
/**
|
|
@@ -142,13 +188,18 @@ export class WasmModel {
|
|
|
142
188
|
*/
|
|
143
189
|
renderChat(messages_json: string, kwargs_json: string): string;
|
|
144
190
|
/**
|
|
145
|
-
* Clears the default session.
|
|
191
|
+
* Clears the default session (nothing to clear for an encoder).
|
|
146
192
|
*/
|
|
147
193
|
reset(): void;
|
|
148
194
|
/**
|
|
149
|
-
* Encodes text into token ids
|
|
195
|
+
* Encodes text into token ids (an encoder's tokenizer cuts texts at
|
|
196
|
+
* its limit, as `embed` does).
|
|
150
197
|
*/
|
|
151
198
|
tokenize(text: string, add_special_tokens: boolean): Uint32Array;
|
|
199
|
+
/**
|
|
200
|
+
* Whether the model is an encoder (it answers `embed`, not `chat`).
|
|
201
|
+
*/
|
|
202
|
+
readonly isEncoder: boolean;
|
|
152
203
|
}
|
|
153
204
|
|
|
154
205
|
/**
|
|
@@ -279,6 +330,12 @@ export function buildInfo(): any;
|
|
|
279
330
|
*/
|
|
280
331
|
export function parseSafetensorsHeader(bytes: Uint8Array): any;
|
|
281
332
|
|
|
333
|
+
/**
|
|
334
|
+
* `model_type` values of the encoders this build embeds with (models
|
|
335
|
+
* whose `WasmModel` answers `embed`).
|
|
336
|
+
*/
|
|
337
|
+
export function supportedEncoderTypes(): string[];
|
|
338
|
+
|
|
282
339
|
/**
|
|
283
340
|
* `model_type` values (from `config.json`) of the architectures this build
|
|
284
341
|
* can run.
|
|
@@ -297,6 +354,7 @@ export interface InitOutput {
|
|
|
297
354
|
readonly __wbg_jssource_free: (a: number, b: number) => void;
|
|
298
355
|
readonly __wbg_jsweightcache_free: (a: number, b: number) => void;
|
|
299
356
|
readonly __wbg_sha256hasher_free: (a: number, b: number) => void;
|
|
357
|
+
readonly __wbg_wasmimagemodel_free: (a: number, b: number) => void;
|
|
300
358
|
readonly __wbg_wasmmodel_free: (a: number, b: number) => void;
|
|
301
359
|
readonly __wbg_wasmsession_free: (a: number, b: number) => void;
|
|
302
360
|
readonly buildInfo: () => [number, number, number];
|
|
@@ -306,15 +364,21 @@ export interface InitOutput {
|
|
|
306
364
|
readonly sha256hasher_finish: (a: number) => [number, number];
|
|
307
365
|
readonly sha256hasher_new: () => number;
|
|
308
366
|
readonly sha256hasher_update: (a: number, b: number, c: number) => void;
|
|
367
|
+
readonly supportedEncoderTypes: () => [number, number];
|
|
309
368
|
readonly supportedModelTypes: () => [number, number];
|
|
310
369
|
readonly version: () => [number, number];
|
|
370
|
+
readonly wasmimagemodel_generate: (a: number, b: number, c: number, d: number, e: number, f: number) => any;
|
|
371
|
+
readonly wasmimagemodel_info: (a: number) => [number, number, number];
|
|
372
|
+
readonly wasmimagemodel_load: (a: number, b: number, c: number, d: number) => any;
|
|
311
373
|
readonly wasmmodel_applyAdapter: (a: number, b: number, c: number, d: number) => any;
|
|
312
374
|
readonly wasmmodel_chat: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
313
375
|
readonly wasmmodel_chatWithMedia: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: any, k: number) => any;
|
|
314
376
|
readonly wasmmodel_createSession: (a: number) => [number, number, number];
|
|
315
377
|
readonly wasmmodel_detokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
378
|
+
readonly wasmmodel_embed: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
316
379
|
readonly wasmmodel_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
317
380
|
readonly wasmmodel_info: (a: number) => [number, number, number];
|
|
381
|
+
readonly wasmmodel_isEncoder: (a: number) => number;
|
|
318
382
|
readonly wasmmodel_load: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
319
383
|
readonly wasmmodel_removeAdapter: (a: number) => any;
|
|
320
384
|
readonly wasmmodel_renderChat: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
@@ -337,10 +401,10 @@ export interface InitOutput {
|
|
|
337
401
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___js_sys_56365fc49d784db6___Function_fn_wasm_bindgen_8cf186fa7724d16d___JsValue_____wasm_bindgen_8cf186fa7724d16d___sys__Undefined___js_sys_56365fc49d784db6___Function_fn_wasm_bindgen_8cf186fa7724d16d___JsValue_____wasm_bindgen_8cf186fa7724d16d___sys__Undefined_______true_: (a: number, b: number, c: any, d: any) => void;
|
|
338
402
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___JsValue__core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
339
403
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true_: (a: number, b: number, c: any) => [number, number];
|
|
340
|
-
readonly
|
|
341
|
-
readonly
|
|
404
|
+
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true__46: (a: number, b: number, c: any) => [number, number];
|
|
405
|
+
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wasm_bindgen_8cf186fa7724d16d___sys__JsNullable_wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuError__GpuError___core_608f92abc48d28da___result__Result_____wasm_bindgen_8cf186fa7724d16d___JsError___true__47: (a: number, b: number, c: any) => [number, number];
|
|
342
406
|
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_: (a: number, b: number, c: any) => void;
|
|
343
|
-
readonly
|
|
407
|
+
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__45: (a: number, b: number, c: any) => void;
|
|
344
408
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
345
409
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
346
410
|
readonly __wbindgen_exn_store: (a: number) => void;
|