@flaxia/node 0.6.0 → 0.7.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 +2 -0
- package/dist/assets/ai-inference.js +83 -175
- package/dist/assets/ai-model-registry.js +127 -0
- package/dist/assets/cc-extract.js +5166 -0
- package/dist/assets/decision.js +142 -0
- package/dist/assets/embed-gemma.js +97 -0
- package/dist/assets/transformers.web.js +2 -2
- package/dist/assets/vector-embed.js +136 -26
- package/dist/assets/webgpuProbe.js +83 -66
- package/dist/client/SignalingClient.d.ts.map +1 -1
- package/dist/client/light-preloader.d.ts +19 -5
- package/dist/client/light-preloader.d.ts.map +1 -1
- package/dist/consent/notice.d.ts +3 -1
- package/dist/consent/notice.d.ts.map +1 -1
- package/dist/executor/WorkerPool.d.ts +1 -0
- package/dist/executor/WorkerPool.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +392 -365
- package/dist/worker.js +130 -121
- package/dist/workloads/__tests__/ai-model-registry.test.d.ts +2 -0
- package/dist/workloads/__tests__/ai-model-registry.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/cc-extract.test.d.ts +2 -0
- package/dist/workloads/__tests__/cc-extract.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/decision.test.d.ts +2 -0
- package/dist/workloads/__tests__/decision.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/embed-gemma.test.d.ts +2 -0
- package/dist/workloads/__tests__/embed-gemma.test.d.ts.map +1 -0
- package/dist/workloads/__tests__/wasm-threads.test.d.ts.map +1 -1
- package/dist/workloads/ai-inference.d.ts +30 -2
- package/dist/workloads/ai-inference.d.ts.map +1 -1
- package/dist/workloads/ai-model-registry.d.ts.map +1 -1
- package/dist/workloads/cc-extract.d.ts +11 -0
- package/dist/workloads/cc-extract.d.ts.map +1 -0
- package/dist/workloads/decision.d.ts +21 -0
- package/dist/workloads/decision.d.ts.map +1 -0
- package/dist/workloads/embed-gemma.d.ts +8 -0
- package/dist/workloads/embed-gemma.d.ts.map +1 -0
- package/dist/workloads/vector-embed.d.ts +10 -0
- package/dist/workloads/vector-embed.d.ts.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -170,6 +170,8 @@ initFlaxiaNode({ /* ... */ })
|
|
|
170
170
|
| `image-process` | `workloads/image-process.ts` | OffscreenCanvas API |
|
|
171
171
|
| `container` | `workloads/container.ts` | container2wasm + WASI |
|
|
172
172
|
| `nudenet` | `workloads/nudenet.ts` | NSFW(成人向け)画像判定 |
|
|
173
|
+
| `cc-extract` | `workloads/cc-extract.ts` | Common Crawl WARC の range 取得 + parse5 本文抽出 |
|
|
174
|
+
| `embed-gemma` | `workloads/embed-gemma.ts` | EmbeddingGemma 2(text-only, MRL) |
|
|
173
175
|
|
|
174
176
|
## フロー
|
|
175
177
|
|
|
@@ -1,117 +1,8 @@
|
|
|
1
1
|
import { t as e } from "./chunk.js";
|
|
2
|
-
import {
|
|
2
|
+
import { L as t, y as n } from "./webgpuProbe.js";
|
|
3
3
|
import { n as r, r as i, t as a } from "./transformers.web.js";
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
"Xenova/bert-base-multilingual-uncased-sentiment": {
|
|
7
|
-
repo: "Xenova/bert-base-multilingual-uncased-sentiment",
|
|
8
|
-
revision: "main",
|
|
9
|
-
maxBytes: o
|
|
10
|
-
},
|
|
11
|
-
"onnx-community/Qwen3-Embedding-0.6B-ONNX": {
|
|
12
|
-
repo: "onnx-community/Qwen3-Embedding-0.6B-ONNX",
|
|
13
|
-
revision: "main",
|
|
14
|
-
maxBytes: o
|
|
15
|
-
},
|
|
16
|
-
"Xenova/m2m100_418M": {
|
|
17
|
-
repo: "Xenova/m2m100_418M",
|
|
18
|
-
revision: "main",
|
|
19
|
-
maxBytes: o
|
|
20
|
-
}
|
|
21
|
-
}).map(([e, t]) => [e, { ...t }])), l = [
|
|
22
|
-
"wasm",
|
|
23
|
-
"cpu",
|
|
24
|
-
"webgpu"
|
|
25
|
-
], u = [
|
|
26
|
-
"q4",
|
|
27
|
-
"q4f16",
|
|
28
|
-
"q8",
|
|
29
|
-
"int8",
|
|
30
|
-
"uint8"
|
|
31
|
-
], d = {
|
|
32
|
-
max_new_tokens: {
|
|
33
|
-
min: 1,
|
|
34
|
-
max: 1024
|
|
35
|
-
},
|
|
36
|
-
temperature: {
|
|
37
|
-
min: 0,
|
|
38
|
-
max: 4
|
|
39
|
-
},
|
|
40
|
-
top_p: {
|
|
41
|
-
min: 0,
|
|
42
|
-
max: 1
|
|
43
|
-
},
|
|
44
|
-
top_k: {
|
|
45
|
-
min: 0,
|
|
46
|
-
max: 1e3
|
|
47
|
-
},
|
|
48
|
-
repetition_penalty: {
|
|
49
|
-
min: 0,
|
|
50
|
-
max: 4
|
|
51
|
-
}
|
|
52
|
-
}, f = 1e5;
|
|
53
|
-
function p() {
|
|
54
|
-
return [...c.keys()];
|
|
55
|
-
}
|
|
56
|
-
function m(e) {
|
|
57
|
-
if (typeof e != "string" || !e) throw Error(`ai-inference: model must be a non-empty string, got ${JSON.stringify(e)}`);
|
|
58
|
-
let t = c.get(e);
|
|
59
|
-
if (!t) throw Error(`ai-inference: model not allowed: ${e} (allowed: ${p().join(", ") || "none"})`);
|
|
60
|
-
return t;
|
|
61
|
-
}
|
|
62
|
-
function h(e) {
|
|
63
|
-
if (e != null) {
|
|
64
|
-
if (typeof e != "string" || !l.includes(e)) throw Error(`ai-inference: device not allowed: ${JSON.stringify(e)} (allowed: ${l.join(", ")})`);
|
|
65
|
-
return e;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
function g(e) {
|
|
69
|
-
if (e != null) {
|
|
70
|
-
if (typeof e != "string" || !u.includes(e)) throw Error(`ai-inference: dtype not allowed: ${JSON.stringify(e)} (allowed: ${u.join(", ")})`);
|
|
71
|
-
return e;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function _(e) {
|
|
75
|
-
if (e == null) return !1;
|
|
76
|
-
if (typeof e != "boolean") throw Error(`ai-inference: option ondeviceOnly must be a boolean, got ${JSON.stringify(e)}`);
|
|
77
|
-
return e;
|
|
78
|
-
}
|
|
79
|
-
function v(e) {
|
|
80
|
-
if (typeof e == "string") {
|
|
81
|
-
if (e.length > 1e5) throw Error(`ai-inference: input exceeds ${f} characters`);
|
|
82
|
-
return e;
|
|
83
|
-
}
|
|
84
|
-
if (Array.isArray(e)) {
|
|
85
|
-
if (e.length === 0 || e.length > 64) throw Error("ai-inference: input array must hold 1..64 items");
|
|
86
|
-
for (let t of e) {
|
|
87
|
-
if (typeof t != "string") throw Error("ai-inference: input array items must be strings");
|
|
88
|
-
if (t.length > 1e5) throw Error(`ai-inference: input exceeds ${f} characters`);
|
|
89
|
-
}
|
|
90
|
-
return e;
|
|
91
|
-
}
|
|
92
|
-
throw Error("ai-inference: input must be a string or an array of strings");
|
|
93
|
-
}
|
|
94
|
-
function y(e, t) {
|
|
95
|
-
for (let [n, r] of Object.entries(d)) {
|
|
96
|
-
let i = t[n];
|
|
97
|
-
if (i != null) {
|
|
98
|
-
if (typeof i != "number" || !Number.isFinite(i) || i < r.min || i > r.max) throw Error(`ai-inference: option ${n} must be a number within ${r.min}..${r.max}, got ${JSON.stringify(i)}`);
|
|
99
|
-
e[n] = i;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (t.do_sample !== void 0) {
|
|
103
|
-
if (typeof t.do_sample != "boolean") throw Error("ai-inference: option do_sample must be a boolean");
|
|
104
|
-
e.do_sample = t.do_sample;
|
|
105
|
-
}
|
|
106
|
-
for (let n of ["src_lang", "tgt_lang"]) {
|
|
107
|
-
let r = t[n];
|
|
108
|
-
if (r != null) {
|
|
109
|
-
if (typeof r != "string" || !/^[a-z]{2,3}(_[A-Za-z0-9]{2,8})?$/.test(r)) throw Error(`ai-inference: option ${n} must be a language code like 'en_XX'`);
|
|
110
|
-
e[n] = r;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
var b = class {
|
|
4
|
+
import { a as o, i as s, n as c, o as l, r as u, s as d, t as f } from "./ai-model-registry.js";
|
|
5
|
+
var p = class {
|
|
115
6
|
constructor(e = {}) {
|
|
116
7
|
this.options = e, this.entries = /* @__PURE__ */ new Map();
|
|
117
8
|
}
|
|
@@ -231,7 +122,7 @@ var b = class {
|
|
|
231
122
|
return Math.max(1, this.options.ttlMs ?? 18e5);
|
|
232
123
|
}
|
|
233
124
|
};
|
|
234
|
-
function
|
|
125
|
+
function m(e) {
|
|
235
126
|
return JSON.stringify([
|
|
236
127
|
e.task,
|
|
237
128
|
e.modelId,
|
|
@@ -243,21 +134,24 @@ function x(e) {
|
|
|
243
134
|
}
|
|
244
135
|
//#endregion
|
|
245
136
|
//#region src/workloads/ai-inference.ts
|
|
246
|
-
var
|
|
247
|
-
DEFAULT_AI_MODEL_MAX_BYTES: () =>
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
137
|
+
var h = /* @__PURE__ */ e({
|
|
138
|
+
DEFAULT_AI_MODEL_MAX_BYTES: () => DEFAULT_AI_MODEL_MAX_BYTES,
|
|
139
|
+
LIGHT_INFERENCE_PLAMO_TRANSLATE_DTYPE: () => T,
|
|
140
|
+
LIGHT_INFERENCE_PLAMO_TRANSLATE_MODEL: () => C,
|
|
141
|
+
LIGHT_INFERENCE_PLAMO_TRANSLATE_TASK: () => w,
|
|
142
|
+
LIGHT_INFERENCE_TRANSLATE_DTYPE: () => S,
|
|
143
|
+
LIGHT_INFERENCE_TRANSLATE_MODEL: () => b,
|
|
144
|
+
LIGHT_INFERENCE_TRANSLATE_TASK: () => x,
|
|
145
|
+
MAX_AI_INPUT_CHARS: () => MAX_AI_INPUT_CHARS,
|
|
252
146
|
MAX_AI_INPUT_ITEMS: () => 64,
|
|
253
147
|
MAX_PENDING_TOKEN_CALLBACKS: () => 64,
|
|
254
|
-
MAX_PENDING_TOKEN_CHARS: () =>
|
|
255
|
-
getModelCacheSnapshot: () =>
|
|
256
|
-
handleAiInference: () =>
|
|
257
|
-
isAiModelPreloaded: () =>
|
|
258
|
-
preloadAiModel: () =>
|
|
259
|
-
releaseCache: () =>
|
|
260
|
-
}),
|
|
148
|
+
MAX_PENDING_TOKEN_CHARS: () => v,
|
|
149
|
+
getModelCacheSnapshot: () => D,
|
|
150
|
+
handleAiInference: () => A,
|
|
151
|
+
isAiModelPreloaded: () => y,
|
|
152
|
+
preloadAiModel: () => j,
|
|
153
|
+
releaseCache: () => E
|
|
154
|
+
}), g = [
|
|
261
155
|
"text-classification",
|
|
262
156
|
"token-classification",
|
|
263
157
|
"question-answering",
|
|
@@ -283,9 +177,12 @@ var S = /* @__PURE__ */ e({
|
|
|
283
177
|
"depth-estimation",
|
|
284
178
|
"feature-extraction",
|
|
285
179
|
"image-feature-extraction"
|
|
286
|
-
],
|
|
287
|
-
|
|
288
|
-
|
|
180
|
+
], _ = new p(), v = 256 * 1024, y = (e) => {
|
|
181
|
+
let t = D();
|
|
182
|
+
return typeof e == "string" ? t.entries.some((t) => t.modelId === e && t.state === "ready") : t.entries.some((t) => t.modelId === e.modelId && t.revision === e.revision && t.dtype === e.dtype && t.backend === e.backend && t.state === "ready");
|
|
183
|
+
}, b = "Xenova/m2m100_418M", x = "translation", S = "q4f16", C = "TeamFlaxia/plamo-3-translate-0.8b-onnx", w = "text-generation", T = "q4f16", E = () => {
|
|
184
|
+
_.releaseAll();
|
|
185
|
+
}, D = () => _.getSnapshot(), O = (e, t) => {
|
|
289
186
|
let n = "", r = null, i = Promise.resolve(), a = 0, o = 0, s, c = !1, l = !1, u = (t) => {
|
|
290
187
|
if (a >= 64 || o + t.length > 262144) throw c = !0, s = /* @__PURE__ */ Error("ai-inference token consumer is too slow; generation stopped at the bounded stream buffer"), s;
|
|
291
188
|
a++, o += t.length, i = i.then(() => {
|
|
@@ -324,95 +221,106 @@ var S = /* @__PURE__ */ e({
|
|
|
324
221
|
cancel: () => p(!1)
|
|
325
222
|
};
|
|
326
223
|
};
|
|
327
|
-
function
|
|
224
|
+
function k() {
|
|
328
225
|
let e = globalThis.fetch.bind(globalThis);
|
|
329
226
|
r.fetch = async (t, n) => {
|
|
330
227
|
let r = new URL(String(t));
|
|
331
228
|
if (!/(^|\.)huggingface\.co$/.test(r.hostname) && !/(^|\.)hf\.co$/.test(r.hostname)) throw Error(`ai-inference: model download blocked from ${r.hostname}`);
|
|
332
229
|
let i = await e(r, n), a = Number(i.headers.get("content-length"));
|
|
333
|
-
if (Number.isFinite(a) && a >
|
|
230
|
+
if (Number.isFinite(a) && a > f) throw Error(`ai-inference: model file too large (${a} bytes > ${f})`);
|
|
334
231
|
return i;
|
|
335
232
|
};
|
|
336
233
|
}
|
|
337
|
-
|
|
338
|
-
var
|
|
339
|
-
let { task: r, model:
|
|
340
|
-
if (
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
234
|
+
k(), r.backends?.onnx?.wasm && (r.backends.onnx.wasm.numThreads = 1, r.backends.onnx.wasm.proxy = !1);
|
|
235
|
+
var A = async (e, n) => {
|
|
236
|
+
let { task: r, model: f, input: p, options: h = {} } = e;
|
|
237
|
+
if (e.decision) {
|
|
238
|
+
let { handleDecision: t } = await import("./decision.js");
|
|
239
|
+
return await t(e);
|
|
240
|
+
}
|
|
241
|
+
if (!g.includes(r)) throw Error(`Invalid or unsupported task: ${r}. Supported tasks are: ${g.join(", ")}`);
|
|
242
|
+
let v = l(f), b = s(h.device), x = o(h.dtype), S = d(h.ondeviceOnly), C = u(p), w = {};
|
|
243
|
+
c(w, h);
|
|
244
|
+
let T = x ?? "q4f16", E = b ?? "wasm";
|
|
245
|
+
if (S && !y({
|
|
246
|
+
modelId: f,
|
|
247
|
+
revision: v.revision,
|
|
248
|
+
dtype: T,
|
|
249
|
+
backend: E
|
|
250
|
+
})) throw new t(`ondeviceOnly: model ${f} is not preloaded on this device`, "preloading");
|
|
251
|
+
let D = m({
|
|
344
252
|
task: r,
|
|
345
|
-
modelId:
|
|
346
|
-
revision:
|
|
347
|
-
dtype:
|
|
348
|
-
backend:
|
|
349
|
-
}),
|
|
350
|
-
modelId:
|
|
351
|
-
revision:
|
|
352
|
-
dtype:
|
|
353
|
-
backend:
|
|
253
|
+
modelId: f,
|
|
254
|
+
revision: v.revision,
|
|
255
|
+
dtype: T,
|
|
256
|
+
backend: E
|
|
257
|
+
}), k = performance.now(), A = await _.acquire(D, {
|
|
258
|
+
modelId: f,
|
|
259
|
+
revision: v.revision,
|
|
260
|
+
dtype: T,
|
|
261
|
+
backend: E
|
|
354
262
|
}, async () => {
|
|
355
263
|
let e = {
|
|
356
|
-
dtype:
|
|
357
|
-
device:
|
|
358
|
-
revision:
|
|
264
|
+
dtype: T,
|
|
265
|
+
device: b,
|
|
266
|
+
revision: v.revision
|
|
359
267
|
};
|
|
360
|
-
console.log(`[flaxia-node] ai-inference: loading pipeline task=${r} model=${
|
|
268
|
+
console.log(`[flaxia-node] ai-inference: loading pipeline task=${r} model=${v.repo} revision=${v.revision} dtype=${e.dtype} device=${b ?? "wasm"}`);
|
|
361
269
|
let t;
|
|
362
270
|
try {
|
|
363
|
-
t = await i(r,
|
|
271
|
+
t = await i(r, v.repo, e);
|
|
364
272
|
} catch (n) {
|
|
365
|
-
if (
|
|
366
|
-
else throw console.error(`[flaxia-node] ai-inference: pipeline load FAILED task=${r} model=${
|
|
273
|
+
if (b && b !== "wasm") console.warn(`[AiInference] ${b} failed, falling back to wasm:`, n), e.device = "wasm", t = await i(r, v.repo, e);
|
|
274
|
+
else throw console.error(`[flaxia-node] ai-inference: pipeline load FAILED task=${r} model=${v.repo} error=${n instanceof Error ? n.message : String(n)}`), n;
|
|
367
275
|
}
|
|
368
|
-
return console.log(`[flaxia-node] ai-inference: pipeline ready task=${r} model=${
|
|
276
|
+
return console.log(`[flaxia-node] ai-inference: pipeline ready task=${r} model=${v.repo} loadMs=${Math.round(performance.now() - k)}`), {
|
|
369
277
|
value: t,
|
|
370
278
|
descriptor: { backend: e.device ?? "wasm" }
|
|
371
279
|
};
|
|
372
|
-
}, (e) => e.dispose?.()),
|
|
280
|
+
}, (e) => e.dispose?.()), j = A.value;
|
|
373
281
|
try {
|
|
374
282
|
let e = {
|
|
375
|
-
max_new_tokens:
|
|
376
|
-
do_sample:
|
|
283
|
+
max_new_tokens: w.max_new_tokens ?? 128,
|
|
284
|
+
do_sample: w.do_sample ?? !1
|
|
377
285
|
};
|
|
378
|
-
for (let [t, n] of Object.entries(
|
|
379
|
-
let t = n &&
|
|
380
|
-
t && (e.streamer = new a(
|
|
286
|
+
for (let [t, n] of Object.entries(w)) t === "max_new_tokens" || t === "do_sample" || (e[t] = n);
|
|
287
|
+
let t = n && j.tokenizer ? O(n, h) : null;
|
|
288
|
+
t && (e.streamer = new a(j.tokenizer, {
|
|
381
289
|
skip_prompt: !0,
|
|
382
290
|
skip_special_tokens: !0,
|
|
383
291
|
callback_function: t.callback
|
|
384
292
|
}));
|
|
385
293
|
let i = performance.now(), o;
|
|
386
294
|
try {
|
|
387
|
-
o = await
|
|
295
|
+
o = await j(C, e);
|
|
388
296
|
} catch (e) {
|
|
389
|
-
throw /out of memory|oom|allocation failed|could not allocate/i.test(e instanceof Error ? e.message : String(e)) &&
|
|
297
|
+
throw /out of memory|oom|allocation failed|could not allocate/i.test(e instanceof Error ? e.message : String(e)) && A.invalidate(), t && await t.cancel(), e;
|
|
390
298
|
}
|
|
391
|
-
return await t?.finish(), console.log(`[flaxia-node] ai-inference: done task=${r} model=${
|
|
299
|
+
return await t?.finish(), console.log(`[flaxia-node] ai-inference: done task=${r} model=${v.repo} execMs=${Math.round(performance.now() - i)} inputLen=${String(C).length}`), { output: o };
|
|
392
300
|
} finally {
|
|
393
|
-
await
|
|
301
|
+
await A.release();
|
|
394
302
|
}
|
|
395
|
-
},
|
|
396
|
-
let { task: t, model: n } = e, r =
|
|
303
|
+
}, j = async (e) => {
|
|
304
|
+
let { task: t, model: n } = e, r = l(n), a = s(e.device), c = o(e.dtype) ?? "q4f16", u = a ?? "wasm", d = m({
|
|
397
305
|
task: t,
|
|
398
306
|
modelId: n,
|
|
399
307
|
revision: r.revision,
|
|
400
|
-
dtype:
|
|
401
|
-
backend:
|
|
308
|
+
dtype: c,
|
|
309
|
+
backend: u
|
|
402
310
|
});
|
|
403
|
-
await (await
|
|
311
|
+
await (await _.acquire(d, {
|
|
404
312
|
modelId: n,
|
|
405
313
|
revision: r.revision,
|
|
406
|
-
dtype:
|
|
407
|
-
backend:
|
|
314
|
+
dtype: c,
|
|
315
|
+
backend: u
|
|
408
316
|
}, async () => (console.log(`[flaxia-node] ai-inference: preloading task=${t} model=${r.repo}`), {
|
|
409
317
|
value: await i(t, r.repo, {
|
|
410
|
-
dtype:
|
|
318
|
+
dtype: c,
|
|
411
319
|
device: a,
|
|
412
320
|
revision: r.revision
|
|
413
321
|
}),
|
|
414
|
-
descriptor: { backend:
|
|
322
|
+
descriptor: { backend: u }
|
|
415
323
|
}), (e) => e.dispose?.())).release();
|
|
416
324
|
};
|
|
417
325
|
//#endregion
|
|
418
|
-
export {
|
|
326
|
+
export { b as a, y as c, S as i, j as l, C as n, x as o, w as r, h as s, T as t };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
//#region src/workloads/ai-model-registry.ts
|
|
2
|
+
var e = 512 * 1024 * 1024, t = 4 * 1024 ** 3, n = new Map(Object.entries({
|
|
3
|
+
"Xenova/bert-base-multilingual-uncased-sentiment": {
|
|
4
|
+
repo: "Xenova/bert-base-multilingual-uncased-sentiment",
|
|
5
|
+
revision: "main",
|
|
6
|
+
maxBytes: e
|
|
7
|
+
},
|
|
8
|
+
"onnx-community/Qwen3-Embedding-0.6B-ONNX": {
|
|
9
|
+
repo: "onnx-community/Qwen3-Embedding-0.6B-ONNX",
|
|
10
|
+
revision: "main",
|
|
11
|
+
maxBytes: e
|
|
12
|
+
},
|
|
13
|
+
"LiquidAI/d1-omni-600M": {
|
|
14
|
+
repo: "LiquidAI/d1-omni-600M",
|
|
15
|
+
revision: "02b55d7076f15129e59ab3f94783f32c4b088674",
|
|
16
|
+
maxBytes: 3 * 1024 ** 3
|
|
17
|
+
},
|
|
18
|
+
"onnx-community/embeddinggemma-2-ONNX": {
|
|
19
|
+
repo: "onnx-community/embeddinggemma-2-ONNX",
|
|
20
|
+
revision: "main",
|
|
21
|
+
maxBytes: 1024 * 1024 * 1024
|
|
22
|
+
},
|
|
23
|
+
"Xenova/m2m100_418M": {
|
|
24
|
+
repo: "Xenova/m2m100_418M",
|
|
25
|
+
revision: "main",
|
|
26
|
+
maxBytes: e
|
|
27
|
+
},
|
|
28
|
+
"TeamFlaxia/plamo-3-translate-0.8b-onnx": {
|
|
29
|
+
repo: "TeamFlaxia/plamo-3-translate-0.8b-onnx",
|
|
30
|
+
revision: "1c8417ee1a72442440ad515b02f99186c81fd08a",
|
|
31
|
+
maxBytes: 2 * 1024 ** 3
|
|
32
|
+
}
|
|
33
|
+
}).map(([e, t]) => [e, { ...t }])), r = [
|
|
34
|
+
"wasm",
|
|
35
|
+
"cpu",
|
|
36
|
+
"webgpu"
|
|
37
|
+
], i = [
|
|
38
|
+
"q4",
|
|
39
|
+
"q4f16",
|
|
40
|
+
"q8",
|
|
41
|
+
"int8",
|
|
42
|
+
"uint8"
|
|
43
|
+
], a = {
|
|
44
|
+
max_new_tokens: {
|
|
45
|
+
min: 1,
|
|
46
|
+
max: 1024
|
|
47
|
+
},
|
|
48
|
+
temperature: {
|
|
49
|
+
min: 0,
|
|
50
|
+
max: 4
|
|
51
|
+
},
|
|
52
|
+
top_p: {
|
|
53
|
+
min: 0,
|
|
54
|
+
max: 1
|
|
55
|
+
},
|
|
56
|
+
top_k: {
|
|
57
|
+
min: 0,
|
|
58
|
+
max: 1e3
|
|
59
|
+
},
|
|
60
|
+
repetition_penalty: {
|
|
61
|
+
min: 0,
|
|
62
|
+
max: 4
|
|
63
|
+
}
|
|
64
|
+
}, o = 1e5;
|
|
65
|
+
function s() {
|
|
66
|
+
return [...n.keys()];
|
|
67
|
+
}
|
|
68
|
+
function c(e) {
|
|
69
|
+
if (typeof e != "string" || !e) throw Error(`ai-inference: model must be a non-empty string, got ${JSON.stringify(e)}`);
|
|
70
|
+
let t = n.get(e);
|
|
71
|
+
if (!t) throw Error(`ai-inference: model not allowed: ${e} (allowed: ${s().join(", ") || "none"})`);
|
|
72
|
+
return t;
|
|
73
|
+
}
|
|
74
|
+
function l(e) {
|
|
75
|
+
if (e != null) {
|
|
76
|
+
if (typeof e != "string" || !r.includes(e)) throw Error(`ai-inference: device not allowed: ${JSON.stringify(e)} (allowed: ${r.join(", ")})`);
|
|
77
|
+
return e;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function u(e) {
|
|
81
|
+
if (e != null) {
|
|
82
|
+
if (typeof e != "string" || !i.includes(e)) throw Error(`ai-inference: dtype not allowed: ${JSON.stringify(e)} (allowed: ${i.join(", ")})`);
|
|
83
|
+
return e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function d(e) {
|
|
87
|
+
if (e == null) return !1;
|
|
88
|
+
if (typeof e != "boolean") throw Error(`ai-inference: option ondeviceOnly must be a boolean, got ${JSON.stringify(e)}`);
|
|
89
|
+
return e;
|
|
90
|
+
}
|
|
91
|
+
function f(e) {
|
|
92
|
+
if (typeof e == "string") {
|
|
93
|
+
if (e.length > 1e5) throw Error(`ai-inference: input exceeds ${o} characters`);
|
|
94
|
+
return e;
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(e)) {
|
|
97
|
+
if (e.length === 0 || e.length > 64) throw Error("ai-inference: input array must hold 1..64 items");
|
|
98
|
+
for (let t of e) {
|
|
99
|
+
if (typeof t != "string") throw Error("ai-inference: input array items must be strings");
|
|
100
|
+
if (t.length > 1e5) throw Error(`ai-inference: input exceeds ${o} characters`);
|
|
101
|
+
}
|
|
102
|
+
return e;
|
|
103
|
+
}
|
|
104
|
+
throw Error("ai-inference: input must be a string or an array of strings");
|
|
105
|
+
}
|
|
106
|
+
function p(e, t) {
|
|
107
|
+
for (let [n, r] of Object.entries(a)) {
|
|
108
|
+
let i = t[n];
|
|
109
|
+
if (i != null) {
|
|
110
|
+
if (typeof i != "number" || !Number.isFinite(i) || i < r.min || i > r.max) throw Error(`ai-inference: option ${n} must be a number within ${r.min}..${r.max}, got ${JSON.stringify(i)}`);
|
|
111
|
+
e[n] = i;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (t.do_sample !== void 0) {
|
|
115
|
+
if (typeof t.do_sample != "boolean") throw Error("ai-inference: option do_sample must be a boolean");
|
|
116
|
+
e.do_sample = t.do_sample;
|
|
117
|
+
}
|
|
118
|
+
for (let n of ["src_lang", "tgt_lang"]) {
|
|
119
|
+
let r = t[n];
|
|
120
|
+
if (r != null) {
|
|
121
|
+
if (typeof r != "string" || !/^[a-z]{2,3}(_[A-Za-z0-9]{2,8})?$/.test(r)) throw Error(`ai-inference: option ${n} must be a language code like 'en_XX'`);
|
|
122
|
+
e[n] = r;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
export { u as a, l as i, p as n, c as o, f as r, d as s, t };
|