Files
Ilker ManapandClaude Opus 5.5 a53b2f4be9 Customise a model from the portal: a file, a model, a button
A page for anyone in a project, built for the one who knows least: an
Excel, CSV or JSONL file of questions and answers, previewed; a model; a
name; who may use it; and a button. The weights to train on are found
from where the model's came (a GGUF repository's base model), the card's
memory from their size, the node as the one with the most free. When it
is done the adapter is published by itself (a llama.cpp model's replicas
replaced to load it) and is a model of its own in the chat and the API.

The project's by default; its members share it wider (confirmed, and
never wider than the knowledge bases its pairs came from) or delete it.
One trains at a time per project. ctl train start needs only --model and
--data now, and --publish publishes when done.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 11:31:12 +01:00

288 lines
12 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{{define "train"}}<!doctype html>
<html lang="{{lang}}"><head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>{{t "train.title"}} · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
<script defer src="{{asset "pages.js"}}"></script>
<meta name="csrf" content="{{.CSRF}}">
<style>
.train-steps { display: grid; gap: .9rem; max-width: 44rem; }
.train-steps .step { border: 1px solid var(--line, #ddd); border-radius: 8px; padding: .8rem 1rem; background: var(--card); }
.train-steps .step h2 { font-size: 1rem; margin: 0 0 .4rem; }
.train-steps select, .train-steps input[type=text] { width: 100%; max-width: 28rem; }
.train-sample { margin-top: .5rem; }
.train-sample td { vertical-align: top; }
.train-confirm { font-weight: 400; }
.train-bar { height: .5rem; background: var(--line, #ddd); border-radius: 3px; overflow: hidden; margin-top: .25rem; max-width: 14rem; }
.train-bar > span { display: block; height: 100%; background: var(--accent); }
#jobs td { vertical-align: top; }
</style>
</head><body><div class="wrap">
<header>
<h1>{{t "train.title"}}</h1>
<p class="sub">{{.User.Email}}</p>
{{template "nav" .Nav}}
</header>
<p>{{t "train.intro"}}</p>
<p class="note">{{th "train.not_knowledge"}}</p>
{{if not .Projects}}
<p class="empty">{{t "train.no_project"}}</p>
{{else if not .Models}}
<p class="empty">{{t "train.no_models"}}</p>
{{else}}
<form id="start" class="train-steps">
<div class="step">
<h2>{{t "train.step.file"}}</h2>
<p class="note">{{t "train.file_hint"}}</p>
<input type="file" id="file" accept=".xlsx,.xlsm,.csv,.tsv,.txt,.jsonl,.ndjson,.json">
<p id="found" class="note" aria-live="polite"></p>
<table id="sample" class="compact train-sample" hidden>
<thead><tr><th>{{t "train.question"}}</th><th>{{t "train.answer"}}</th></tr></thead><tbody></tbody>
</table>
</div>
<div class="step">
<h2>{{t "train.step.model"}}</h2>
<label>{{t "train.base"}}
<select id="model">{{range .Models}}<option>{{.}}</option>{{end}}</select></label>
<label>{{t "train.name"}} <span class="opt">{{t "train.name_hint"}}</span>
<input type="text" id="name" maxlength="100" pattern="[A-Za-z0-9][A-Za-z0-9._\-]*" required></label>
</div>
<div class="step">
<h2>{{t "train.step.who"}}</h2>
{{if gt (len .Projects) 1}}
<label>{{t "train.project"}}
<select id="project">{{range .Projects}}<option value="{{.Value}}">{{.Label}}</option>{{end}}</select></label>
{{else}}{{with index .Projects 0}}<input type="hidden" id="project" value="{{.Value}}">
<p class="note">{{t "train.project"}}: {{.Label}}</p>{{end}}{{end}}
<label>{{t "train.share"}}
<select id="share">
<option value="me">{{t "train.share.me"}}</option>
<option value="project" selected>{{t "train.share.project"}}</option>
<option value="team">{{t "train.share.team"}}</option>
<option value="org">{{t "train.share.org"}}</option>
<option value="all">{{t "train.share.all"}}</option>
</select></label>
<label class="train-confirm" id="confirm-row" hidden><input type="checkbox" id="agree"> {{t "train.confirm"}}</label>
</div>
<div><button type="submit" id="go">{{t "train.go"}}</button></div>
<p id="status" class="note" aria-live="polite"></p>
</form>
{{end}}
<h2>{{t "train.jobs"}}</h2>
<table id="jobs" class="compact">
<thead><tr><th>{{t "train.col.name"}}</th><th>{{t "train.col.state"}}</th><th>{{t "train.col.share"}}</th><th></th></tr></thead>
<tbody></tbody>
</table>
<p id="nojobs" class="empty" hidden>{{t "train.no_jobs"}}</p>
<p class="note">{{t "train.after"}}</p>
<footer><span>llmgw {{.Version}}</span><span>{{stamp .Now}}</span>{{template "langs"}}</footer>
</div>
<script>
const say = {
found: {{t "train.js.found"}},
skipped: {{t "train.js.skipped"}},
few: {{t "train.js.few"}},
noFile: {{t "train.js.no_file"}},
noName: {{t "train.js.no_name"}},
needConfirm: {{t "train.js.need_confirm"}},
started: {{t "train.js.started"}},
failed: {{t "train.js.failed"}},
queued: {{t "train.js.queued"}},
waiting: {{t "train.js.waiting"}},
preparing: {{t "train.js.preparing"}},
running: {{t "train.js.running"}},
publishing: {{t "train.js.publishing"}},
ready: {{t "train.js.ready"}},
restarting: {{t "train.js.restarting"}},
notPublished: {{t "train.js.not_published"}},
jobFailed: {{t "train.js.job_failed"}},
cancelled: {{t "train.js.cancelled"}},
del: {{t "train.js.delete"}},
delAsk: {{t "train.js.delete_ask"}},
shareAsk: {{t "train.js.share_ask"}},
tryIt: {{t "train.js.try"}},
by: {{t "train.js.by"}},
shares: { me: {{t "train.share.me"}}, project: {{t "train.share.project"}}, team: {{t "train.share.team"}},
org: {{t "train.share.org"}}, all: {{t "train.share.all"}}, other: {{t "train.share.other"}} },
};
function fill(s, vals) { return s.replace(/\{(\w+)\}/g, (m, k) => (k in vals ? String(vals[k]) : m)); }
(function () {
const csrf = document.querySelector('meta[name="csrf"]').content;
const $ = (id) => document.getElementById(id);
const wide = (s) => s === "team" || s === "org" || s === "all";
async function post(url, data) {
const resp = await fetch(url, { method: "POST", headers: { "X-CSRF-Token": csrf }, body: data });
const j = await resp.json().catch(() => ({}));
if (!resp.ok) throw new Error(j.error || String(resp.status));
return j;
}
const form = $("start");
if (form) {
const file = $("file"), found = $("found"), sample = $("sample"), status = $("status"), go = $("go");
let pairs = 0;
file.addEventListener("change", async () => {
const f = file.files[0];
pairs = 0;
sample.hidden = true;
found.classList.remove("bad");
if (!f) { found.textContent = ""; return; }
if (!$("name").value) {
$("name").value = f.name.replace(/\.[^.]*$/, "").toLowerCase()
.replace(/[çğıöşü]/g, (c) => ({ "ç": "c", "ğ": "g", "ı": "i", "ö": "o", "ş": "s", "ü": "u" })[c])
.replace(/[^a-z0-9._-]+/g, "-").replace(/^[^a-z0-9]+|-+$/g, "").slice(0, 100);
}
const fd = new FormData();
fd.append("file", f);
try {
const j = await post("/train/preview", fd);
pairs = j.pairs;
let line = fill(say.found, { n: j.pairs });
if (j.skipped) line += " " + fill(say.skipped, { n: j.skipped });
if (j.pairs < 50) line += " " + say.few;
found.textContent = line;
const body = sample.tBodies[0];
body.replaceChildren();
for (const p of j.sample) {
const tr = body.insertRow();
tr.insertCell().textContent = p.q;
tr.insertCell().textContent = p.a;
}
sample.hidden = false;
} catch (err) {
found.textContent = err.message;
found.classList.add("bad");
}
});
const share = $("share"), confirmRow = $("confirm-row");
share.addEventListener("change", () => { confirmRow.hidden = !wide(share.value); });
form.addEventListener("submit", async (e) => {
e.preventDefault();
status.classList.remove("bad");
if (!file.files[0] || !pairs) { status.textContent = say.noFile; return; }
if (!$("name").value.trim()) { status.textContent = say.noName; return; }
if (wide(share.value) && !$("agree").checked) { status.textContent = say.needConfirm; return; }
const fd = new FormData();
fd.append("file", file.files[0]);
fd.append("name", $("name").value.trim());
fd.append("model", $("model").value);
fd.append("project", $("project").value);
fd.append("share", share.value);
if ($("agree").checked) fd.append("confirm", "yes");
go.disabled = true;
try {
await post("/train/start", fd);
status.textContent = say.started;
form.reset();
found.textContent = "";
sample.hidden = true;
confirmRow.hidden = true;
pairs = 0;
refresh();
} catch (err) {
status.textContent = fill(say.failed, { why: err.message });
status.classList.add("bad");
} finally {
go.disabled = false;
}
});
}
function describe(j) {
switch (j.state) {
case "queued": return j.message && j.message.startsWith("waiting") ? say.waiting : say.queued;
case "starting": case "preparing": return say.preparing;
case "running": return fill(say.running, { p: j.steps ? Math.floor(100 * j.step / j.steps) : 0, m: j.minutes });
case "done":
if (j.published) return j.message && j.message.includes("restarting") ? fill(say.restarting, { name: j.name }) : fill(say.ready, { name: j.name });
if (j.message && j.message.startsWith("trained, but")) return fill(say.notPublished, { why: j.message });
return say.publishing;
case "failed": return fill(say.jobFailed, { why: j.message || "" });
case "cancelled": return say.cancelled;
}
return j.state;
}
const over = (j) => j.state === "failed" || j.state === "cancelled" ||
(j.state === "done" && (j.published || (j.message || "").startsWith("trained, but")));
let timer = null;
async function refresh() {
clearTimeout(timer);
const resp = await fetch("/train/jobs");
const jobs = await resp.json().catch(() => []);
const body = $("jobs").tBodies[0];
body.replaceChildren();
$("nojobs").hidden = jobs.length > 0;
$("jobs").hidden = jobs.length === 0;
for (const j of jobs) {
const tr = body.insertRow();
const name = tr.insertCell();
const b = document.createElement("strong");
b.textContent = j.name;
const sub = document.createElement("div");
sub.className = "note";
sub.textContent = j.model + " · " + j.pairs + " · " + (j.project || "") + " · " + fill(say.by, { who: j.created_by });
name.append(b, sub);
const st = tr.insertCell();
st.textContent = describe(j);
if (j.state === "failed") st.classList.add("bad");
if (j.state === "running" && j.steps) {
const bar = document.createElement("div");
bar.className = "train-bar";
const fillBar = document.createElement("span");
fillBar.style.width = Math.floor(100 * j.step / j.steps) + "%";
bar.append(fillBar);
st.append(bar);
}
const sh = tr.insertCell();
const sel = document.createElement("select");
for (const k of ["me", "project", "team", "org", "all"]) {
if (!j.project && k !== "me" && k !== "all") continue;
const o = new Option(say.shares[k], k, false, j.share === k);
sel.add(o);
}
if (j.share === "other") sel.add(new Option(say.shares.other, "other", true, true));
sel.addEventListener("change", async () => {
const fd = new FormData();
fd.append("share", sel.value);
if (wide(sel.value)) {
if (!confirm(say.shareAsk)) { refresh(); return; }
fd.append("confirm", "yes");
}
try { await post("/train/jobs/" + encodeURIComponent(j.id) + "/share", fd); }
catch (err) { alert(err.message); }
refresh();
});
sh.append(sel);
const act = tr.insertCell();
if (j.published) {
const a = document.createElement("a");
a.href = "/chat";
a.className = "link";
a.textContent = say.tryIt;
act.append(a, " ");
}
const del = document.createElement("button");
del.type = "button";
del.className = "link";
del.textContent = say.del;
del.addEventListener("click", async () => {
if (!confirm(fill(say.delAsk, { name: j.name }))) return;
try { await post("/train/jobs/" + encodeURIComponent(j.id) + "/delete", new FormData()); }
catch (err) { alert(err.message); }
refresh();
});
act.append(del);
}
if (jobs.some((j) => !over(j))) timer = setTimeout(refresh, 5000);
}
refresh();
})();
</script>
</body></html>{{end}}