kjarni-wasm 0.2.7 → 0.2.9
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 +8 -4
- package/package.json +2 -2
- package/pkg/kjarni_wasm.d.ts +29 -25
- package/pkg/kjarni_wasm.js +507 -442
- package/pkg/kjarni_wasm_bg.wasm +0 -0
- package/pkg/kjarni_wasm_bg.wasm.d.ts +12 -8
- package/pkg/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# kjarni-wasm
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
**Run transformer models inside your web page. Same output as PyTorch, no server.**
|
|
4
|
+
|
|
5
|
+
Kjarni is a transformer inference library, and this is its WebAssembly build:
|
|
6
|
+
embeddings, classification, reranking, semantic search and chat in the browser,
|
|
7
|
+
running in a Web Worker so the page never freezes. The same engine ships for
|
|
8
|
+
Python, C#, Go, C++ and Rust.
|
|
5
9
|
|
|
6
10
|
```bash
|
|
7
11
|
npm i kjarni-wasm
|
|
@@ -11,7 +15,7 @@ Or without a bundler, straight from a CDN:
|
|
|
11
15
|
|
|
12
16
|
```html
|
|
13
17
|
<script type="module">
|
|
14
|
-
import { Kjarni } from "https://cdn.jsdelivr.net/npm/kjarni-wasm@0.
|
|
18
|
+
import { Kjarni } from "https://cdn.jsdelivr.net/npm/kjarni-wasm@0.2/dist/index.js";
|
|
15
19
|
</script>
|
|
16
20
|
```
|
|
17
21
|
|
|
@@ -32,7 +36,7 @@ server will do.
|
|
|
32
36
|
```html
|
|
33
37
|
<pre id="out">starting…</pre>
|
|
34
38
|
<script type="module">
|
|
35
|
-
import init, { WasmModel } from "https://cdn.jsdelivr.net/npm/kjarni-wasm@0.
|
|
39
|
+
import init, { WasmModel } from "https://cdn.jsdelivr.net/npm/kjarni-wasm@0.2/pkg/kjarni_wasm.js";
|
|
36
40
|
await init();
|
|
37
41
|
|
|
38
42
|
const url = "https://huggingface.co/olafuraron/all-MiniLM-L6-v2-q8/resolve/main/all-MiniLM-L6-v2-q8.kjq";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kjarni-wasm",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.9",
|
|
4
|
+
"description": "Run transformer models inside your web page: embeddings, classification, reranking, semantic search and chat in a Web Worker. Same output as PyTorch, no server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
package/pkg/kjarni_wasm.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ export class WasmChat {
|
|
|
60
60
|
* `model_id` selects the chat template, e.g. `qwen2.5-0.5b-instruct`. Without
|
|
61
61
|
* one the model still generates, but its turn markers will not be applied.
|
|
62
62
|
*/
|
|
63
|
-
static load(data: Uint8Array, model_id?: string | null): WasmChat;
|
|
63
|
+
static load(data: Uint8Array | number[], model_id?: string | null): WasmChat;
|
|
64
64
|
/**
|
|
65
65
|
* Sends a message in an ongoing conversation, streaming the reply.
|
|
66
66
|
*
|
|
@@ -82,6 +82,13 @@ export class WasmClassifier {
|
|
|
82
82
|
private constructor();
|
|
83
83
|
free(): void;
|
|
84
84
|
[Symbol.dispose](): void;
|
|
85
|
+
/**
|
|
86
|
+
* Classify a batch, returning the single best label for each input.
|
|
87
|
+
*
|
|
88
|
+
* One result per input, in input order, so the caller can line them up with
|
|
89
|
+
* whatever it passed in.
|
|
90
|
+
*/
|
|
91
|
+
classify_batch(texts: string[]): any;
|
|
85
92
|
/**
|
|
86
93
|
* Classify one text, returning every label with its score, highest first.
|
|
87
94
|
*
|
|
@@ -90,13 +97,6 @@ export class WasmClassifier {
|
|
|
90
97
|
* what makes the behaviour testable on the host.
|
|
91
98
|
*/
|
|
92
99
|
classify(text: string): any;
|
|
93
|
-
/**
|
|
94
|
-
* Classify a batch, returning the single best label for each input.
|
|
95
|
-
*
|
|
96
|
-
* One result per input, in input order, so the caller can line them up with
|
|
97
|
-
* whatever it passed in.
|
|
98
|
-
*/
|
|
99
|
-
classify_batch(texts: string[]): any;
|
|
100
100
|
/**
|
|
101
101
|
* The labels this model predicts, in index order.
|
|
102
102
|
*/
|
|
@@ -104,7 +104,7 @@ export class WasmClassifier {
|
|
|
104
104
|
/**
|
|
105
105
|
* Load a classifier from a `.kjq` container.
|
|
106
106
|
*/
|
|
107
|
-
static load(data: Uint8Array): WasmClassifier;
|
|
107
|
+
static load(data: Uint8Array | number[]): WasmClassifier;
|
|
108
108
|
/**
|
|
109
109
|
* How many labels the model predicts.
|
|
110
110
|
*/
|
|
@@ -116,18 +116,18 @@ export class WasmEncoder {
|
|
|
116
116
|
free(): void;
|
|
117
117
|
[Symbol.dispose](): void;
|
|
118
118
|
encode_file(text: string, source_path: string): any;
|
|
119
|
-
static new(model_data: Uint8Array): WasmEncoder;
|
|
119
|
+
static new(model_data: Uint8Array | number[]): WasmEncoder;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
export class WasmIndexBuilder {
|
|
123
123
|
private constructor();
|
|
124
124
|
free(): void;
|
|
125
125
|
[Symbol.dispose](): void;
|
|
126
|
-
add_chunk(text: string, embedding: Float32Array, source: string, chunk_index: number): void;
|
|
126
|
+
add_chunk(text: string, embedding: Float32Array | number[], source: string, chunk_index: number): void;
|
|
127
127
|
add_file(text: string, source_path: string): number;
|
|
128
128
|
doc_count(): number;
|
|
129
129
|
finish(): Uint8Array;
|
|
130
|
-
static new(model_data: Uint8Array): WasmIndexBuilder;
|
|
130
|
+
static new(model_data: Uint8Array | number[]): WasmIndexBuilder;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
export class WasmModel {
|
|
@@ -145,7 +145,7 @@ export class WasmModel {
|
|
|
145
145
|
/**
|
|
146
146
|
* Load from a `.kjq` container: config, tokenizer and int8 tensors in one file.
|
|
147
147
|
*/
|
|
148
|
-
static from_quantized(data: Uint8Array): WasmModel;
|
|
148
|
+
static from_quantized(data: Uint8Array | number[]): WasmModel;
|
|
149
149
|
/**
|
|
150
150
|
* Fetch a model straight from Hugging Face. Browser-only: it uses `fetch`.
|
|
151
151
|
*/
|
|
@@ -153,7 +153,7 @@ export class WasmModel {
|
|
|
153
153
|
/**
|
|
154
154
|
* Load from raw safetensors plus its config and tokenizer.
|
|
155
155
|
*/
|
|
156
|
-
constructor(weights_data: Uint8Array, config_json: string, tokenizer_json: string);
|
|
156
|
+
constructor(weights_data: Uint8Array | number[], config_json: string, tokenizer_json: string);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
export enum WasmModelType {
|
|
@@ -169,7 +169,7 @@ export class WasmReranker {
|
|
|
169
169
|
*
|
|
170
170
|
* The engine's `CrossEncoder` loads the classifier head as part of the model.
|
|
171
171
|
*/
|
|
172
|
-
static load(data: Uint8Array): WasmReranker;
|
|
172
|
+
static load(data: Uint8Array | number[]): WasmReranker;
|
|
173
173
|
/**
|
|
174
174
|
* Score every document against the query and return the best `limit`,
|
|
175
175
|
* highest first. Scores are raw logits, so negative values are normal.
|
|
@@ -185,9 +185,9 @@ export class WasmSearch {
|
|
|
185
185
|
private constructor();
|
|
186
186
|
free(): void;
|
|
187
187
|
[Symbol.dispose](): void;
|
|
188
|
-
add_chunk(text: string, embedding: Float32Array, source: string, chunk_index: number): void;
|
|
188
|
+
add_chunk(text: string, embedding: Float32Array | number[], source: string, chunk_index: number): void;
|
|
189
189
|
doc_count(): number;
|
|
190
|
-
static load(model_data: Uint8Array, index_data: Uint8Array): WasmSearch;
|
|
190
|
+
static load(model_data: Uint8Array | number[], index_data: Uint8Array | number[]): WasmSearch;
|
|
191
191
|
remove_file(source_path: string): number;
|
|
192
192
|
save_index(): Uint8Array;
|
|
193
193
|
search(query: string, limit: number): any;
|
|
@@ -217,11 +217,11 @@ export interface InitOutput {
|
|
|
217
217
|
readonly wasmchat_context_size: (a: number) => number;
|
|
218
218
|
readonly wasmchat_enablePrefixCache: (a: number, b: number, c: number) => void;
|
|
219
219
|
readonly wasmchat_generate: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
220
|
-
readonly wasmchat_generate_stream: (a: number, b: number, c: number, d: number, e: number, f: number, g:
|
|
220
|
+
readonly wasmchat_generate_stream: (a: number, b: number, c: number, d: number, e: number, f: number, g: any) => void;
|
|
221
221
|
readonly wasmchat_hasPrefixCache: (a: number) => number;
|
|
222
222
|
readonly wasmchat_history_len: (a: number) => number;
|
|
223
223
|
readonly wasmchat_load: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
224
|
-
readonly wasmchat_send_stream: (a: number, b: number, c: number, d: number, e: number, f: number, g:
|
|
224
|
+
readonly wasmchat_send_stream: (a: number, b: number, c: number, d: number, e: number, f: number, g: any) => void;
|
|
225
225
|
readonly wasmclassifier_classify: (a: number, b: number, c: number, d: number) => void;
|
|
226
226
|
readonly wasmclassifier_classify_batch: (a: number, b: number, c: number, d: number) => void;
|
|
227
227
|
readonly wasmclassifier_labels: (a: number, b: number) => void;
|
|
@@ -236,7 +236,7 @@ export interface InitOutput {
|
|
|
236
236
|
readonly wasmindexbuilder_new: (a: number, b: number, c: number) => void;
|
|
237
237
|
readonly wasmmodel_encode: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
238
238
|
readonly wasmmodel_from_quantized: (a: number, b: number, c: number) => void;
|
|
239
|
-
readonly wasmmodel_from_type: (a: number) =>
|
|
239
|
+
readonly wasmmodel_from_type: (a: number) => any;
|
|
240
240
|
readonly wasmmodel_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
241
241
|
readonly wasmreranker_load: (a: number, b: number, c: number) => void;
|
|
242
242
|
readonly wasmreranker_rerank: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
@@ -250,14 +250,18 @@ export interface InitOutput {
|
|
|
250
250
|
readonly wasmsearch_search_keywords: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
251
251
|
readonly wasmsearch_search_semantic: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
252
252
|
readonly wasmsearch_update_file: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
253
|
-
readonly
|
|
254
|
-
readonly
|
|
253
|
+
readonly __wasm_bindgen_func_elem_5740: (a: number, b: number, c: number, d: any) => void;
|
|
254
|
+
readonly __wasm_bindgen_func_elem_5769: (a: number, b: number, c: any, d: any) => void;
|
|
255
255
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
256
256
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
257
|
-
readonly __wbindgen_export3: (a: number) => void;
|
|
258
|
-
readonly __wbindgen_export4: (a: number
|
|
259
|
-
readonly __wbindgen_export5: (
|
|
257
|
+
readonly __wbindgen_export3: (a: number, b: number, c: number) => void;
|
|
258
|
+
readonly __wbindgen_export4: (a: number) => void;
|
|
259
|
+
readonly __wbindgen_export5: () => number;
|
|
260
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
261
|
+
readonly __wbindgen_export6: (a: number, b: number) => void;
|
|
260
262
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
263
|
+
readonly __wbindgen_export7: (a: number) => void;
|
|
264
|
+
readonly __wbindgen_export8: (a: number, b: number) => void;
|
|
261
265
|
readonly __wbindgen_start: () => void;
|
|
262
266
|
}
|
|
263
267
|
|