@hackbuild/ai-views 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +93 -2
- package/dist/chat.d.ts +91 -0
- package/dist/chat.js +237 -0
- package/dist/dom.d.ts +38 -0
- package/dist/dom.js +67 -0
- package/dist/elements.d.ts +42 -0
- package/dist/elements.js +378 -0
- package/dist/frame.d.ts +55 -0
- package/dist/frame.js +40 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +10 -0
- package/dist/jobs.d.ts +26 -0
- package/dist/jobs.js +49 -0
- package/dist/memory.d.ts +26 -0
- package/dist/memory.js +36 -0
- package/dist/mount-chat.d.ts +38 -0
- package/dist/mount-chat.js +177 -0
- package/dist/mount-frame.d.ts +45 -0
- package/dist/mount-frame.js +237 -0
- package/dist/mount-mask.d.ts +109 -0
- package/dist/mount-mask.js +446 -0
- package/dist/mount-model.d.ts +27 -0
- package/dist/mount-model.js +122 -0
- package/dist/mount-transcribe.d.ts +42 -0
- package/dist/mount-transcribe.js +203 -0
- package/dist/pick.d.ts +132 -0
- package/dist/pick.js +254 -0
- package/dist/rows.d.ts +36 -0
- package/dist/rows.js +147 -0
- package/dist/single/elements.iife.js +9568 -0
- package/dist/single/elements.js +9542 -0
- package/dist/single/index.iife.js +6814 -0
- package/dist/single/index.js +6778 -0
- package/dist/single/vue.iife.js +11334 -0
- package/dist/single/vue.js +11316 -0
- package/dist/transcribe.d.ts +80 -0
- package/dist/transcribe.js +175 -0
- package/dist/vue.d.ts +259 -0
- package/dist/vue.js +199 -0
- package/how.ts +26 -0
- package/package.json +61 -4
package/dist/rows.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalogue records to hackbuild-ui ModelRow: every word a person reads in
|
|
3
|
+
* the picker is written here, once. The kit draws rows and never reads a
|
|
4
|
+
* record; this module never draws.
|
|
5
|
+
*/
|
|
6
|
+
import { fitOf, ladderFor } from "@hackbuild/models";
|
|
7
|
+
import { bytesText } from "@virgilvox/hackbuild-ui/vanilla";
|
|
8
|
+
const MIB = 1024 * 1024;
|
|
9
|
+
/** Catalogue group words to the sheet's groups. */
|
|
10
|
+
const GROUPS = {
|
|
11
|
+
"start here": "start",
|
|
12
|
+
tiny: "small",
|
|
13
|
+
cpu: "small",
|
|
14
|
+
good: "better",
|
|
15
|
+
uncensored: "uncensored",
|
|
16
|
+
reasoning: "reasoning",
|
|
17
|
+
"no download": "none",
|
|
18
|
+
own: "own",
|
|
19
|
+
};
|
|
20
|
+
export function isNoDownload(r) {
|
|
21
|
+
return !!r.noDownload || r.sizeMB === 0 || r.provider === "prompt-api" || r.provider === "system";
|
|
22
|
+
}
|
|
23
|
+
export function isUncensored(r) {
|
|
24
|
+
return r.censorship === "uncensored" || r.censorship === "abliterated";
|
|
25
|
+
}
|
|
26
|
+
/** The group a row sits in. A model on this machine leads; else the record's group, else by size. */
|
|
27
|
+
export function groupOf(r, state = "none") {
|
|
28
|
+
if (state === "stored" || state === "loaded")
|
|
29
|
+
return "here";
|
|
30
|
+
if (r.group && GROUPS[r.group])
|
|
31
|
+
return GROUPS[r.group];
|
|
32
|
+
if (isNoDownload(r))
|
|
33
|
+
return "none";
|
|
34
|
+
if (isUncensored(r))
|
|
35
|
+
return "uncensored";
|
|
36
|
+
return r.sizeMB !== null && r.sizeMB < 600 ? "small" : "better";
|
|
37
|
+
}
|
|
38
|
+
/** Where it runs here: the first rung this machine can take, else the record's first. */
|
|
39
|
+
export function backendOf(r, env) {
|
|
40
|
+
if (r.provider === "remote")
|
|
41
|
+
return "remote";
|
|
42
|
+
const rung = ladderFor(r, env).rungs[0] ?? r.ladder[0];
|
|
43
|
+
switch (rung?.device) {
|
|
44
|
+
case "webgpu":
|
|
45
|
+
case "webgl":
|
|
46
|
+
return "gpu";
|
|
47
|
+
case "browser":
|
|
48
|
+
return "browser";
|
|
49
|
+
case "remote":
|
|
50
|
+
return "remote";
|
|
51
|
+
default:
|
|
52
|
+
return "cpu";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Download words: "1.7 gb". Null for a record with no download or an unknown size. */
|
|
56
|
+
export function sizeWords(r) {
|
|
57
|
+
if (isNoDownload(r) || r.sizeMB === null)
|
|
58
|
+
return undefined;
|
|
59
|
+
return bytesText(r.sizeMB * MIB);
|
|
60
|
+
}
|
|
61
|
+
/** The record's label, else its id made readable: "hermes 3 llama 3.2 3b". */
|
|
62
|
+
const pretty = (r) => r.label ?? r.id.replace(/-(mlc|gguf)$/, "").replace(/-/g, " ");
|
|
63
|
+
/** The chevron detail: licence, source, context, quant, runtime, and where the size came from. */
|
|
64
|
+
export function detailOf(r) {
|
|
65
|
+
const out = [];
|
|
66
|
+
const use = r.commercial === true ? "commercial use allowed" : r.commercial === false ? "not for commercial use" : "commercial use unknown";
|
|
67
|
+
out.push({ label: "licence", value: `${r.licence}. ${use}` });
|
|
68
|
+
const src = r.source.repo ?? r.source.modelId ?? r.source.url;
|
|
69
|
+
if (src)
|
|
70
|
+
out.push({ label: "source", value: r.source.file ? `${src}, ${r.source.file}` : src });
|
|
71
|
+
if (r.sizeMB !== null && !isNoDownload(r))
|
|
72
|
+
out.push({ label: "size", value: `${bytesText(r.sizeMB * MIB)}, ${r.sizeSource}` });
|
|
73
|
+
if (r.vramMB != null)
|
|
74
|
+
out.push({ label: "gpu memory", value: `${bytesText(r.vramMB * MIB)}, ${r.vramSource ?? "unknown"}` });
|
|
75
|
+
if (r.ctx)
|
|
76
|
+
out.push({ label: "context", value: `${r.ctx} tokens` });
|
|
77
|
+
if (r.quant)
|
|
78
|
+
out.push({ label: "quant", value: r.quant });
|
|
79
|
+
if (r.runtime)
|
|
80
|
+
out.push({ label: "runtime", value: r.runtime });
|
|
81
|
+
for (const n of r.notes ?? [])
|
|
82
|
+
out.push({ label: "note", value: n });
|
|
83
|
+
for (const w of r.quirks?.warnings ?? [])
|
|
84
|
+
out.push({ label: "warning", value: w });
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/** Context sizes a chat record can take, up to its own. */
|
|
88
|
+
const CTX = [2048, 4096, 8192, 16384, 32768];
|
|
89
|
+
/** The options a chosen row offers: backend when the ladder has gpu and cpu, quant when it has several, context for chat. */
|
|
90
|
+
export function optionsOf(r, values = {}, extra = []) {
|
|
91
|
+
const out = [];
|
|
92
|
+
const devices = new Set(r.ladder.map((g) => (g.device === "webgpu" ? "webgpu" : g.device === "wasm" || g.device === "cpu" ? "wasm" : g.device)));
|
|
93
|
+
if (devices.has("webgpu") && devices.has("wasm")) {
|
|
94
|
+
out.push({ key: "backend", label: "backend", value: values.backend ?? "auto", choices: [{ value: "auto", label: "auto" }, { value: "webgpu", label: "webgpu" }, { value: "wasm", label: "wasm, cpu" }] });
|
|
95
|
+
}
|
|
96
|
+
const dtypes = [...new Set(r.ladder.map((g) => (typeof g.dtype === "string" ? g.dtype : null)).filter((d) => !!d))];
|
|
97
|
+
if (dtypes.length > 1)
|
|
98
|
+
out.push({ key: "quant", label: "quant", value: values.quant ?? dtypes[0], choices: dtypes.map((d) => ({ value: d, label: d })) });
|
|
99
|
+
if (r.provides.includes("chat") && r.ctx && r.provider !== "remote") {
|
|
100
|
+
const sizes = CTX.filter((c) => c <= Math.max(r.ctx, 2048));
|
|
101
|
+
if (sizes.length > 1)
|
|
102
|
+
out.push({ key: "context", label: "context", value: values.context ?? String(r.ctx), choices: sizes.map((c) => ({ value: String(c), label: `${c / 1024}k` })) });
|
|
103
|
+
}
|
|
104
|
+
return [...out, ...extra];
|
|
105
|
+
}
|
|
106
|
+
/** One record as one picker row. */
|
|
107
|
+
export function rowOf(r, ctx = {}) {
|
|
108
|
+
const state = ctx.state ?? "none";
|
|
109
|
+
// the system voice runs wherever speechSynthesis does; its ladder's browser rung reads as a prompt api need
|
|
110
|
+
const fit = r.provider === "system" ? { fit: "fits", ok: true, reason: "" } : fitOf(r, ctx.env, ctx.estimate ?? null);
|
|
111
|
+
const size = sizeWords(r);
|
|
112
|
+
const row = {
|
|
113
|
+
id: r.id,
|
|
114
|
+
name: pretty(r),
|
|
115
|
+
group: ctx.own ? "own" : groupOf(r, state),
|
|
116
|
+
backend: backendOf(r, ctx.env),
|
|
117
|
+
state,
|
|
118
|
+
};
|
|
119
|
+
if (size)
|
|
120
|
+
row.size = size;
|
|
121
|
+
if (r.vramMB != null)
|
|
122
|
+
row.memory = `needs ${bytesText(r.vramMB * MIB)}`;
|
|
123
|
+
if (r.sizeMB !== null && !isNoDownload(r))
|
|
124
|
+
row.bytes = r.sizeMB * MIB;
|
|
125
|
+
const speed = fit.fit === "fits on cpu, slow" ? "slow" : r.speed;
|
|
126
|
+
if (speed)
|
|
127
|
+
row.speed = speed;
|
|
128
|
+
if (r.verdict ?? r.badge)
|
|
129
|
+
row.verdict = (r.verdict ?? r.badge);
|
|
130
|
+
if (isUncensored(r))
|
|
131
|
+
row.uncensored = true;
|
|
132
|
+
if (r.commercial === false)
|
|
133
|
+
row.noncommercial = true;
|
|
134
|
+
if (isNoDownload(r))
|
|
135
|
+
row.noDownload = true;
|
|
136
|
+
if (!fit.ok)
|
|
137
|
+
row.unfit = fit.reason;
|
|
138
|
+
if (state === "loading")
|
|
139
|
+
row.progress = ctx.progress ?? 0;
|
|
140
|
+
const detail = detailOf(r);
|
|
141
|
+
if (detail.length)
|
|
142
|
+
row.detail = detail;
|
|
143
|
+
const options = optionsOf(r, ctx.options, ctx.extra);
|
|
144
|
+
if (options.length)
|
|
145
|
+
row.options = options;
|
|
146
|
+
return row;
|
|
147
|
+
}
|