kjarni-wasm 0.2.6 → 0.2.7
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 +1 -1
- package/dist/index.d.ts +18 -3
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +9 -0
- package/package.json +2 -2
- package/pkg/kjarni_wasm.d.ts +9 -9
- package/pkg/kjarni_wasm.js +22 -22
- package/pkg/kjarni_wasm_bg.wasm +0 -0
- package/pkg/kjarni_wasm_bg.wasm.d.ts +2 -2
- package/pkg/package.json +2 -2
package/README.md
CHANGED
|
@@ -224,6 +224,6 @@ you need the server half of the same product:
|
|
|
224
224
|
|
|
225
225
|
## Making your own `.kjq`
|
|
226
226
|
|
|
227
|
-
See [the format guide](
|
|
227
|
+
See [the format guide](https://github.com/olafurjohannsson/kjarni/blob/main/crates/kjarni-wasm/scripts/README.md). Any BERT-family encoder,
|
|
228
228
|
cross-encoder, classifier or small decoder from Hugging Face converts with one
|
|
229
229
|
script.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Capability, ClassifyResult, ModelSource, RankedDocument } from "./protocol.js";
|
|
2
|
-
export type { ClassifyResult, ModelSource, RankedDocument };
|
|
2
|
+
export type { Capability, ClassifyResult, ModelSource, RankedDocument };
|
|
3
|
+
/** Which models {@link Kjarni.load} loads. Name only the ones you need. */
|
|
3
4
|
export interface LoadOptions {
|
|
4
5
|
/** Embeddings and semantic similarity. A `.kjq` file. */
|
|
5
6
|
encoder?: ModelSource;
|
|
@@ -14,11 +15,23 @@ export interface LoadOptions {
|
|
|
14
15
|
/** Called as each model is fetched, for progress UI. */
|
|
15
16
|
onProgress?: (capability: Capability, loaded: number, total: number) => void;
|
|
16
17
|
}
|
|
18
|
+
/** How {@link Kjarni.chat} generates a reply. */
|
|
17
19
|
export interface ChatOptions {
|
|
20
|
+
/** The most tokens to generate. Defaults to 256. */
|
|
18
21
|
maxNewTokens?: number;
|
|
19
|
-
/** 0
|
|
22
|
+
/** Sampling temperature. Defaults to 0, greedy decoding, which is deterministic. */
|
|
20
23
|
temperature?: number;
|
|
21
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Models running in a Web Worker. Create one with {@link Kjarni.load}; every
|
|
27
|
+
* method returns a promise, so the page stays responsive while a model works.
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const kjarni = await Kjarni.load({ encoder: "/models/minilm.kjq" });
|
|
31
|
+
* const [a, b] = await kjarni.encode(["doctor", "physician"]);
|
|
32
|
+
* console.log(Kjarni.cosine(a, b)); // 0.8598
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
22
35
|
export declare class Kjarni {
|
|
23
36
|
#private;
|
|
24
37
|
private constructor();
|
|
@@ -39,7 +52,9 @@ export declare class Kjarni {
|
|
|
39
52
|
/**
|
|
40
53
|
* Generates a reply, yielding text as it arrives.
|
|
41
54
|
*
|
|
42
|
-
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* for await (const piece of kjarni.chat("Explain RAG")) out.textContent += piece;
|
|
57
|
+
* ```
|
|
43
58
|
*/
|
|
44
59
|
chat(prompt: string, options?: ChatOptions): AsyncGenerator<string, void, unknown>;
|
|
45
60
|
/** Releases the models and stops the worker. */
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,16 @@ async function toBytes(src, capability, onProgress) {
|
|
|
41
41
|
}
|
|
42
42
|
return bytes;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Models running in a Web Worker. Create one with {@link Kjarni.load}; every
|
|
46
|
+
* method returns a promise, so the page stays responsive while a model works.
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* const kjarni = await Kjarni.load({ encoder: "/models/minilm.kjq" });
|
|
50
|
+
* const [a, b] = await kjarni.encode(["doctor", "physician"]);
|
|
51
|
+
* console.log(Kjarni.cosine(a, b)); // 0.8598
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
44
54
|
export class Kjarni {
|
|
45
55
|
#worker;
|
|
46
56
|
#next = 1;
|
|
@@ -116,7 +126,9 @@ export class Kjarni {
|
|
|
116
126
|
/**
|
|
117
127
|
* Generates a reply, yielding text as it arrives.
|
|
118
128
|
*
|
|
119
|
-
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* for await (const piece of kjarni.chat("Explain RAG")) out.textContent += piece;
|
|
131
|
+
* ```
|
|
120
132
|
*/
|
|
121
133
|
async *chat(prompt, options = {}) {
|
|
122
134
|
const queue = [];
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,yEAAyE;AACzE,iEAAiE;AACjE,kDAAkD;AAClD,EAAE;AACF,+EAA+E;AAC/E,2DAA2D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,EAAE;AACF,yEAAyE;AACzE,iEAAiE;AACjE,kDAAkD;AAClD,EAAE;AACF,+EAA+E;AAC/E,2DAA2D;AAqC3D,KAAK,UAAU,OAAO,CACpB,GAAgB,EAChB,UAAsB,EACtB,UAAsC;IAEtC,IAAI,GAAG,YAAY,UAAU;QAAE,OAAO,GAAG,CAAC;IAC1C,IAAI,GAAG,YAAY,WAAW;QAAE,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAE3D,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,YAAY,GAAG,iBAAiB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,8EAA8E;IAC9E,2EAA2E;IAC3E,kDAAkD;IAClD,M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,CAAC,CAAC,CAAC;YACnB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAClB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,CAAC;IACvD,CAAC;CACF;AAED,eAAe,MAAM,CAAC"}
|
package/dist/protocol.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
/** A model to load, either already in memory or somewhere to fetch it from. */
|
|
2
2
|
export type ModelSource = string | URL | ArrayBuffer | Uint8Array;
|
|
3
|
+
/** A kind of model a {@link Kjarni} instance can hold, one of each. */
|
|
3
4
|
export type Capability = "encoder" | "classifier" | "reranker" | "chat";
|
|
5
|
+
/** The top prediction for one text. */
|
|
4
6
|
export interface ClassifyResult {
|
|
7
|
+
/** The predicted label, for example "POSITIVE". */
|
|
5
8
|
label: string;
|
|
9
|
+
/** Its probability, from 0 to 1. */
|
|
6
10
|
score: number;
|
|
11
|
+
/** The label's position in the model's label list. */
|
|
7
12
|
index: number;
|
|
8
13
|
}
|
|
14
|
+
/** One document after reranking. */
|
|
9
15
|
export interface RankedDocument {
|
|
16
|
+
/** Its position in the list that was passed in. */
|
|
10
17
|
index: number;
|
|
18
|
+
/** The cross-encoder's raw score; higher is more relevant. */
|
|
11
19
|
score: number;
|
|
20
|
+
/** The document text. */
|
|
12
21
|
text: string;
|
|
13
22
|
}
|
|
14
23
|
export type Request = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kjarni-wasm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "Local AI inference in the browser: embeddings, classification, reranking, semantic search and chat, running in a Web Worker.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "^5.6.0"
|
|
26
26
|
},
|
|
27
|
-
"license": "MIT",
|
|
27
|
+
"license": "MIT OR Apache-2.0",
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
30
|
"url": "git+https://github.com/olafurjohannsson/kjarni.git",
|
package/pkg/kjarni_wasm.d.ts
CHANGED
|
@@ -82,13 +82,6 @@ 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;
|
|
92
85
|
/**
|
|
93
86
|
* Classify one text, returning every label with its score, highest first.
|
|
94
87
|
*
|
|
@@ -97,6 +90,13 @@ export class WasmClassifier {
|
|
|
97
90
|
* what makes the behaviour testable on the host.
|
|
98
91
|
*/
|
|
99
92
|
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
|
*/
|
|
@@ -250,8 +250,8 @@ 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_5727: (a: number, b: number, c: number, d: number) => void;
|
|
254
|
+
readonly __wasm_bindgen_func_elem_5745: (a: number, b: number, c: number, d: number) => 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
257
|
readonly __wbindgen_export3: (a: number) => void;
|
package/pkg/kjarni_wasm.js
CHANGED
|
@@ -248,19 +248,20 @@ export class WasmClassifier {
|
|
|
248
248
|
wasm.__wbg_wasmclassifier_free(ptr, 0);
|
|
249
249
|
}
|
|
250
250
|
/**
|
|
251
|
-
* Classify
|
|
251
|
+
* Classify one text, returning every label with its score, highest first.
|
|
252
252
|
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
253
|
+
* Serializing to a `JsValue` panics outside wasm32, so the work lives in
|
|
254
|
+
* [`WasmClassifier::classify_core`] and this is only the conversion. That is
|
|
255
|
+
* what makes the behaviour testable on the host.
|
|
256
|
+
* @param {string} text
|
|
256
257
|
* @returns {any}
|
|
257
258
|
*/
|
|
258
|
-
|
|
259
|
+
classify(text) {
|
|
259
260
|
try {
|
|
260
261
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
261
|
-
const ptr0 =
|
|
262
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
262
263
|
const len0 = WASM_VECTOR_LEN;
|
|
263
|
-
wasm.
|
|
264
|
+
wasm.wasmclassifier_classify(retptr, this.__wbg_ptr, ptr0, len0);
|
|
264
265
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
265
266
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
266
267
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -273,20 +274,19 @@ export class WasmClassifier {
|
|
|
273
274
|
}
|
|
274
275
|
}
|
|
275
276
|
/**
|
|
276
|
-
* Classify
|
|
277
|
+
* Classify a batch, returning the single best label for each input.
|
|
277
278
|
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
* @param {string} text
|
|
279
|
+
* One result per input, in input order, so the caller can line them up with
|
|
280
|
+
* whatever it passed in.
|
|
281
|
+
* @param {string[]} texts
|
|
282
282
|
* @returns {any}
|
|
283
283
|
*/
|
|
284
|
-
|
|
284
|
+
classify_batch(texts) {
|
|
285
285
|
try {
|
|
286
286
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
287
|
-
const ptr0 =
|
|
287
|
+
const ptr0 = passArrayJsValueToWasm0(texts, wasm.__wbindgen_export);
|
|
288
288
|
const len0 = WASM_VECTOR_LEN;
|
|
289
|
-
wasm.
|
|
289
|
+
wasm.wasmclassifier_classify_batch(retptr, this.__wbg_ptr, ptr0, len0);
|
|
290
290
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
291
291
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
292
292
|
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
@@ -1109,7 +1109,7 @@ function __wbg_get_imports() {
|
|
|
1109
1109
|
const a = state0.a;
|
|
1110
1110
|
state0.a = 0;
|
|
1111
1111
|
try {
|
|
1112
|
-
return
|
|
1112
|
+
return __wasm_bindgen_func_elem_5745(a, state0.b, arg0, arg1);
|
|
1113
1113
|
} finally {
|
|
1114
1114
|
state0.a = a;
|
|
1115
1115
|
}
|
|
@@ -1223,8 +1223,8 @@ function __wbg_get_imports() {
|
|
|
1223
1223
|
return addHeapObject(ret);
|
|
1224
1224
|
},
|
|
1225
1225
|
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
1226
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
1227
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
1226
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 2088, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
1227
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_5727);
|
|
1228
1228
|
return addHeapObject(ret);
|
|
1229
1229
|
},
|
|
1230
1230
|
__wbindgen_generic_0000000000000002: function(arg0) {
|
|
@@ -1261,14 +1261,14 @@ function __wbg_get_imports() {
|
|
|
1261
1261
|
};
|
|
1262
1262
|
}
|
|
1263
1263
|
|
|
1264
|
-
function
|
|
1265
|
-
wasm.
|
|
1264
|
+
function __wasm_bindgen_func_elem_5745(arg0, arg1, arg2, arg3) {
|
|
1265
|
+
wasm.__wasm_bindgen_func_elem_5745(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
1266
1266
|
}
|
|
1267
1267
|
|
|
1268
|
-
function
|
|
1268
|
+
function __wasm_bindgen_func_elem_5727(arg0, arg1, arg2) {
|
|
1269
1269
|
try {
|
|
1270
1270
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
1271
|
-
wasm.
|
|
1271
|
+
wasm.__wasm_bindgen_func_elem_5727(retptr, arg0, arg1, addHeapObject(arg2));
|
|
1272
1272
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
1273
1273
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
1274
1274
|
if (r1) {
|
package/pkg/kjarni_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -47,8 +47,8 @@ export const wasmsearch_search: (a: number, b: number, c: number, d: number, e:
|
|
|
47
47
|
export const wasmsearch_search_keywords: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
48
48
|
export const wasmsearch_search_semantic: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
49
49
|
export const wasmsearch_update_file: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
50
|
-
export const
|
|
51
|
-
export const
|
|
50
|
+
export const __wasm_bindgen_func_elem_5727: (a: number, b: number, c: number, d: number) => void;
|
|
51
|
+
export const __wasm_bindgen_func_elem_5745: (a: number, b: number, c: number, d: number) => void;
|
|
52
52
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
53
53
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
54
54
|
export const __wbindgen_export3: (a: number) => void;
|
package/pkg/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"Ólafur Aron Jóhannsson <olafurjohannss@gmail.com>"
|
|
6
6
|
],
|
|
7
7
|
"description": "Local AI inference in the browser: embeddings, classification, reranking, semantic search and chat, compiled to WebAssembly.",
|
|
8
|
-
"version": "0.2.
|
|
9
|
-
"license": "MIT",
|
|
8
|
+
"version": "0.2.7",
|
|
9
|
+
"license": "MIT OR Apache-2.0",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/olafurjohannsson/kjarni"
|