webslm 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +373 -2
- package/dist/ai-sdk/index.d.ts +81 -0
- package/dist/ai-sdk/index.js +90 -0
- package/dist/ai-sdk/language-model.d.ts +77 -0
- package/dist/ai-sdk/language-model.js +422 -0
- package/dist/ai-sdk/loader.d.ts +54 -0
- package/dist/ai-sdk/loader.js +170 -0
- package/dist/ai-sdk/output.d.ts +43 -0
- package/dist/ai-sdk/output.js +152 -0
- package/dist/ai-sdk/prompt.d.ts +21 -0
- package/dist/ai-sdk/prompt.js +111 -0
- package/dist/async-queue.d.ts +22 -0
- package/dist/async-queue.js +70 -0
- package/dist/cache/cache-api.d.ts +29 -0
- package/dist/cache/cache-api.js +115 -0
- package/dist/cache/index.d.ts +21 -0
- package/dist/cache/index.js +42 -0
- package/dist/cache/memory.d.ts +12 -0
- package/dist/cache/memory.js +61 -0
- package/dist/cache/models.d.ts +67 -0
- package/dist/cache/models.js +107 -0
- package/dist/cache/node-fs.d.ts +21 -0
- package/dist/cache/node-fs.js +147 -0
- package/dist/cache/opfs.d.ts +69 -0
- package/dist/cache/opfs.js +181 -0
- package/dist/cache/store.d.ts +53 -0
- package/dist/cache/store.js +64 -0
- package/dist/cache-management.d.ts +23 -0
- package/dist/cache-management.js +58 -0
- package/dist/capabilities.d.ts +67 -0
- package/dist/capabilities.js +55 -0
- package/dist/client.d.ts +61 -0
- package/dist/client.js +256 -0
- package/dist/curated.d.ts +22 -0
- package/dist/curated.js +53 -0
- package/dist/download.d.ts +51 -0
- package/dist/download.js +289 -0
- package/dist/engine.d.ts +54 -0
- package/dist/engine.js +510 -0
- package/dist/errors.d.ts +81 -0
- package/dist/errors.js +89 -0
- package/dist/hub.d.ts +185 -0
- package/dist/hub.js +409 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +41 -0
- package/dist/models.d.ts +225 -0
- package/dist/models.js +730 -0
- package/dist/node-pool-worker.d.ts +6 -0
- package/dist/node-pool-worker.js +32 -0
- package/dist/node-web-worker.d.ts +23 -0
- package/dist/node-web-worker.js +84 -0
- package/dist/node-worker.d.ts +2 -0
- package/dist/node-worker.js +9 -0
- package/dist/pool-worker.d.ts +36 -0
- package/dist/pool-worker.js +30 -0
- package/dist/pool.d.ts +17 -0
- package/dist/pool.js +41 -0
- package/dist/protocol.d.ts +246 -0
- package/dist/protocol.js +19 -0
- package/dist/runtime.d.ts +21 -0
- package/dist/runtime.js +53 -0
- package/dist/safetensors.d.ts +20 -0
- package/dist/safetensors.js +2 -0
- package/dist/simple.d.ts +310 -0
- package/dist/simple.js +553 -0
- package/dist/types.d.ts +412 -0
- package/dist/types.js +2 -0
- package/dist/wasm-flavour.d.ts +85 -0
- package/dist/wasm-flavour.js +169 -0
- package/dist/wasm.d.ts +34 -0
- package/dist/wasm.js +38 -0
- package/dist/worker.d.ts +6 -0
- package/dist/worker.js +11 -0
- package/package.json +92 -3
- package/wasm/relaxed/webslm_wasm.d.ts +325 -0
- package/wasm/relaxed/webslm_wasm.js +1899 -0
- package/wasm/relaxed/webslm_wasm_bg.wasm +0 -0
- package/wasm/relaxed/webslm_wasm_bg.wasm.d.ts +56 -0
- package/wasm/simd/webslm_wasm.d.ts +325 -0
- package/wasm/simd/webslm_wasm.js +1899 -0
- package/wasm/simd/webslm_wasm_bg.wasm +0 -0
- package/wasm/simd/webslm_wasm_bg.wasm.d.ts +56 -0
- package/wasm/threads/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.js +108 -0
- package/wasm/threads/webslm_wasm.d.ts +357 -0
- package/wasm/threads/webslm_wasm.js +2100 -0
- package/wasm/threads/webslm_wasm_bg.wasm +0 -0
- package/wasm/threads/webslm_wasm_bg.wasm.d.ts +66 -0
package/dist/wasm.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy loader for the Rust engine compiled to WebAssembly.
|
|
3
|
+
*
|
|
4
|
+
* The bindings live in `../wasm/simd/`, generated by `cargo xtask build-wasm`.
|
|
5
|
+
* They are imported dynamically so that importing `webslm` stays cheap and
|
|
6
|
+
* bundlers emit the `.wasm` file as a separate asset.
|
|
7
|
+
*/
|
|
8
|
+
/** The engine's low-level exports used outside the worker. */
|
|
9
|
+
export interface WasmExports {
|
|
10
|
+
/** Version of the Rust engine. */
|
|
11
|
+
version(): string;
|
|
12
|
+
/** `model_type` values the engine runs. */
|
|
13
|
+
supportedModelTypes(): string[];
|
|
14
|
+
/** Parses a safetensors header (see `parseSafetensorsHeader`). */
|
|
15
|
+
parseSafetensorsHeader(bytes: Uint8Array): unknown;
|
|
16
|
+
/** Incremental SHA-256 (`finish()` returns the hex digest and resets). */
|
|
17
|
+
readonly Sha256Hasher: new () => {
|
|
18
|
+
update(bytes: Uint8Array): void;
|
|
19
|
+
finish(): string;
|
|
20
|
+
free(): void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
type Bindings = WasmExports;
|
|
24
|
+
/** Anything `WebAssembly.instantiate` or `fetch` accepts for the module. */
|
|
25
|
+
export type WasmSource = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
26
|
+
/**
|
|
27
|
+
* Loads and instantiates the engine once; later calls share the same instance.
|
|
28
|
+
*
|
|
29
|
+
* @param source Where to load `webslm_wasm_bg.wasm` from. Defaults to the
|
|
30
|
+
* file shipped next to the bindings, resolved via `import.meta.url` (read
|
|
31
|
+
* from disk in Node).
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadWasm(source?: WasmSource): Promise<Bindings>;
|
|
34
|
+
export {};
|
package/dist/wasm.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy loader for the Rust engine compiled to WebAssembly.
|
|
3
|
+
*
|
|
4
|
+
* The bindings live in `../wasm/simd/`, generated by `cargo xtask build-wasm`.
|
|
5
|
+
* They are imported dynamically so that importing `webslm` stays cheap and
|
|
6
|
+
* bundlers emit the `.wasm` file as a separate asset.
|
|
7
|
+
*/
|
|
8
|
+
import { importNode, isNode } from "./runtime.js";
|
|
9
|
+
let bindings;
|
|
10
|
+
/**
|
|
11
|
+
* Loads and instantiates the engine once; later calls share the same instance.
|
|
12
|
+
*
|
|
13
|
+
* @param source Where to load `webslm_wasm_bg.wasm` from. Defaults to the
|
|
14
|
+
* file shipped next to the bindings, resolved via `import.meta.url` (read
|
|
15
|
+
* from disk in Node).
|
|
16
|
+
*/
|
|
17
|
+
export function loadWasm(source) {
|
|
18
|
+
if (bindings === undefined) {
|
|
19
|
+
const pending = (async () => {
|
|
20
|
+
const module = await import("../wasm/simd/webslm_wasm.js");
|
|
21
|
+
let input = source;
|
|
22
|
+
if (input === undefined && isNode()) {
|
|
23
|
+
// Node's fetch cannot read file: URLs.
|
|
24
|
+
const fs = await importNode("fs/promises");
|
|
25
|
+
input = await fs.readFile(new URL("../wasm/simd/webslm_wasm_bg.wasm", import.meta.url));
|
|
26
|
+
}
|
|
27
|
+
await module.default(input === undefined ? undefined : { module_or_path: input });
|
|
28
|
+
return module;
|
|
29
|
+
})();
|
|
30
|
+
// Allow a retry after a failed load (network error, CSP...).
|
|
31
|
+
pending.catch(() => {
|
|
32
|
+
if (bindings === pending)
|
|
33
|
+
bindings = undefined;
|
|
34
|
+
});
|
|
35
|
+
bindings = pending;
|
|
36
|
+
}
|
|
37
|
+
return bindings;
|
|
38
|
+
}
|
package/dist/worker.d.ts
ADDED
package/dist/worker.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entry point of the dedicated module Worker that runs the engine in
|
|
3
|
+
* browsers. Started by the page with
|
|
4
|
+
* `new Worker(new URL("./worker.js", import.meta.url), { type: "module" })`.
|
|
5
|
+
*/
|
|
6
|
+
import { Engine } from "./engine.js";
|
|
7
|
+
const scope = globalThis;
|
|
8
|
+
const engine = new Engine({
|
|
9
|
+
post: (message, transfer) => scope.postMessage(message, transfer ?? []),
|
|
10
|
+
});
|
|
11
|
+
scope.addEventListener("message", (event) => engine.handle(event.data));
|
package/package.json
CHANGED
|
@@ -1,6 +1,95 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webslm",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"author": "Maxime Golfier",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/maxgfr/webslm.git",
|
|
10
|
+
"directory": "packages/webslm"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://maxgfr.github.io/webslm/",
|
|
13
|
+
"bugs": "https://github.com/maxgfr/webslm/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"llm",
|
|
16
|
+
"slm",
|
|
17
|
+
"wasm",
|
|
18
|
+
"webassembly",
|
|
19
|
+
"safetensors",
|
|
20
|
+
"huggingface",
|
|
21
|
+
"browser",
|
|
22
|
+
"worker",
|
|
23
|
+
"opfs",
|
|
24
|
+
"language-model",
|
|
25
|
+
"chat",
|
|
26
|
+
"inference",
|
|
27
|
+
"node",
|
|
28
|
+
"bun",
|
|
29
|
+
"ai-sdk"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": [
|
|
33
|
+
"./dist/worker.js",
|
|
34
|
+
"./dist/node-worker.js",
|
|
35
|
+
"./dist/node-pool-worker.js",
|
|
36
|
+
"./dist/pool-worker.js"
|
|
37
|
+
],
|
|
38
|
+
"main": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
},
|
|
45
|
+
"./ai-sdk": {
|
|
46
|
+
"types": "./dist/ai-sdk/index.d.ts",
|
|
47
|
+
"default": "./dist/ai-sdk/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"wasm/simd/webslm_wasm.js",
|
|
54
|
+
"wasm/simd/webslm_wasm.d.ts",
|
|
55
|
+
"wasm/simd/webslm_wasm_bg.wasm",
|
|
56
|
+
"wasm/simd/webslm_wasm_bg.wasm.d.ts",
|
|
57
|
+
"wasm/relaxed/webslm_wasm.js",
|
|
58
|
+
"wasm/relaxed/webslm_wasm.d.ts",
|
|
59
|
+
"wasm/relaxed/webslm_wasm_bg.wasm",
|
|
60
|
+
"wasm/relaxed/webslm_wasm_bg.wasm.d.ts",
|
|
61
|
+
"wasm/threads/webslm_wasm.js",
|
|
62
|
+
"wasm/threads/webslm_wasm.d.ts",
|
|
63
|
+
"wasm/threads/webslm_wasm_bg.wasm",
|
|
64
|
+
"wasm/threads/webslm_wasm_bg.wasm.d.ts",
|
|
65
|
+
"wasm/threads/snippets"
|
|
66
|
+
],
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=20"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"@ai-sdk/provider": "^4.0.0",
|
|
72
|
+
"ai": "^7.0.0"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@ai-sdk/provider": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"ai": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"devDependencies": {
|
|
83
|
+
"@ai-sdk/provider": "^4.0.39",
|
|
84
|
+
"@types/node": "^26.6.11",
|
|
85
|
+
"@webgpu/types": "^0.1.74",
|
|
86
|
+
"ai": "^7.0.184",
|
|
87
|
+
"typescript": "^7.0.2",
|
|
88
|
+
"vitest": "^5.1.2"
|
|
89
|
+
},
|
|
90
|
+
"scripts": {
|
|
91
|
+
"build": "node scripts/wasm-flavours.mjs placeholders && node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
92
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
93
|
+
"test": "vitest run"
|
|
94
|
+
}
|
|
6
95
|
}
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checkpoint files served by JavaScript.
|
|
6
|
+
*
|
|
7
|
+
* `read(path, start?, end?)` returns (a promise of) a `Uint8Array` or an
|
|
8
|
+
* `ArrayBuffer` holding the whole file, or bytes `start..end` (end
|
|
9
|
+
* exclusive) when a range is given. A missing file is reported by
|
|
10
|
+
* resolving to `null`/`undefined` or by rejecting with an error whose
|
|
11
|
+
* `code` is `"NOT_FOUND"` (or whose `name` is `"NotFoundError"`, as OPFS
|
|
12
|
+
* throws). The optional `list()` returns the file names of the checkpoint.
|
|
13
|
+
*/
|
|
14
|
+
export class JsSource {
|
|
15
|
+
free(): void;
|
|
16
|
+
[Symbol.dispose](): void;
|
|
17
|
+
constructor(read: Function, list?: Function | null);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Incremental SHA-256.
|
|
22
|
+
*/
|
|
23
|
+
export class Sha256Hasher {
|
|
24
|
+
free(): void;
|
|
25
|
+
[Symbol.dispose](): void;
|
|
26
|
+
/**
|
|
27
|
+
* Lowercase hex digest of everything fed so far; resets the hasher.
|
|
28
|
+
*/
|
|
29
|
+
finish(): string;
|
|
30
|
+
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Feeds bytes.
|
|
33
|
+
*/
|
|
34
|
+
update(bytes: Uint8Array): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A loaded checkpoint, with a default session used by `chat` and
|
|
39
|
+
* `generate`.
|
|
40
|
+
*/
|
|
41
|
+
export class WasmModel {
|
|
42
|
+
private constructor();
|
|
43
|
+
free(): void;
|
|
44
|
+
[Symbol.dispose](): void;
|
|
45
|
+
/**
|
|
46
|
+
* Merges a PEFT LoRA adapter served by `lora` into the weights,
|
|
47
|
+
* replacing the adapter applied before (if any). `options_json`:
|
|
48
|
+
* `{ scale?: number }` (default 1). Resolves to the adapter's
|
|
49
|
+
* description (see [`LoraInfo`]); rejects with `INVALID_ADAPTER`,
|
|
50
|
+
* leaving the model unchanged, when the adapter does not fit the
|
|
51
|
+
* model. Sessions start over at their next call.
|
|
52
|
+
*/
|
|
53
|
+
applyAdapter(lora: JsSource, options_json: string): Promise<any>;
|
|
54
|
+
/**
|
|
55
|
+
* Answers a conversation in the default session; see
|
|
56
|
+
* [`WasmSession::chat`].
|
|
57
|
+
*/
|
|
58
|
+
chat(messages_json: string, options_json: string, on_delta: Function, on_prefill?: Function | null): Promise<any>;
|
|
59
|
+
/**
|
|
60
|
+
* Starts a new, empty session over the same weights.
|
|
61
|
+
*/
|
|
62
|
+
createSession(): WasmSession;
|
|
63
|
+
/**
|
|
64
|
+
* Decodes token ids into text.
|
|
65
|
+
*/
|
|
66
|
+
detokenize(ids: Uint32Array, skip_special_tokens: boolean): string;
|
|
67
|
+
/**
|
|
68
|
+
* Completes raw text in the default session; see
|
|
69
|
+
* [`WasmSession::generate`].
|
|
70
|
+
*/
|
|
71
|
+
generate(prompt: string, options_json: string, on_delta: Function, on_prefill?: Function | null): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Describes the model; see [`ModelInfo`].
|
|
74
|
+
*/
|
|
75
|
+
info(): any;
|
|
76
|
+
/**
|
|
77
|
+
* Loads a checkpoint from `source`. `options_json` is a JSON object:
|
|
78
|
+
* `{ format?: "q8" | "q4" | "q4_0" | "f32" | "f16" | "bf16",
|
|
79
|
+
* contextLength?: number, deterministic?: boolean,
|
|
80
|
+
* activations?: "quantized" | "f32", device?: "cpu" | "webgpu" | "auto" }`.
|
|
81
|
+
*
|
|
82
|
+
* `device` defaults to `"cpu"`. `"auto"` picks WebGPU when an adapter
|
|
83
|
+
* is available and the model has more than
|
|
84
|
+
* [`AUTO_GPU_MIN_PARAMETERS`] parameters. When WebGPU is wanted but
|
|
85
|
+
* the device cannot be created, the model loads on the CPU and
|
|
86
|
+
* `info().deviceNote` says why. `deterministic` runs on the CPU: GPU
|
|
87
|
+
* results depend on the adapter.
|
|
88
|
+
*
|
|
89
|
+
* `lora`, when given, serves a PEFT LoRA adapter (`adapter_config.json`
|
|
90
|
+
* and `adapter_model.safetensors`) merged into the weights as they
|
|
91
|
+
* load, at `adapterScale` (default 1).
|
|
92
|
+
*/
|
|
93
|
+
static load(source: JsSource, options_json: string, lora?: JsSource | null): Promise<WasmModel>;
|
|
94
|
+
/**
|
|
95
|
+
* Removes the adapter, restoring the base weights exactly. Resolves to
|
|
96
|
+
* the description of the adapter removed, or `null` when there was
|
|
97
|
+
* none.
|
|
98
|
+
*/
|
|
99
|
+
removeAdapter(): Promise<any>;
|
|
100
|
+
/**
|
|
101
|
+
* Renders a conversation (JSON array of `{ role, content }`) with the
|
|
102
|
+
* chat template, ending with the header of a new assistant turn.
|
|
103
|
+
* `kwargs_json` holds extra template variables, e.g.
|
|
104
|
+
* `{"enable_thinking": false}`.
|
|
105
|
+
*/
|
|
106
|
+
renderChat(messages_json: string, kwargs_json: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Clears the default session.
|
|
109
|
+
*/
|
|
110
|
+
reset(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Encodes text into token ids.
|
|
113
|
+
*/
|
|
114
|
+
tokenize(text: string, add_special_tokens: boolean): Uint32Array;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* An independent conversation (KV cache) over a model.
|
|
119
|
+
*/
|
|
120
|
+
export class WasmSession {
|
|
121
|
+
private constructor();
|
|
122
|
+
free(): void;
|
|
123
|
+
[Symbol.dispose](): void;
|
|
124
|
+
/**
|
|
125
|
+
* Answers a conversation: `messages_json` is a JSON array of
|
|
126
|
+
* `{ role, content }`, `options_json` a JSON object of generation
|
|
127
|
+
* options (`maxTokens`, `temperature`, `topK`, `topP`, `minP`,
|
|
128
|
+
* `repetitionPenalty`, `seed`, `stop`, `templateKwargs`,
|
|
129
|
+
* `ignoreStopTokens`). Turns already in the cache are not recomputed.
|
|
130
|
+
*
|
|
131
|
+
* Generation controls: `presencePenalty`, `frequencyPenalty`,
|
|
132
|
+
* `stopTokenIds`, `logprobs` (number of alternatives), `json`, `schema`,
|
|
133
|
+
* `thinkingBudget`, `loopDetection`, `contextShift`.
|
|
134
|
+
*
|
|
135
|
+
* `on_delta(text, tokenId, info)` runs after every token; `info` is
|
|
136
|
+
* `undefined` or `{ logprob, topLogprobs: [id, logprob][], forced }`.
|
|
137
|
+
* Returning `false` (or a promise resolving to `false`) stops the
|
|
138
|
+
* generation before the next token. `on_prefill(done, total)`, when
|
|
139
|
+
* given, runs after every piece of the prompt (128 tokens) and may stop
|
|
140
|
+
* it the same way. Resolves to `{ text, tokens, finishReason,
|
|
141
|
+
* promptTokens, reusedTokens, generatedTokens, droppedTokens, length }`;
|
|
142
|
+
* `finishReason` is `"stop"`, `"stop_string"`, `"length"`,
|
|
143
|
+
* `"context_full"`, `"loop"` or `"aborted"`.
|
|
144
|
+
*/
|
|
145
|
+
chat(messages_json: string, options_json: string, on_delta: Function, on_prefill?: Function | null): Promise<any>;
|
|
146
|
+
/**
|
|
147
|
+
* A new session holding a copy of this one's cache, to continue it in
|
|
148
|
+
* several directions without recomputing it. Fails on backends that
|
|
149
|
+
* cannot copy caches.
|
|
150
|
+
*/
|
|
151
|
+
fork(): WasmSession;
|
|
152
|
+
/**
|
|
153
|
+
* Completes raw text, without the chat template (`addSpecialTokens`
|
|
154
|
+
* in the options, default `true`, adds the tokenizer's BOS). Same
|
|
155
|
+
* callback and result as [`WasmSession::chat`].
|
|
156
|
+
*/
|
|
157
|
+
generate(prompt: string, options_json: string, on_delta: Function, on_prefill?: Function | null): Promise<any>;
|
|
158
|
+
/**
|
|
159
|
+
* Empties the cache.
|
|
160
|
+
*/
|
|
161
|
+
reset(): void;
|
|
162
|
+
/**
|
|
163
|
+
* Log-probabilities of several continuations of one prefix, the prefix
|
|
164
|
+
* computed once. `continuations_json` is a JSON array of token-id
|
|
165
|
+
* arrays. Resolves to an array of `Float32Array`, one log-probability
|
|
166
|
+
* per continuation token; the session then holds the prefix.
|
|
167
|
+
*/
|
|
168
|
+
scoreContinuations(prefix: Uint32Array, continuations_json: string): Promise<any>;
|
|
169
|
+
/**
|
|
170
|
+
* Teacher-forced pass: appends `ids` to the cache. `options_json`:
|
|
171
|
+
* `{ logits?: "all" | "last" | "none", hiddenStates?: number[] }`
|
|
172
|
+
* (default `"last"`). Hidden state `i` is the residual stream after
|
|
173
|
+
* layer `i` counted from 1, `0` the embedding output, all before the
|
|
174
|
+
* final norm (the `output_hidden_states` indexing of `transformers`).
|
|
175
|
+
*
|
|
176
|
+
* Resolves to `{ logits?: Float32Array, hidden: { [i]: Float32Array },
|
|
177
|
+
* positions, vocabSize, hiddenSize, length }`; arrays are row-major,
|
|
178
|
+
* one row per position.
|
|
179
|
+
*/
|
|
180
|
+
score(ids: Uint32Array, options_json: string): Promise<any>;
|
|
181
|
+
/**
|
|
182
|
+
* Context shift: drops `drop` cached positions after the first `keep`
|
|
183
|
+
* and recomputes the rest. Resolves to the new length.
|
|
184
|
+
*/
|
|
185
|
+
shiftContext(keep: number, drop: number): Promise<any>;
|
|
186
|
+
/**
|
|
187
|
+
* One decode step with a token chosen by the caller. `options_json`:
|
|
188
|
+
* `{ logits?: boolean, hiddenStates?: number[] }` (logits by default).
|
|
189
|
+
*/
|
|
190
|
+
step(id: number, options_json: string): Promise<any>;
|
|
191
|
+
/**
|
|
192
|
+
* The token ids in the cache.
|
|
193
|
+
*/
|
|
194
|
+
tokens(): Uint32Array;
|
|
195
|
+
/**
|
|
196
|
+
* Keeps the first `len` positions. Models with recurrent layers (LFM2
|
|
197
|
+
* and LFM3 convolutions, Qwen3.5 Gated DeltaNet, sliding-window ring
|
|
198
|
+
* buffers) recompute their state for those positions (a prefill of
|
|
199
|
+
* `len` tokens).
|
|
200
|
+
*/
|
|
201
|
+
truncate(len: number): void;
|
|
202
|
+
/**
|
|
203
|
+
* Largest number of positions the cache holds.
|
|
204
|
+
*/
|
|
205
|
+
readonly capacity: number;
|
|
206
|
+
/**
|
|
207
|
+
* Positions run through the network since the session was created
|
|
208
|
+
* (what prefix reuse and forking save).
|
|
209
|
+
*/
|
|
210
|
+
readonly computed: number;
|
|
211
|
+
/**
|
|
212
|
+
* Number of positions in the cache.
|
|
213
|
+
*/
|
|
214
|
+
readonly length: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* How this module was built: `{ flavour, kernels, threads }`. `flavour`
|
|
219
|
+
* is `"simd"`, `"relaxed"` (SIMD128 and relaxed SIMD) or `"threads"`
|
|
220
|
+
* (relaxed SIMD with atomics and a Web Worker pool); `kernels` the CPU
|
|
221
|
+
* kernel set; `threads` the size of the pool (1 until `startThreadPool`).
|
|
222
|
+
*/
|
|
223
|
+
export function buildInfo(): any;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Parses the header of a safetensors file.
|
|
227
|
+
*
|
|
228
|
+
* `bytes` must hold at least the 8-byte length prefix and the whole JSON
|
|
229
|
+
* header. Returns a plain object
|
|
230
|
+
* `{ headerLen, dataStart, tensors: { [name]: { name, dtype, shape, dataOffsets } } }`
|
|
231
|
+
* and throws an `Error` if the header is malformed.
|
|
232
|
+
*/
|
|
233
|
+
export function parseSafetensorsHeader(bytes: Uint8Array): any;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* `model_type` values (from `config.json`) of the architectures this build
|
|
237
|
+
* can run.
|
|
238
|
+
*/
|
|
239
|
+
export function supportedModelTypes(): string[];
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Version of the Rust engine, as declared in `Cargo.toml`.
|
|
243
|
+
*/
|
|
244
|
+
export function version(): string;
|
|
245
|
+
|
|
246
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
247
|
+
|
|
248
|
+
export interface InitOutput {
|
|
249
|
+
readonly memory: WebAssembly.Memory;
|
|
250
|
+
readonly __wbg_jssource_free: (a: number, b: number) => void;
|
|
251
|
+
readonly __wbg_sha256hasher_free: (a: number, b: number) => void;
|
|
252
|
+
readonly __wbg_wasmmodel_free: (a: number, b: number) => void;
|
|
253
|
+
readonly __wbg_wasmsession_free: (a: number, b: number) => void;
|
|
254
|
+
readonly buildInfo: () => [number, number, number];
|
|
255
|
+
readonly jssource_new: (a: any, b: number) => number;
|
|
256
|
+
readonly parseSafetensorsHeader: (a: number, b: number) => [number, number, number];
|
|
257
|
+
readonly sha256hasher_finish: (a: number) => [number, number];
|
|
258
|
+
readonly sha256hasher_new: () => number;
|
|
259
|
+
readonly sha256hasher_update: (a: number, b: number, c: number) => void;
|
|
260
|
+
readonly supportedModelTypes: () => [number, number];
|
|
261
|
+
readonly version: () => [number, number];
|
|
262
|
+
readonly wasmmodel_applyAdapter: (a: number, b: number, c: number, d: number) => any;
|
|
263
|
+
readonly wasmmodel_chat: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
264
|
+
readonly wasmmodel_createSession: (a: number) => [number, number, number];
|
|
265
|
+
readonly wasmmodel_detokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
266
|
+
readonly wasmmodel_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
267
|
+
readonly wasmmodel_info: (a: number) => [number, number, number];
|
|
268
|
+
readonly wasmmodel_load: (a: number, b: number, c: number, d: number) => any;
|
|
269
|
+
readonly wasmmodel_removeAdapter: (a: number) => any;
|
|
270
|
+
readonly wasmmodel_renderChat: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
271
|
+
readonly wasmmodel_reset: (a: number) => [number, number];
|
|
272
|
+
readonly wasmmodel_tokenize: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
273
|
+
readonly wasmsession_capacity: (a: number) => [number, number, number];
|
|
274
|
+
readonly wasmsession_chat: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
275
|
+
readonly wasmsession_computed: (a: number) => [number, number, number];
|
|
276
|
+
readonly wasmsession_fork: (a: number) => [number, number, number];
|
|
277
|
+
readonly wasmsession_generate: (a: number, b: number, c: number, d: number, e: number, f: any, g: number) => any;
|
|
278
|
+
readonly wasmsession_length: (a: number) => number;
|
|
279
|
+
readonly wasmsession_reset: (a: number) => [number, number];
|
|
280
|
+
readonly wasmsession_score: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
281
|
+
readonly wasmsession_scoreContinuations: (a: number, b: number, c: number, d: number, e: number) => any;
|
|
282
|
+
readonly wasmsession_shiftContext: (a: number, b: number, c: number) => any;
|
|
283
|
+
readonly wasmsession_step: (a: number, b: number, c: number, d: number) => any;
|
|
284
|
+
readonly wasmsession_tokens: (a: number) => [number, number, number, number];
|
|
285
|
+
readonly wasmsession_truncate: (a: number, b: number) => [number, number];
|
|
286
|
+
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;
|
|
287
|
+
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];
|
|
288
|
+
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];
|
|
289
|
+
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__37: (a: number, b: number, c: any) => [number, number];
|
|
290
|
+
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__38: (a: number, b: number, c: any) => [number, number];
|
|
291
|
+
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true_: (a: number, b: number, c: any) => void;
|
|
292
|
+
readonly wasm_bindgen_8cf186fa7724d16d___convert__closures_____invoke___wgpu_54917290532eaf6b___backend__webgpu__webgpu_sys__gen_GpuDeviceLostInfo__GpuDeviceLostInfo______true__36: (a: number, b: number, c: any) => void;
|
|
293
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
294
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
295
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
296
|
+
readonly __externref_table_alloc: () => number;
|
|
297
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
298
|
+
readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
|
|
299
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
300
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
301
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
302
|
+
readonly __wbindgen_start: () => void;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
309
|
+
* a precompiled `WebAssembly.Module`.
|
|
310
|
+
*
|
|
311
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
312
|
+
*
|
|
313
|
+
* @returns {InitOutput}
|
|
314
|
+
*/
|
|
315
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
319
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
320
|
+
*
|
|
321
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
322
|
+
*
|
|
323
|
+
* @returns {Promise<InitOutput>}
|
|
324
|
+
*/
|
|
325
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|