brsh 3.3.1 → 3.5.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/CHANGELOG.md +14 -0
- package/Readme.md +2 -2
- package/dist/wbt.es.js +384 -242
- package/dist/wbt.es.js.map +1 -1
- package/dist/wbt.min.js +3 -3
- package/dist/wbt.min.js.map +1 -1
- package/lib/wbt/packages/wllama.js +433 -125
- package/package.json +1 -1
- package/test/wbt.test.js +38 -3
package/dist/wbt.es.js
CHANGED
|
@@ -620,24 +620,24 @@ var u, d, f, p, m, h, g, _, v, y, b = e((() => {
|
|
|
620
620
|
}), u.prototype.writeBigInt64BE = $(function(e, t = 0) {
|
|
621
621
|
return G(this, e, t, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff"));
|
|
622
622
|
});
|
|
623
|
-
function
|
|
623
|
+
function ee(e, t, n, r, i, a) {
|
|
624
624
|
if (n + r > e.length || n < 0) throw RangeError("Index out of range");
|
|
625
625
|
}
|
|
626
|
-
function
|
|
627
|
-
return t = +t, r >>>= 0, a ||
|
|
626
|
+
function K(e, t, r, i, a) {
|
|
627
|
+
return t = +t, r >>>= 0, a || ee(e, t, r, 4), n.write(e, t, r, i, 23, 4), r + 4;
|
|
628
628
|
}
|
|
629
629
|
u.prototype.writeFloatLE = function(e, t, n) {
|
|
630
|
-
return
|
|
630
|
+
return K(this, e, t, !0, n);
|
|
631
631
|
}, u.prototype.writeFloatBE = function(e, t, n) {
|
|
632
|
-
return
|
|
632
|
+
return K(this, e, t, !1, n);
|
|
633
633
|
};
|
|
634
|
-
function
|
|
635
|
-
return t = +t, r >>>= 0, a ||
|
|
634
|
+
function q(e, t, r, i, a) {
|
|
635
|
+
return t = +t, r >>>= 0, a || ee(e, t, r, 8), n.write(e, t, r, i, 52, 8), r + 8;
|
|
636
636
|
}
|
|
637
637
|
u.prototype.writeDoubleLE = function(e, t, n) {
|
|
638
|
-
return
|
|
638
|
+
return q(this, e, t, !0, n);
|
|
639
639
|
}, u.prototype.writeDoubleBE = function(e, t, n) {
|
|
640
|
-
return
|
|
640
|
+
return q(this, e, t, !1, n);
|
|
641
641
|
}, u.prototype.copy = function(e, t, n, r) {
|
|
642
642
|
if (!u.isBuffer(e)) throw TypeError("argument should be a Buffer");
|
|
643
643
|
if (n ||= 0, !r && r !== 0 && (r = this.length), t >= e.length && (t = e.length), t ||= 0, r > 0 && r < n && (r = n), r === n || e.length === 0 || this.length === 0) return 0;
|
|
@@ -1706,7 +1706,7 @@ function I(e, t) {
|
|
|
1706
1706
|
this.fun = e, this.array = t;
|
|
1707
1707
|
}
|
|
1708
1708
|
function L() {}
|
|
1709
|
-
var R, z, B, V, H, U, W, G, K, q
|
|
1709
|
+
var R, z, B, V, H, U, W, G, ee, K, q = e((() => {
|
|
1710
1710
|
R = { exports: {} }, z = R.exports = {}, (function() {
|
|
1711
1711
|
try {
|
|
1712
1712
|
B = typeof setTimeout == "function" ? setTimeout : A;
|
|
@@ -1734,7 +1734,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
1734
1734
|
throw Error("process.chdir is not supported");
|
|
1735
1735
|
}, z.umask = function() {
|
|
1736
1736
|
return 0;
|
|
1737
|
-
},
|
|
1737
|
+
}, ee = R.exports, K = /* @__PURE__ */ k(ee);
|
|
1738
1738
|
})), J = /* @__PURE__ */ t(((e, t) => {
|
|
1739
1739
|
var n = T();
|
|
1740
1740
|
t.exports = class extends n {
|
|
@@ -1766,7 +1766,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
1766
1766
|
}
|
|
1767
1767
|
};
|
|
1768
1768
|
})), Y = /* @__PURE__ */ t(((e, t) => {
|
|
1769
|
-
b(),
|
|
1769
|
+
b(), q();
|
|
1770
1770
|
var { BinaryFile: n, SymlinkRef: r } = O(), i = new Uint8Array([
|
|
1771
1771
|
66,
|
|
1772
1772
|
82,
|
|
@@ -1903,8 +1903,8 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
1903
1903
|
let t = new DecompressionStream("gzip"), n = new Blob([e]).stream().pipeThrough(t), r = await new Response(n).arrayBuffer();
|
|
1904
1904
|
return new Uint8Array(r);
|
|
1905
1905
|
}
|
|
1906
|
-
if (
|
|
1907
|
-
let t =
|
|
1906
|
+
if (K !== void 0 && typeof K.getBuiltinModule == "function") {
|
|
1907
|
+
let t = K.getBuiltinModule("zlib");
|
|
1908
1908
|
if (t) return new Uint8Array(t.gunzipSync(y.from(e.buffer, e.byteOffset, e.byteLength)));
|
|
1909
1909
|
}
|
|
1910
1910
|
throw Error("Gzip decompression is not supported in this environment");
|
|
@@ -1923,8 +1923,8 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
1923
1923
|
return f(new Uint8Array(n), t);
|
|
1924
1924
|
}
|
|
1925
1925
|
if (typeof e == "string") {
|
|
1926
|
-
if (!/^https?:\/\//i.test(e) &&
|
|
1927
|
-
let n =
|
|
1926
|
+
if (!/^https?:\/\//i.test(e) && K !== void 0 && typeof K.getBuiltinModule == "function" && typeof window > "u") try {
|
|
1927
|
+
let n = K.getBuiltinModule("fs");
|
|
1928
1928
|
if (n && n.existsSync(e)) {
|
|
1929
1929
|
let r = await n.promises.readFile(e);
|
|
1930
1930
|
return f(new Uint8Array(r.buffer, r.byteOffset, r.byteLength), t);
|
|
@@ -2255,7 +2255,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
2255
2255
|
})), ne = /* @__PURE__ */ t(((e, t) => {
|
|
2256
2256
|
t.exports = null;
|
|
2257
2257
|
})), re = /* @__PURE__ */ t(((e, t) => {
|
|
2258
|
-
|
|
2258
|
+
q();
|
|
2259
2259
|
function n(e) {
|
|
2260
2260
|
if (typeof e != "string") throw TypeError("Path must be a string. Received " + JSON.stringify(e));
|
|
2261
2261
|
}
|
|
@@ -2293,7 +2293,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
2293
2293
|
resolve: function() {
|
|
2294
2294
|
for (var e = "", t = !1, i, a = arguments.length - 1; a >= -1 && !t; a--) {
|
|
2295
2295
|
var o;
|
|
2296
|
-
a >= 0 ? o = arguments[a] : (i === void 0 && (i =
|
|
2296
|
+
a >= 0 ? o = arguments[a] : (i === void 0 && (i = K.cwd()), o = i), n(o), o.length !== 0 && (e = o + "/" + e, t = o.charCodeAt(0) === 47);
|
|
2297
2297
|
}
|
|
2298
2298
|
return e = r(e, !t), t ? e.length > 0 ? "/" + e : "/" : e.length > 0 ? e : ".";
|
|
2299
2299
|
},
|
|
@@ -3810,23 +3810,80 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3810
3810
|
};
|
|
3811
3811
|
})), oe = /* @__PURE__ */ t(((e, t) => {
|
|
3812
3812
|
T();
|
|
3813
|
-
var n = Z(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = ae(), o =
|
|
3814
|
-
|
|
3815
|
-
|
|
3813
|
+
var n = Z(), { readBytesFromFs: r, writeBytesToFs: i, loadModule: a } = ae(), o = {
|
|
3814
|
+
smol: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
|
|
3815
|
+
smollm: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
|
|
3816
|
+
smollm2: "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
|
|
3817
|
+
"smol-135m": "https://huggingface.co/bartowski/SmolLM2-135M-Instruct-GGUF/resolve/main/SmolLM2-135M-Instruct-Q4_K_M.gguf",
|
|
3818
|
+
"smol-360m": "https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf",
|
|
3819
|
+
"smollm-360m": "https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf",
|
|
3820
|
+
"smollm2-360m": "https://huggingface.co/bartowski/SmolLM2-360M-Instruct-GGUF/resolve/main/SmolLM2-360M-Instruct-Q4_K_M.gguf",
|
|
3821
|
+
"smol-1.7b": "https://huggingface.co/bartowski/SmolLM2-1.7B-Instruct-GGUF/resolve/main/SmolLM2-1.7B-Instruct-Q4_K_M.gguf",
|
|
3822
|
+
qwen: "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
|
|
3823
|
+
"qwen2.5": "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
|
|
3824
|
+
"qwen-0.5b": "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
|
|
3825
|
+
"qwen2.5-0.5b": "https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF/resolve/main/qwen2.5-0.5b-instruct-q4_k_m.gguf",
|
|
3826
|
+
"qwen-1.5b": "https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct-GGUF/resolve/main/qwen2.5-1.5b-instruct-q4_k_m.gguf",
|
|
3827
|
+
"qwen2.5-1.5b": "https://huggingface.co/Qwen/Qwen2.5-1.5B-Instruct-GGUF/resolve/main/qwen2.5-1.5b-instruct-q4_k_m.gguf",
|
|
3828
|
+
stories: "https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories260K.gguf",
|
|
3829
|
+
stories15m: "https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories15M.gguf"
|
|
3830
|
+
}, s = o.smol, c = "https://cdn.jsdelivr.net/npm/@wllama/wllama@3.8.1/src/wasm/wllama.wasm", l = "/var/cache/wllama", u = /* @__PURE__ */ new Map();
|
|
3831
|
+
function d(e) {
|
|
3832
|
+
if (!e) return `${l}/model.gguf`;
|
|
3816
3833
|
if (e.kind === "fs") return e.path;
|
|
3817
|
-
if (e.kind === "hf-quant") return `${
|
|
3818
|
-
let t = (e.file || e.url ||
|
|
3819
|
-
return /\.gguf$/i.test(t) || (t += ".gguf"), `${
|
|
3834
|
+
if (e.kind === "hf-quant") return `${l}/${(e.repo || "model").split("/").pop().replace(/[^a-zA-Z0-9._-]/g, "_")}-${(e.quant || "Q4_K_M").replace(/[^a-zA-Z0-9._-]/g, "_")}.gguf`;
|
|
3835
|
+
let t = (e.file || e.url || s).split("/").pop().split("?")[0] || "model.gguf";
|
|
3836
|
+
return /\.gguf$/i.test(t) || (t += ".gguf"), `${l}/${t}`;
|
|
3820
3837
|
}
|
|
3821
|
-
function
|
|
3822
|
-
|
|
3838
|
+
function f(e) {
|
|
3839
|
+
return !e || e <= 0 ? "0 B" : e >= 1024 * 1024 * 1024 ? `${(e / (1024 * 1024 * 1024)).toFixed(1)} GB` : e >= 1024 * 1024 ? `${(e / (1024 * 1024)).toFixed(1)} MB` : e >= 1024 ? `${(e / 1024).toFixed(1)} KB` : `${e} B`;
|
|
3840
|
+
}
|
|
3841
|
+
function p(e, t, n, r = 20) {
|
|
3842
|
+
let i = (e || "model.gguf").split("/").pop().split("?")[0] || e;
|
|
3823
3843
|
if (n > 0) {
|
|
3824
|
-
let e = Math.max(0, Math.min(1, t / n)),
|
|
3825
|
-
return `\rPulling ${
|
|
3844
|
+
let e = Math.max(0, Math.min(1, t / n)), a = Math.round(e * 100), o = Math.round(e * r);
|
|
3845
|
+
return `\rPulling ${i}: [${"█".repeat(o) + "░".repeat(Math.max(0, r - o))}] ${String(a).padStart(3)}% (${f(t)} / ${f(n)})`;
|
|
3826
3846
|
}
|
|
3827
|
-
return `\rPulling ${
|
|
3847
|
+
return `\rPulling ${i}: ${f(t)} downloaded...`;
|
|
3828
3848
|
}
|
|
3829
|
-
|
|
3849
|
+
var m = class {
|
|
3850
|
+
constructor({ onRender: e = null, width: t = 20, intervalMs: n = 80, enabled: r = !0 } = {}) {
|
|
3851
|
+
this.onRender = e, this.width = t, this.intervalMs = n, this.enabled = r, this.label = "", this.total = 0, this.loaded = 0, this.hint = "", this.startTime = 0, this.step = 0, this.timer = null, this.active = !1, this.isDeterminate = !1;
|
|
3852
|
+
}
|
|
3853
|
+
start(e, { total: t = 0, loaded: n = 0, hint: r = "", determinate: i = null } = {}) {
|
|
3854
|
+
this.enabled && (this.stopTimer(), this.label = e || "Loading", this.total = t || 0, this.loaded = n || 0, this.hint = r || "", this.startTime = Date.now(), this.step = 0, this.active = !0, this.isDeterminate = i === null ? this.total > 0 && this.loaded > 0 : i, this.render(), this.timer = setInterval(() => {
|
|
3855
|
+
this.step++, this.render();
|
|
3856
|
+
}, this.intervalMs));
|
|
3857
|
+
}
|
|
3858
|
+
update({ loaded: e, total: t, hint: n } = {}) {
|
|
3859
|
+
!this.enabled || !this.active || (typeof t == "number" && t > 0 && (this.total = t, this.isDeterminate = !0), typeof e == "number" && e >= 0 && (this.loaded = e, this.total > 0 && (this.isDeterminate = !0)), typeof n == "string" && (this.hint = n), this.render());
|
|
3860
|
+
}
|
|
3861
|
+
formatLine() {
|
|
3862
|
+
let e = ((Date.now() - this.startTime) / 1e3).toFixed(1) + "s";
|
|
3863
|
+
if (this.isDeterminate && this.total > 0) {
|
|
3864
|
+
let t = Math.max(0, Math.min(1, this.loaded / this.total)), n = Math.round(t * 100), r = Math.round(t * this.width), i = "█".repeat(r) + "░".repeat(Math.max(0, this.width - r)), a = `${f(this.loaded)} / ${f(this.total)}`, o = this.hint ? ` (${this.hint})` : "";
|
|
3865
|
+
return `${this.label}: [${i}] ${String(n).padStart(3)}% (${a}, ${e})${o}`;
|
|
3866
|
+
}
|
|
3867
|
+
let t = Math.max(1, this.width - 5), n = t * 2, r = this.step % n, i = r < t ? r : n - r, a = `[${"░".repeat(i)}${"█".repeat(5)}${"░".repeat(Math.max(0, this.width - i - 5))}]`, o = this.hint ? ` (${this.hint})` : "";
|
|
3868
|
+
return `${this.label}: ${a} ${e}${o}`;
|
|
3869
|
+
}
|
|
3870
|
+
render() {
|
|
3871
|
+
!this.enabled || !this.active || typeof this.onRender != "function" || this.onRender(this.formatLine());
|
|
3872
|
+
}
|
|
3873
|
+
stopTimer() {
|
|
3874
|
+
this.timer !== null && (clearInterval(this.timer), this.timer = null);
|
|
3875
|
+
}
|
|
3876
|
+
finish(e = "Done") {
|
|
3877
|
+
if (!this.enabled || !this.active) return;
|
|
3878
|
+
this.stopTimer();
|
|
3879
|
+
let t = ((Date.now() - this.startTime) / 1e3).toFixed(1) + "s", n = "█".repeat(this.width), r = this.total > 0 ? `, ${f(this.total)}` : "", i = `${this.label}: [${n}] 100% (${t}${r}) — ${e}`;
|
|
3880
|
+
typeof this.onRender == "function" && this.onRender(i), this.active = !1;
|
|
3881
|
+
}
|
|
3882
|
+
clear() {
|
|
3883
|
+
this.stopTimer(), this.active = !1, this.enabled && typeof this.onRender == "function" && this.onRender("");
|
|
3884
|
+
}
|
|
3885
|
+
};
|
|
3886
|
+
function h(e, t = null, n = null, r = null) {
|
|
3830
3887
|
if (t) {
|
|
3831
3888
|
if (n) {
|
|
3832
3889
|
let e = t.replace(/^hf:/i, "").replace(/^\/+|\/+$/g, ""), r = n.replace(/^\/+/, "");
|
|
@@ -3848,10 +3905,11 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3848
3905
|
let i = (e || "").trim();
|
|
3849
3906
|
if (!i) return {
|
|
3850
3907
|
kind: "url",
|
|
3851
|
-
key:
|
|
3852
|
-
url:
|
|
3908
|
+
key: s,
|
|
3909
|
+
url: s
|
|
3853
3910
|
};
|
|
3854
|
-
|
|
3911
|
+
let a = i.toLowerCase();
|
|
3912
|
+
if (o[a] && (i = o[a]), /^hf:\/\//i.test(i) || /^hf:/i.test(i)) {
|
|
3855
3913
|
let e = i.replace(/^hf:(\/\/)?/i, ""), t = e.match(/^([^/]+\/[^/:]+):([^/]+)$/);
|
|
3856
3914
|
if (t) return {
|
|
3857
3915
|
kind: "hf-quant",
|
|
@@ -3887,7 +3945,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3887
3945
|
path: i
|
|
3888
3946
|
};
|
|
3889
3947
|
}
|
|
3890
|
-
async function
|
|
3948
|
+
async function g(e, t) {
|
|
3891
3949
|
let n = await fetch(e);
|
|
3892
3950
|
if (!n.ok) throw Error(`Failed to fetch model from ${e}: HTTP ${n.status}`);
|
|
3893
3951
|
let r = Number(n.headers.get("content-length") || 0);
|
|
@@ -3912,8 +3970,8 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3912
3970
|
let s = new Blob(a, { type: "application/octet-stream" });
|
|
3913
3971
|
return s.name = e.split("/").pop().split("?")[0] || "model.gguf", s;
|
|
3914
3972
|
}
|
|
3915
|
-
async function
|
|
3916
|
-
if (!
|
|
3973
|
+
async function _({ wllama: e, mod: t, modelSpec: n, downloadedBlob: r = null, targetPersistPath: a, fs: o, progressCallback: c }) {
|
|
3974
|
+
if (!o || !a) return null;
|
|
3917
3975
|
let l = null;
|
|
3918
3976
|
if (r && typeof r.arrayBuffer == "function") l = new Uint8Array(await r.arrayBuffer());
|
|
3919
3977
|
else if (e && typeof e.getLoadedBlob == "function") {
|
|
@@ -3927,7 +3985,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3927
3985
|
}
|
|
3928
3986
|
} catch {}
|
|
3929
3987
|
if (!l) {
|
|
3930
|
-
let e = n.url || (n.kind === "url" ?
|
|
3988
|
+
let e = n.url || (n.kind === "url" ? s : null);
|
|
3931
3989
|
if (!e && n.kind === "hf-quant" && t && typeof t.getHFModelSource == "function") try {
|
|
3932
3990
|
let r = await t.getHFModelSource({
|
|
3933
3991
|
repo: n.repo,
|
|
@@ -3936,7 +3994,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3936
3994
|
e = r.url || r;
|
|
3937
3995
|
} catch {}
|
|
3938
3996
|
if (e && typeof fetch == "function") try {
|
|
3939
|
-
let t = await
|
|
3997
|
+
let t = await g(e, c);
|
|
3940
3998
|
l = new Uint8Array(await t.arrayBuffer());
|
|
3941
3999
|
} catch {}
|
|
3942
4000
|
}
|
|
@@ -3949,33 +4007,33 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3949
4007
|
0,
|
|
3950
4008
|
0,
|
|
3951
4009
|
0
|
|
3952
|
-
]), i(
|
|
4010
|
+
]), i(o, a, l, "application/octet-stream"), {
|
|
3953
4011
|
path: a,
|
|
3954
4012
|
size: l.byteLength
|
|
3955
4013
|
};
|
|
3956
4014
|
}
|
|
3957
|
-
async function
|
|
3958
|
-
let { modelSpec: t, mmprojSpec: n = null, loadParams:
|
|
3959
|
-
typeof
|
|
3960
|
-
let
|
|
3961
|
-
if (f.wasmPath &&
|
|
3962
|
-
let e = r(
|
|
3963
|
-
e && e.byteLength > 0 && (
|
|
3964
|
-
}
|
|
3965
|
-
let
|
|
3966
|
-
default:
|
|
3967
|
-
"single-thread/wllama.wasm":
|
|
3968
|
-
"multi-thread/wllama.wasm":
|
|
3969
|
-
},
|
|
4015
|
+
async function v(e = {}) {
|
|
4016
|
+
let { modelSpec: t, mmprojSpec: n = null, loadParams: o = {}, fs: l, pkgMeta: f = {}, wbtConfig: p = {}, loadModel: m = !0, persist: h = !1, persistPath: v = null, tracker: y = null, shortLabel: b = "model.gguf", isPullCommand: x = !1, onStatus: S = null } = e;
|
|
4017
|
+
typeof S == "function" && S("Initializing WASM runtime...");
|
|
4018
|
+
let C = await a("@wllama/wllama", f.cdnUrl, p.moduleLoader), w = C.Wllama || C.default || C, T = C.LoggerWithoutDebug || void 0, E = f.wasmUrl || c;
|
|
4019
|
+
if (f.wasmPath && l && typeof URL < "u" && typeof URL.createObjectURL == "function") {
|
|
4020
|
+
let e = r(l, f.wasmPath);
|
|
4021
|
+
e && e.byteLength > 0 && (E = URL.createObjectURL(new Blob([e], { type: "application/wasm" })));
|
|
4022
|
+
}
|
|
4023
|
+
let D = {
|
|
4024
|
+
default: E,
|
|
4025
|
+
"single-thread/wllama.wasm": E,
|
|
4026
|
+
"multi-thread/wllama.wasm": E
|
|
4027
|
+
}, O = () => {
|
|
3970
4028
|
try {
|
|
3971
|
-
return new
|
|
4029
|
+
return new w(D, {
|
|
3972
4030
|
suppressNativeLog: !0,
|
|
3973
|
-
logger:
|
|
4031
|
+
logger: T
|
|
3974
4032
|
});
|
|
3975
4033
|
} catch {
|
|
3976
|
-
return new
|
|
4034
|
+
return new w(D, {
|
|
3977
4035
|
suppressNativeLog: !0,
|
|
3978
|
-
logger:
|
|
4036
|
+
logger: T,
|
|
3979
4037
|
cacheManager: {
|
|
3980
4038
|
isSupported: () => !0,
|
|
3981
4039
|
getNameFromURL: async (e) => e,
|
|
@@ -3986,135 +4044,181 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
3986
4044
|
});
|
|
3987
4045
|
}
|
|
3988
4046
|
};
|
|
3989
|
-
if (!
|
|
3990
|
-
wllama:
|
|
3991
|
-
mod:
|
|
3992
|
-
Wllama:
|
|
4047
|
+
if (!m) return {
|
|
4048
|
+
wllama: O(),
|
|
4049
|
+
mod: C,
|
|
4050
|
+
Wllama: w,
|
|
3993
4051
|
modelKey: null,
|
|
3994
4052
|
isCached: !1,
|
|
3995
4053
|
persisted: null
|
|
3996
4054
|
};
|
|
3997
|
-
let
|
|
3998
|
-
if (
|
|
3999
|
-
let e =
|
|
4055
|
+
let k = v || (h && t.kind !== "fs" ? d(t) : null), A = t.kind === "fs" ? null : d(t), j = t.kind === "fs" && l && typeof l.absolutePath == "function" ? `fs:${l.absolutePath(t.path)}:gpu=${o.n_gpu_layers ?? "auto"}:emb=${!!o.embeddings}` : `${t.key}:gpu=${o.n_gpu_layers ?? "auto"}:emb=${!!o.embeddings}`;
|
|
4056
|
+
if (u.has(j)) {
|
|
4057
|
+
let e = u.get(j);
|
|
4000
4058
|
if (typeof e.isModelLoaded != "function" || e.isModelLoaded()) {
|
|
4001
|
-
typeof
|
|
4059
|
+
typeof S == "function" && S("Loaded model from cache."), y && y.finish("Loaded model from cache");
|
|
4002
4060
|
let n = null;
|
|
4003
|
-
if ((
|
|
4004
|
-
let e = r(
|
|
4061
|
+
if ((h || v) && l && k) if (l.exists(k)) {
|
|
4062
|
+
let e = r(l, k);
|
|
4005
4063
|
n = {
|
|
4006
|
-
path:
|
|
4064
|
+
path: k,
|
|
4007
4065
|
size: e ? e.byteLength : 0
|
|
4008
4066
|
};
|
|
4009
|
-
} else n = await
|
|
4067
|
+
} else n = await _({
|
|
4010
4068
|
wllama: e,
|
|
4011
|
-
mod:
|
|
4069
|
+
mod: C,
|
|
4012
4070
|
modelSpec: t,
|
|
4013
|
-
targetPersistPath:
|
|
4014
|
-
fs:
|
|
4015
|
-
progressCallback:
|
|
4071
|
+
targetPersistPath: k,
|
|
4072
|
+
fs: l,
|
|
4073
|
+
progressCallback: o.progressCallback
|
|
4016
4074
|
});
|
|
4017
4075
|
return {
|
|
4018
4076
|
wllama: e,
|
|
4019
|
-
mod:
|
|
4020
|
-
Wllama:
|
|
4021
|
-
modelKey:
|
|
4077
|
+
mod: C,
|
|
4078
|
+
Wllama: w,
|
|
4079
|
+
modelKey: j,
|
|
4022
4080
|
isCached: !0,
|
|
4023
4081
|
persisted: n
|
|
4024
4082
|
};
|
|
4025
4083
|
}
|
|
4026
4084
|
}
|
|
4027
|
-
let
|
|
4028
|
-
|
|
4029
|
-
|
|
4085
|
+
let M = O(), N = null, P = null, F = (e = "loading tensors") => ({
|
|
4086
|
+
...o,
|
|
4087
|
+
progressCallback: ({ loaded: t, total: n }) => {
|
|
4088
|
+
y && y.update({
|
|
4089
|
+
loaded: t,
|
|
4090
|
+
total: n,
|
|
4091
|
+
hint: e
|
|
4092
|
+
}), typeof o.progressCallback == "function" && o.progressCallback({
|
|
4093
|
+
loaded: t,
|
|
4094
|
+
total: n
|
|
4095
|
+
});
|
|
4096
|
+
}
|
|
4097
|
+
});
|
|
4098
|
+
if (t.kind !== "fs" && l) {
|
|
4099
|
+
let e = k && l.exists(k) ? k : A && l.exists(A) ? A : null;
|
|
4030
4100
|
if (e) {
|
|
4031
|
-
let t = r(
|
|
4101
|
+
let t = r(l, e);
|
|
4032
4102
|
if (t && t.byteLength > 0) {
|
|
4033
|
-
typeof
|
|
4103
|
+
typeof S == "function" && S(`Loading model from ${e}...`), y && y.start(`Loading model (${b}) weights`, {
|
|
4104
|
+
total: t.byteLength,
|
|
4105
|
+
hint: "parsing tensors & compiling WebGPU shaders"
|
|
4106
|
+
});
|
|
4034
4107
|
let n = new Blob([t], { type: "application/octet-stream" });
|
|
4035
|
-
n.name = e.split("/").pop() || "model.gguf", await
|
|
4108
|
+
n.name = e.split("/").pop() || "model.gguf", await M.loadModel([n], F()), P = {
|
|
4036
4109
|
path: e,
|
|
4037
4110
|
bytes: t
|
|
4038
|
-
};
|
|
4111
|
+
}, y && y.finish("Model weights loaded");
|
|
4039
4112
|
}
|
|
4040
4113
|
}
|
|
4041
4114
|
}
|
|
4042
|
-
if (
|
|
4115
|
+
if (P) k && k !== P.path && i(l, k, P.bytes, "application/octet-stream");
|
|
4043
4116
|
else if (t.kind === "fs") {
|
|
4044
|
-
typeof
|
|
4045
|
-
let e = r(
|
|
4117
|
+
typeof S == "function" && S(`Loading model from ${t.path}...`), y && y.start(`Loading model (${b}) weights`, { hint: "reading file" });
|
|
4118
|
+
let e = r(l, t.path);
|
|
4046
4119
|
if (!e) throw Error(`${t.path}: No such file or directory`);
|
|
4047
4120
|
let a = new Blob([e], { type: "application/octet-stream" });
|
|
4048
4121
|
a.name = t.path.split("/").pop() || "model.gguf";
|
|
4049
4122
|
let o = [a];
|
|
4050
4123
|
if (n) {
|
|
4051
|
-
let e = r(
|
|
4124
|
+
let e = r(l, n);
|
|
4052
4125
|
if (!e) throw Error(`${n}: No such file or directory`);
|
|
4053
4126
|
let t = new Blob([e], { type: "application/octet-stream" });
|
|
4054
4127
|
t.name = n.split("/").pop() || "mmproj.gguf", o.push(t);
|
|
4055
4128
|
}
|
|
4056
|
-
typeof
|
|
4057
|
-
|
|
4058
|
-
|
|
4129
|
+
typeof S == "function" && S(`Loading model ${a.name} into memory...`), y && y.start(`Loading model (${b}) weights`, {
|
|
4130
|
+
total: e.byteLength,
|
|
4131
|
+
loaded: e.byteLength,
|
|
4132
|
+
hint: "parsing tensors & compiling WebGPU shaders"
|
|
4133
|
+
}), await M.loadModel(o, F()), y && y.finish("Model weights loaded"), k && k !== t.path && i(l, k, e, "application/octet-stream");
|
|
4134
|
+
} else if (t.kind === "hf-quant" && typeof M.loadModelFromHF == "function") {
|
|
4135
|
+
typeof S == "function" && S(`Pulling model ${t.repo} (${t.quant})...`), y && y.start(`Pulling ${b}`, { hint: "connecting to Hugging Face" });
|
|
4059
4136
|
try {
|
|
4060
|
-
await
|
|
4137
|
+
await M.loadModelFromHF({
|
|
4061
4138
|
repo: t.repo,
|
|
4062
4139
|
quant: t.quant
|
|
4063
|
-
},
|
|
4140
|
+
}, F("downloading")), y && y.finish("Model weights loaded");
|
|
4064
4141
|
} catch (e) {
|
|
4065
|
-
if (typeof
|
|
4066
|
-
let e = await
|
|
4142
|
+
if (typeof C.getHFModelSource == "function") {
|
|
4143
|
+
let e = await C.getHFModelSource({
|
|
4067
4144
|
repo: t.repo,
|
|
4068
4145
|
quant: t.quant
|
|
4069
4146
|
});
|
|
4070
|
-
typeof
|
|
4147
|
+
typeof S == "function" && S(`Pulling model ${t.repo} (${t.quant})...`), y && y.start(`Pulling ${b}`, { hint: "downloading" }), N = await g(e.url || e, (e) => {
|
|
4148
|
+
y && y.update({
|
|
4149
|
+
loaded: e.loaded,
|
|
4150
|
+
total: e.total,
|
|
4151
|
+
hint: "downloading"
|
|
4152
|
+
}), typeof o.progressCallback == "function" && o.progressCallback(e);
|
|
4153
|
+
}), typeof S == "function" && S("Loading model into memory..."), y && y.start(`Loading model (${b}) weights`, {
|
|
4154
|
+
total: N.size,
|
|
4155
|
+
hint: "parsing tensors & compiling WebGPU shaders"
|
|
4156
|
+
}), await M.loadModel([N], F()), y && y.finish("Model weights loaded");
|
|
4071
4157
|
} else throw e;
|
|
4072
4158
|
}
|
|
4073
|
-
} else if (t.kind === "hf-file" && typeof
|
|
4074
|
-
typeof
|
|
4159
|
+
} else if (t.kind === "hf-file" && typeof M.loadModelFromHF == "function") {
|
|
4160
|
+
typeof S == "function" && S(`Pulling model ${t.repo}/${t.file}...`), y && y.start(`Pulling ${b}`, { hint: "connecting to Hugging Face" });
|
|
4075
4161
|
try {
|
|
4076
|
-
await
|
|
4162
|
+
await M.loadModelFromHF({
|
|
4077
4163
|
repo: t.repo,
|
|
4078
4164
|
file: t.file
|
|
4079
|
-
},
|
|
4165
|
+
}, F("downloading")), y && y.finish("Model weights loaded");
|
|
4080
4166
|
} catch {
|
|
4081
|
-
|
|
4167
|
+
y && y.start(`Pulling ${b}`, { hint: "downloading" }), N = await g(t.url, (e) => {
|
|
4168
|
+
y && y.update({
|
|
4169
|
+
loaded: e.loaded,
|
|
4170
|
+
total: e.total,
|
|
4171
|
+
hint: "downloading"
|
|
4172
|
+
}), typeof o.progressCallback == "function" && o.progressCallback(e);
|
|
4173
|
+
}), typeof S == "function" && S("Loading model into memory..."), y && y.start(`Loading model (${b}) weights`, {
|
|
4174
|
+
total: N.size,
|
|
4175
|
+
hint: "parsing tensors & compiling WebGPU shaders"
|
|
4176
|
+
}), await M.loadModel([N], F()), y && y.finish("Model weights loaded");
|
|
4082
4177
|
}
|
|
4083
4178
|
} else {
|
|
4084
|
-
let e = t.url ||
|
|
4085
|
-
typeof
|
|
4179
|
+
let e = t.url || s;
|
|
4180
|
+
typeof S == "function" && S(`Pulling model from ${e.split("/").pop().split("?")[0] || e}...`), y && y.start(`Pulling ${b}`, { hint: "downloading" });
|
|
4086
4181
|
try {
|
|
4087
|
-
n && /^https?:\/\//i.test(n) ? await
|
|
4182
|
+
n && /^https?:\/\//i.test(n) ? await M.loadModelFromUrl({
|
|
4088
4183
|
url: e,
|
|
4089
4184
|
mmprojUrl: n
|
|
4090
|
-
},
|
|
4185
|
+
}, F("downloading")) : await M.loadModelFromUrl(e, F("downloading")), y && y.finish("Model weights loaded");
|
|
4091
4186
|
} catch {
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4187
|
+
N = await g(e, (e) => {
|
|
4188
|
+
y && y.update({
|
|
4189
|
+
loaded: e.loaded,
|
|
4190
|
+
total: e.total,
|
|
4191
|
+
hint: "downloading"
|
|
4192
|
+
}), typeof o.progressCallback == "function" && o.progressCallback(e);
|
|
4193
|
+
}), typeof S == "function" && S("Loading model into memory..."), y && y.start(`Loading model (${b}) weights`, {
|
|
4194
|
+
total: N.size,
|
|
4195
|
+
hint: "parsing tensors & compiling WebGPU shaders"
|
|
4196
|
+
}), await M.loadModel([N], F()), y && y.finish("Model weights loaded");
|
|
4197
|
+
}
|
|
4198
|
+
}
|
|
4199
|
+
typeof S == "function" && S("Model loaded.");
|
|
4200
|
+
let I = null;
|
|
4201
|
+
return P ? I = {
|
|
4202
|
+
path: k || P.path,
|
|
4203
|
+
size: P.bytes.byteLength
|
|
4204
|
+
} : (h || v) && l && k && t.kind !== "fs" && (I = await _({
|
|
4205
|
+
wllama: M,
|
|
4206
|
+
mod: C,
|
|
4103
4207
|
modelSpec: t,
|
|
4104
|
-
downloadedBlob:
|
|
4105
|
-
targetPersistPath:
|
|
4106
|
-
fs:
|
|
4107
|
-
progressCallback:
|
|
4108
|
-
})),
|
|
4109
|
-
wllama:
|
|
4110
|
-
mod:
|
|
4111
|
-
Wllama:
|
|
4112
|
-
modelKey:
|
|
4208
|
+
downloadedBlob: N,
|
|
4209
|
+
targetPersistPath: k,
|
|
4210
|
+
fs: l,
|
|
4211
|
+
progressCallback: o.progressCallback
|
|
4212
|
+
})), u.set(j, M), {
|
|
4213
|
+
wllama: M,
|
|
4214
|
+
mod: C,
|
|
4215
|
+
Wllama: w,
|
|
4216
|
+
modelKey: j,
|
|
4113
4217
|
isCached: !1,
|
|
4114
|
-
persisted:
|
|
4218
|
+
persisted: I
|
|
4115
4219
|
};
|
|
4116
4220
|
}
|
|
4117
|
-
function
|
|
4221
|
+
function y(e) {
|
|
4118
4222
|
if (typeof e == "string") return e;
|
|
4119
4223
|
if (!e || typeof e != "object") return "";
|
|
4120
4224
|
if (Array.isArray(e.choices) && e.choices.length > 0) {
|
|
@@ -4125,7 +4229,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4125
4229
|
}
|
|
4126
4230
|
return typeof e.content == "string" ? e.content : typeof e.text == "string" ? e.text : "";
|
|
4127
4231
|
}
|
|
4128
|
-
function
|
|
4232
|
+
function b(e = {}, t = {}, i = "wllama") {
|
|
4129
4233
|
class a extends n {
|
|
4130
4234
|
static get name() {
|
|
4131
4235
|
return i;
|
|
@@ -4140,22 +4244,22 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4140
4244
|
});
|
|
4141
4245
|
}
|
|
4142
4246
|
_parseArgs(e) {
|
|
4143
|
-
let t = null, n = null, r = null, i = null, a = null,
|
|
4144
|
-
for (let
|
|
4145
|
-
let
|
|
4146
|
-
if (
|
|
4147
|
-
else if (
|
|
4148
|
-
else if (
|
|
4149
|
-
else if (
|
|
4150
|
-
else if (
|
|
4151
|
-
else if (
|
|
4152
|
-
|
|
4153
|
-
let n = e[
|
|
4154
|
-
n && !n.startsWith("-") && !/^https?:\/\//i.test(n) && !/^hf:/i.test(n) && (n.startsWith("/") || n.startsWith("./") || n.startsWith("../") || /\.gguf$/i.test(n)) && (t !== null || r !== null ||
|
|
4155
|
-
} else
|
|
4247
|
+
let t = null, n = null, r = null, i = null, a = null, s = null, c = null, l = null, u = 256, d = .7, f, p, m = 4096, g, _, v, y = !1, b = !1, x = !1, S = !0, C = !0, w = !1, T = null, E = !0, D = !1, O = !1, k = null, A = [], j = [];
|
|
4248
|
+
for (let o = 0; o < e.length; o++) {
|
|
4249
|
+
let h = e[o];
|
|
4250
|
+
if (h === "--help" || h === "-h" && o + 1 >= e.length || h === "-?") D = !0;
|
|
4251
|
+
else if (h === "--version" || h === "-V" || h === "-v") O = !0;
|
|
4252
|
+
else if (h === "--serve" || h === "--daemon") k = "serve";
|
|
4253
|
+
else if (h === "-q" || h === "--quiet" || h === "--no-progress") E = !1;
|
|
4254
|
+
else if (h === "--progress") E = !0;
|
|
4255
|
+
else if (h === "--persist" || h === "--save") {
|
|
4256
|
+
w = !0;
|
|
4257
|
+
let n = e[o + 1];
|
|
4258
|
+
n && !n.startsWith("-") && !/^https?:\/\//i.test(n) && !/^hf:/i.test(n) && (n.startsWith("/") || n.startsWith("./") || n.startsWith("../") || /\.gguf$/i.test(n)) && (t !== null || r !== null || o + 2 < e.length || k === "pull") && (t !== null || r !== null) && (T = e[++o]);
|
|
4259
|
+
} else h.startsWith("--persist=") ? (w = !0, T = h.slice(10) || null) : h.startsWith("--save=") ? (w = !0, T = h.slice(7) || null) : (h === "-o" || h === "--output") && o + 1 < e.length ? (w = !0, T = e[++o]) : h.startsWith("--output=") ? (w = !0, T = h.slice(9) || null) : (h === "-m" || h === "--model" || h === "--url") && o + 1 < e.length ? t = e[++o] : h.startsWith("--model=") ? t = h.slice(8) : h === "--mmproj" && o + 1 < e.length ? n = e[++o] : (h === "--hf" || h === "-hf" || h === "--hf-repo") && o + 1 < e.length ? r = e[++o] : h === "--hf-file" && o + 1 < e.length ? i = e[++o] : (h === "--quant" || h === "--hf-quant") && o + 1 < e.length ? a = e[++o] : (h === "-p" || h === "--prompt") && o + 1 < e.length ? s = e[++o] : h.startsWith("--prompt=") ? s = h.slice(9) : (h === "-f" || h === "--file") && o + 1 < e.length ? c = e[++o] : (h === "-s" || h === "--system" || h === "--system-prompt") && o + 1 < e.length ? l = e[++o] : (h === "-n" || h === "--n-predict" || h === "--max-tokens") && o + 1 < e.length ? u = Number(e[++o]) || 256 : (h === "--temp" || h === "--temperature") && o + 1 < e.length ? d = Number(e[++o]) : (h === "--top-k" || h === "--top_k") && o + 1 < e.length ? f = Number(e[++o]) : (h === "--top-p" || h === "--top_p") && o + 1 < e.length ? p = Number(e[++o]) : (h === "-c" || h === "--ctx-size" || h === "--n-ctx") && o + 1 < e.length ? m = Number(e[++o]) || 4096 : (h === "-b" || h === "--batch-size") && o + 1 < e.length ? g = Number(e[++o]) : (h === "-t" || h === "--threads") && o + 1 < e.length ? _ = Number(e[++o]) : (h === "-ngl" || h === "--n-gpu-layers" || h === "--gpu-layers") && o + 1 < e.length ? v = Number(e[++o]) : h === "--no-gpu" || h === "--cpu" ? v = 0 : h === "--webgpu" || h === "--gpu" ? (v === void 0 || v === 0) && (v = 99) : h === "--embeddings" || h === "--embedding" || h === "--embed" ? (y = !0, k ||= "embed") : h === "--raw" || h === "--completion" ? b = !0 : h === "--stream" ? S = !0 : h === "--no-stream" ? S = !1 : h === "--json" ? x = !0 : h === "--no-jinja" ? C = !1 : h.startsWith("-") ? A.push(h) : j.push(h);
|
|
4156
4260
|
}
|
|
4157
|
-
if (
|
|
4158
|
-
let e =
|
|
4261
|
+
if (j.length > 0) {
|
|
4262
|
+
let e = j[0].toLowerCase();
|
|
4159
4263
|
if ([
|
|
4160
4264
|
"info",
|
|
4161
4265
|
"models",
|
|
@@ -4170,45 +4274,45 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4170
4274
|
"pull",
|
|
4171
4275
|
"download"
|
|
4172
4276
|
].includes(e)) {
|
|
4173
|
-
let e =
|
|
4174
|
-
e === "list" ?
|
|
4277
|
+
let e = j.shift().toLowerCase();
|
|
4278
|
+
e === "list" ? k = "models" : e === "embeddings" ? (k = "embed", y = !0) : e === "test-ops" ? k = "bench" : e === "completion" ? (k = "run", b = !0) : e === "download" || e === "pull" ? (k = "pull", w = !0) : k = e;
|
|
4175
4279
|
}
|
|
4176
4280
|
}
|
|
4177
|
-
if (
|
|
4281
|
+
if (j.length > 0 && (!t && !r && (k === "pull" || o[j[0].toLowerCase()] || /\.gguf(\?.*)?$/i.test(j[0]) || /^hf:/i.test(j[0]) || /^https?:\/\//i.test(j[0])) && (t = j.shift()), k === "pull" && j.length > 0 && !T ? T = j.shift() : j.length > 0 && s === null && (s = j.join(" "))), !t && !r && this.context && typeof this.context.getVar == "function") {
|
|
4178
4282
|
let e = this.context.getVar("WLLAMA_MODEL");
|
|
4179
4283
|
e && (t = e);
|
|
4180
4284
|
}
|
|
4181
|
-
let
|
|
4285
|
+
let M = h(t, r, i, a), N = {
|
|
4182
4286
|
n_ctx: m,
|
|
4183
|
-
jinja:
|
|
4287
|
+
jinja: C
|
|
4184
4288
|
};
|
|
4185
|
-
return
|
|
4289
|
+
return v !== void 0 && (N.n_gpu_layers = v), g !== void 0 && (N.n_batch = g), _ !== void 0 && (N.n_threads = _), y && (N.embeddings = !0), {
|
|
4186
4290
|
model: t,
|
|
4187
4291
|
mmproj: n,
|
|
4188
|
-
modelSpec:
|
|
4189
|
-
loadParams:
|
|
4190
|
-
prompt:
|
|
4191
|
-
file:
|
|
4192
|
-
systemPrompt:
|
|
4193
|
-
maxTokens:
|
|
4194
|
-
temperature:
|
|
4195
|
-
topK:
|
|
4292
|
+
modelSpec: M,
|
|
4293
|
+
loadParams: N,
|
|
4294
|
+
prompt: s,
|
|
4295
|
+
file: c,
|
|
4296
|
+
systemPrompt: l,
|
|
4297
|
+
maxTokens: u,
|
|
4298
|
+
temperature: d,
|
|
4299
|
+
topK: f,
|
|
4196
4300
|
topP: p,
|
|
4197
4301
|
nCtx: m,
|
|
4198
|
-
nGpuLayers:
|
|
4199
|
-
embeddings:
|
|
4200
|
-
rawCompletion:
|
|
4201
|
-
jsonOutput:
|
|
4202
|
-
stream:
|
|
4203
|
-
persist:
|
|
4204
|
-
persistPath:
|
|
4205
|
-
showProgress:
|
|
4206
|
-
help:
|
|
4207
|
-
version:
|
|
4208
|
-
subcommand:
|
|
4302
|
+
nGpuLayers: v,
|
|
4303
|
+
embeddings: y,
|
|
4304
|
+
rawCompletion: b,
|
|
4305
|
+
jsonOutput: x,
|
|
4306
|
+
stream: S,
|
|
4307
|
+
persist: w,
|
|
4308
|
+
persistPath: T,
|
|
4309
|
+
showProgress: E,
|
|
4310
|
+
help: D,
|
|
4311
|
+
version: O,
|
|
4312
|
+
subcommand: k,
|
|
4209
4313
|
host: "127.0.0.1",
|
|
4210
4314
|
port: 8080,
|
|
4211
|
-
extraArgs:
|
|
4315
|
+
extraArgs: A
|
|
4212
4316
|
};
|
|
4213
4317
|
}
|
|
4214
4318
|
shouldBeInteractive() {
|
|
@@ -4235,6 +4339,16 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4235
4339
|
_clearStatus() {
|
|
4236
4340
|
!this._parsed.showProgress || this._parsed.jsonOutput || this.stderr && typeof this.stderr.write == "function" && this.stderr.write("\r\x1B[K");
|
|
4237
4341
|
}
|
|
4342
|
+
_createTracker(e = "Loading") {
|
|
4343
|
+
return new m({
|
|
4344
|
+
enabled: !!(this._parsed.showProgress && !this._parsed.jsonOutput),
|
|
4345
|
+
width: 20,
|
|
4346
|
+
intervalMs: 80,
|
|
4347
|
+
onRender: (e) => {
|
|
4348
|
+
this.interactive ? (this._replStatus = e, this._renderRepl()) : e ? this._renderStatus(e) : this._clearStatus();
|
|
4349
|
+
}
|
|
4350
|
+
});
|
|
4351
|
+
}
|
|
4238
4352
|
_attachProgressCallback() {
|
|
4239
4353
|
if (!this._parsed.showProgress || this._parsed.modelSpec.kind === "fs") return;
|
|
4240
4354
|
let e = this._parsed.model || this._parsed.modelSpec.file || this._parsed.modelSpec.repo || this._parsed.modelSpec.url || "model.gguf", t = 0;
|
|
@@ -4242,28 +4356,36 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4242
4356
|
let i = Date.now();
|
|
4243
4357
|
if (t === 0 || r > 0 && n >= r || i - t >= 40) {
|
|
4244
4358
|
t = i;
|
|
4245
|
-
let a =
|
|
4359
|
+
let a = p(e, n, r);
|
|
4246
4360
|
this.interactive ? (this._replStatus = a.replace(/^\r/, ""), this._renderRepl()) : this._parsed.subcommand === "pull" ? (this.stdOut = a, this.flush()) : this._renderStatus(a.replace(/^\r/, ""));
|
|
4247
4361
|
}
|
|
4248
4362
|
};
|
|
4249
4363
|
}
|
|
4250
4364
|
async _initWllama(n = !0) {
|
|
4251
4365
|
n && this._attachProgressCallback();
|
|
4252
|
-
let
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4366
|
+
let r = this._parsed.model || this._parsed.modelSpec.file || this._parsed.modelSpec.repo || this._parsed.modelSpec.url || "model.gguf", i = r.split("/").pop().split("?")[0] || r, a = this._createTracker(), o = (e) => {
|
|
4367
|
+
this.interactive ? (this._replStatus = e, this._renderRepl()) : this._renderStatus(e);
|
|
4368
|
+
};
|
|
4369
|
+
try {
|
|
4370
|
+
let { wllama: r, Wllama: s, persisted: c } = await v({
|
|
4371
|
+
modelSpec: this._parsed.modelSpec,
|
|
4372
|
+
mmprojSpec: this._parsed.mmproj,
|
|
4373
|
+
loadParams: this._parsed.loadParams,
|
|
4374
|
+
fs: this.fs,
|
|
4375
|
+
pkgMeta: e,
|
|
4376
|
+
wbtConfig: t,
|
|
4377
|
+
loadModel: n,
|
|
4378
|
+
persist: this._parsed.persist,
|
|
4379
|
+
persistPath: this._parsed.persistPath,
|
|
4380
|
+
tracker: a,
|
|
4381
|
+
shortLabel: i,
|
|
4382
|
+
isPullCommand: this._parsed.subcommand === "pull",
|
|
4383
|
+
onStatus: o
|
|
4384
|
+
});
|
|
4385
|
+
this._wllama = r, this._WllamaClass = s, this._persisted = c;
|
|
4386
|
+
} finally {
|
|
4387
|
+
a && a.clear(), this.interactive || this._clearStatus();
|
|
4388
|
+
}
|
|
4267
4389
|
}
|
|
4268
4390
|
async initRepl() {
|
|
4269
4391
|
await this._initWllama(!0);
|
|
@@ -4322,39 +4444,46 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4322
4444
|
temperature: this._parsed.temperature,
|
|
4323
4445
|
stream: n
|
|
4324
4446
|
};
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4447
|
+
this._parsed.topK !== void 0 && (r.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (r.top_p = this._parsed.topP);
|
|
4448
|
+
let i = this._createTracker();
|
|
4449
|
+
i.start("Running inference", { hint: "evaluating prompt & preparing KV cache" });
|
|
4450
|
+
try {
|
|
4451
|
+
if (typeof this._wllama.createChatCompletion == "function") {
|
|
4452
|
+
let e = await this._wllama.createChatCompletion(r);
|
|
4453
|
+
if (e && typeof e[Symbol.asyncIterator] == "function") {
|
|
4454
|
+
let n = "", r = !1;
|
|
4455
|
+
for await (let a of e) {
|
|
4456
|
+
let e = a?.choices?.[0]?.delta?.content ?? a?.choices?.[0]?.text ?? "";
|
|
4457
|
+
e && (r || (r = !0, i.clear(), this.interactive ? (this._replStatus = "Streaming tokens...", this._renderRepl()) : this._clearStatus()), n += e, typeof t == "function" && t(e));
|
|
4458
|
+
}
|
|
4459
|
+
return i.clear(), this.interactive || this._clearStatus(), n;
|
|
4332
4460
|
}
|
|
4333
|
-
|
|
4461
|
+
if (i.clear(), this.interactive || this._clearStatus(), this._parsed.jsonOutput) return JSON.stringify(e);
|
|
4462
|
+
let n = y(e);
|
|
4463
|
+
return typeof t == "function" && n && t(n), n;
|
|
4334
4464
|
}
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
let i = r?.choices?.[0]?.text ?? r?.choices?.[0]?.delta?.content ?? "";
|
|
4351
|
-
i && (n || (n = !0, this.interactive ? (this._replStatus = "Streaming tokens...", this._renderRepl()) : this._clearStatus()), e += i, typeof t == "function" && t(i));
|
|
4465
|
+
let a = {
|
|
4466
|
+
prompt: e[e.length - 1]?.content || "",
|
|
4467
|
+
max_tokens: this._parsed.maxTokens,
|
|
4468
|
+
temperature: this._parsed.temperature,
|
|
4469
|
+
stream: n
|
|
4470
|
+
};
|
|
4471
|
+
this._parsed.topK !== void 0 && (a.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (a.top_p = this._parsed.topP);
|
|
4472
|
+
let o = await this._wllama.createCompletion(a);
|
|
4473
|
+
if (o && typeof o[Symbol.asyncIterator] == "function") {
|
|
4474
|
+
let e = "", n = !1;
|
|
4475
|
+
for await (let r of o) {
|
|
4476
|
+
let a = r?.choices?.[0]?.text ?? r?.choices?.[0]?.delta?.content ?? "";
|
|
4477
|
+
a && (n || (n = !0, i.clear(), this.interactive ? (this._replStatus = "Streaming tokens...", this._renderRepl()) : this._clearStatus()), e += a, typeof t == "function" && t(a));
|
|
4478
|
+
}
|
|
4479
|
+
return i.clear(), this.interactive || this._clearStatus(), e;
|
|
4352
4480
|
}
|
|
4353
|
-
|
|
4481
|
+
if (i.clear(), this.interactive || this._clearStatus(), this._parsed.jsonOutput) return JSON.stringify(o);
|
|
4482
|
+
let s = y(o);
|
|
4483
|
+
return typeof t == "function" && s && t(s), s;
|
|
4484
|
+
} finally {
|
|
4485
|
+
i.clear(), this.interactive || this._clearStatus();
|
|
4354
4486
|
}
|
|
4355
|
-
if (this.interactive || this._clearStatus(), this._parsed.jsonOutput) return JSON.stringify(a);
|
|
4356
|
-
let o = g(a);
|
|
4357
|
-
return typeof t == "function" && o && t(o), o;
|
|
4358
4487
|
}
|
|
4359
4488
|
_formatModelInfo() {
|
|
4360
4489
|
let t = this._wllama && typeof this._wllama.isSupportWebGPU == "function" ? this._wllama.isSupportWebGPU() : !!(typeof navigator < "u" && navigator.gpu), n = this._wllama && typeof this._wllama.isMultithread == "function" ? this._wllama.isMultithread() : !1, r = this._wllama && typeof this._wllama.getNumThreads == "function" ? this._wllama.getNumThreads() : 1, i = this._WllamaClass && typeof this._WllamaClass.getLibllamaVersion == "function" ? this._WllamaClass.getLibllamaVersion() : "b6327", a = this._wllama && typeof this._wllama.getModelMetadata == "function" ? this._wllama.getModelMetadata() : null, o = [
|
|
@@ -4371,7 +4500,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4371
4500
|
if (this._parsed.port, e === "pull") {
|
|
4372
4501
|
try {
|
|
4373
4502
|
await this._initWllama(!0);
|
|
4374
|
-
let e = this._persisted && this._persisted.path || this._parsed.persistPath ||
|
|
4503
|
+
let e = this._persisted && this._persisted.path || this._parsed.persistPath || d(this._parsed.modelSpec), t = this._persisted && this._persisted.size || 0, n = t >= 1024 * 1024 ? `${(t / (1024 * 1024)).toFixed(1)} MB` : `${t} B`;
|
|
4375
4504
|
this.stdOut = `Persisted model ${this._parsed.model || this._parsed.modelSpec.key} -> ${e} (${n})`;
|
|
4376
4505
|
} catch (e) {
|
|
4377
4506
|
this.stdErr = `wllama: could not pull model: ${e.message || e}`, this.exitCode = 1;
|
|
@@ -4388,22 +4517,22 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4388
4517
|
let e = [];
|
|
4389
4518
|
this._wllama && this._wllama.modelManager && typeof this._wllama.modelManager.getModels == "function" && (e = await this._wllama.modelManager.getModels());
|
|
4390
4519
|
let t = [];
|
|
4391
|
-
if (this.fs && typeof this.fs.exists == "function" && this.fs.exists(
|
|
4392
|
-
let e = typeof this.fs.getFileByPath == "function" ? this.fs.getFileByPath(
|
|
4520
|
+
if (this.fs && typeof this.fs.exists == "function" && this.fs.exists(l)) {
|
|
4521
|
+
let e = typeof this.fs.getFileByPath == "function" ? this.fs.getFileByPath(l) : null;
|
|
4393
4522
|
if (e && typeof e == "object") for (let n of Object.keys(e)) {
|
|
4394
|
-
let e = `${
|
|
4523
|
+
let e = `${l}/${n}`, i = r(this.fs, e);
|
|
4395
4524
|
t.push({
|
|
4396
4525
|
path: e,
|
|
4397
4526
|
size: i ? i.byteLength : 0
|
|
4398
4527
|
});
|
|
4399
4528
|
}
|
|
4400
4529
|
}
|
|
4401
|
-
if (e.length === 0 &&
|
|
4530
|
+
if (e.length === 0 && u.size === 0 && t.length === 0) {
|
|
4402
4531
|
this.stdOut = "No cached models found.";
|
|
4403
4532
|
return;
|
|
4404
4533
|
}
|
|
4405
4534
|
this.stdOut = "MODEL SIZE STATUS";
|
|
4406
|
-
for (let [e] of
|
|
4535
|
+
for (let [e] of u.entries()) this.stdOut = `${e.split(":gpu=")[0].padEnd(54)} in-memory loaded`;
|
|
4407
4536
|
for (let e of t) {
|
|
4408
4537
|
let t = e.size >= 1024 * 1024 ? `${(e.size / (1024 * 1024)).toFixed(1)} MB` : `${e.size} B`;
|
|
4409
4538
|
this.stdOut = `${e.path.padEnd(54)} ${t.padEnd(11)} persisted (fs)`;
|
|
@@ -4434,7 +4563,7 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4434
4563
|
" wllama bench Run ggml WebGPU/CPU backend ops test",
|
|
4435
4564
|
"",
|
|
4436
4565
|
"Options:",
|
|
4437
|
-
" -m, --model=MODEL Path in brsh
|
|
4566
|
+
" -m, --model=MODEL Path in brsh fs, URL, HF spec, or alias (default: smol [SmolLM2-135M]; also: qwen)",
|
|
4438
4567
|
" --hf=REPO Hugging Face model repository (e.g. Qwen/Qwen2.5-0.5B-Instruct-GGUF)",
|
|
4439
4568
|
" --quant=QUANT Hugging Face GGUF quantization (default: Q4_K_M)",
|
|
4440
4569
|
" --persist[=PATH] Persist pulled remote model into brsh filesystem (default: /var/cache/wllama/)",
|
|
@@ -4486,10 +4615,17 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4486
4615
|
e = String(t);
|
|
4487
4616
|
} else this._parsed.prompt === null ? this.stdin !== void 0 && this.stdin !== null && String(this.stdin).trim().length > 0 && (e = String(this.stdin).trim()) : e = this._parsed.prompt;
|
|
4488
4617
|
if (this._parsed.embeddings || this._parsed.subcommand === "embed") {
|
|
4489
|
-
let t =
|
|
4490
|
-
|
|
4618
|
+
let t = this._createTracker();
|
|
4619
|
+
t.start("Computing embeddings", { hint: "evaluating prompt" });
|
|
4620
|
+
let n;
|
|
4621
|
+
try {
|
|
4622
|
+
n = await this._wllama.createEmbedding({ input: e });
|
|
4623
|
+
} finally {
|
|
4624
|
+
t.clear(), this._clearStatus();
|
|
4625
|
+
}
|
|
4626
|
+
if (this._parsed.jsonOutput) this.stdOut = JSON.stringify(n);
|
|
4491
4627
|
else {
|
|
4492
|
-
let e =
|
|
4628
|
+
let e = n?.data?.[0]?.embedding || n?.embedding || [];
|
|
4493
4629
|
this.stdOut = JSON.stringify(e);
|
|
4494
4630
|
}
|
|
4495
4631
|
return;
|
|
@@ -4501,20 +4637,26 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4501
4637
|
temperature: this._parsed.temperature,
|
|
4502
4638
|
stream: t
|
|
4503
4639
|
};
|
|
4504
|
-
this._parsed.topK !== void 0 && (n.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (n.top_p = this._parsed.topP)
|
|
4505
|
-
let r =
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
n
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4640
|
+
this._parsed.topK !== void 0 && (n.top_k = this._parsed.topK), this._parsed.topP !== void 0 && (n.top_p = this._parsed.topP);
|
|
4641
|
+
let r = this._createTracker();
|
|
4642
|
+
r.start("Running inference", { hint: "evaluating prompt & preparing KV cache" });
|
|
4643
|
+
try {
|
|
4644
|
+
let e = await this._wllama.createCompletion(n), t = "";
|
|
4645
|
+
if (e && typeof e[Symbol.asyncIterator] == "function") {
|
|
4646
|
+
let n = !1;
|
|
4647
|
+
for await (let i of e) {
|
|
4648
|
+
let e = i?.choices?.[0]?.text ?? i?.choices?.[0]?.delta?.content ?? "";
|
|
4649
|
+
e && (n || (n = !0, this._streamedStdout = !0, r.clear(), this._clearStatus()), t += e, this.stdout && typeof this.stdout.write == "function" && this.stdout.write(e), this.emit("token", e));
|
|
4650
|
+
}
|
|
4651
|
+
r.clear(), this._clearStatus(), n && t.length > 0 && !t.endsWith("\n") && this.stdout && typeof this.stdout.write == "function" && this.stdout.write("\r\n");
|
|
4652
|
+
} else r.clear(), this._clearStatus(), t = this._parsed.jsonOutput ? JSON.stringify(e) : y(e);
|
|
4653
|
+
t.split(/\r?\n/).forEach((e) => {
|
|
4654
|
+
this.stdOut = e;
|
|
4655
|
+
});
|
|
4656
|
+
return;
|
|
4657
|
+
} finally {
|
|
4658
|
+
r.clear(), this._clearStatus();
|
|
4659
|
+
}
|
|
4518
4660
|
}
|
|
4519
4661
|
let t = [];
|
|
4520
4662
|
this._parsed.systemPrompt && t.push({
|
|
@@ -4541,26 +4683,26 @@ var R, z, B, V, H, U, W, G, K, q, ee = e((() => {
|
|
|
4541
4683
|
}
|
|
4542
4684
|
return a;
|
|
4543
4685
|
}
|
|
4544
|
-
function
|
|
4686
|
+
function x(e = {}, t = {}) {
|
|
4545
4687
|
return [
|
|
4546
4688
|
{
|
|
4547
4689
|
bin: (e.bin || "wllama").toLowerCase(),
|
|
4548
|
-
Cmd:
|
|
4690
|
+
Cmd: b(e, t, "wllama")
|
|
4549
4691
|
},
|
|
4550
4692
|
{
|
|
4551
4693
|
bin: "llama",
|
|
4552
|
-
Cmd:
|
|
4694
|
+
Cmd: b(e, t, "llama")
|
|
4553
4695
|
},
|
|
4554
4696
|
{
|
|
4555
4697
|
bin: "llama-cli",
|
|
4556
|
-
Cmd:
|
|
4698
|
+
Cmd: b(e, t, "llama-cli")
|
|
4557
4699
|
}
|
|
4558
4700
|
];
|
|
4559
4701
|
}
|
|
4560
|
-
t.exports =
|
|
4702
|
+
t.exports = b, t.exports.createWllamaCommand = b, t.exports.buildEntries = x, t.exports.WllamaCommand = b({
|
|
4561
4703
|
name: "wllama",
|
|
4562
4704
|
version: "3.8.1"
|
|
4563
|
-
}), t.exports.wllamaInstances =
|
|
4705
|
+
}), t.exports.wllamaInstances = u, t.exports.getDefaultPersistPath = d, t.exports.DEFAULT_PERSIST_DIR = l, t.exports.resolveModelSpec = h, t.exports.formatDownloadProgress = p, t.exports.DEFAULT_MODEL_URL = s, t.exports.MODEL_ALIASES = o;
|
|
4564
4706
|
})), se = /* @__PURE__ */ t(((e, t) => {
|
|
4565
4707
|
b();
|
|
4566
4708
|
var r = E(), i = X(), a = Z(), { DEFAULT_REGISTRY: o, resolvePackageName: s } = ie(), c = oe(), { writeBytesToFs: l, createGenericWasmCommand: u } = i, { createReplWasmCommand: d } = a, f = "/var/lib/wbt/installed.json", p = "/var/cache/wbt";
|