The portal in English and Turkish: a catalogue per language, a switcher at the foot of every page, landing.language, Turkish numbers and dates
Every template and handler message in internal/web goes through a JSON
catalogue under internal/web/locales/<code>/, with English as the fallback.
The language is the person's choice (a cookie set by /_lang/{code}), else
Accept-Language, else landing.language. Tests refuse a key some language
lacks, a translation with other arguments than English, and template text
left in English.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
30f7f3474a
commit
11231d8c2b
113 files changed
+8091
-1981
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{{define "chat"}}<!doctype html>
|
||||
<html lang="en"><head>
|
||||
<html lang="{{lang}}"><head>
|
||||
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Chat · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
<title>{{t "chat.title"}} · llmgw</title><link rel="stylesheet" href="{{stylesheet}}">
|
||||
<link rel="stylesheet" href="/_static/katex/katex.min.css">
|
||||
<script defer src="/_static/katex/katex.min.js"></script>
|
||||
<script defer src="/_static/katex/auto-render.min.js"></script>
|
||||
@@ -9,7 +9,7 @@
|
||||
<meta name="csrf" content="{{.CSRF}}">
|
||||
</head><body><div class="wrap">
|
||||
<header>
|
||||
<h1>Chat</h1>
|
||||
<h1>{{t "chat.title"}}</h1>
|
||||
<p class="sub">{{.User.Email}}</p>
|
||||
{{template "nav" .Nav}}
|
||||
</header>
|
||||
@@ -19,62 +19,85 @@
|
||||
below is the one this choice allows; the server checks it again on every
|
||||
message rather than trusting the page. */}}
|
||||
<form method="get" action="/chat" class="chat-context">
|
||||
<label class="inline-label">Using
|
||||
<label class="inline-label">{{t "chat.context.using"}}
|
||||
<select id="context" name="context" data-autosubmit>
|
||||
{{range .Contexts}}<option value="{{.Value}}"{{if eq .Value $.Context}} selected{{end}}>{{.Label}}</option>{{end}}
|
||||
</select></label>
|
||||
<noscript><button type="submit" class="link">switch</button></noscript>
|
||||
{{/* translate="no" only because a parser reads noscript as raw text and
|
||||
would take the markup for prose; the label is translated. */}}
|
||||
<noscript translate="no"><button type="submit" class="link">{{t "chat.context.switch"}}</button></noscript>
|
||||
</form>
|
||||
{{else if .Contexts}}{{with index .Contexts 0}}<input type="hidden" id="context" value="{{.Value}}">{{end}}{{end}}
|
||||
|
||||
{{if .Models}}
|
||||
<div class="chat-bar">
|
||||
<label class="inline-label">Model
|
||||
<select id="model">{{range .Models}}<option value="{{.Name}}" data-simulated="{{if .Simulated}}1{{else}}0{{end}}" data-ondemand="{{if .OnDemand}}1{{else}}0{{end}}">{{.Name}}{{with .Runs}} · {{.}}{{end}}{{if .Simulated}} (simulated){{end}}{{if .OnDemand}} (not loaded){{end}}</option>{{end}}</select>
|
||||
<label class="inline-label">{{t "chat.model"}}
|
||||
<select id="model">{{range .Models}}<option value="{{.Name}}" data-simulated="{{if .Simulated}}1{{else}}0{{end}}" data-ondemand="{{if .OnDemand}}1{{else}}0{{end}}">{{.Name}}{{with .Runs}} · {{.}}{{end}}{{if .Simulated}} {{t "chat.model.simulated"}}{{end}}{{if .OnDemand}} {{t "chat.model.not_loaded"}}{{end}}</option>{{end}}</select>
|
||||
</label>
|
||||
<button id="reset" type="button" class="link">New conversation</button>
|
||||
<button id="reset" type="button" class="link">{{t "chat.new"}}</button>
|
||||
</div>
|
||||
|
||||
<details class="chat-settings" id="settings">
|
||||
<summary>Settings</summary>
|
||||
<label>System prompt <span class="opt">how the model should behave, sent before every turn</span>
|
||||
<textarea id="system" rows="2" placeholder="You are a concise assistant. Answer in the language of the question."></textarea></label>
|
||||
<label class="temp">Temperature <output id="temp-out">0.7</output>
|
||||
<summary>{{t "chat.settings"}}</summary>
|
||||
<label>{{t "chat.settings.system"}} <span class="opt">{{t "chat.settings.system_hint"}}</span>
|
||||
<textarea id="system" rows="2" placeholder="{{t "chat.settings.system_placeholder"}}"></textarea></label>
|
||||
<label class="temp">{{t "chat.settings.temperature"}} <output id="temp-out">{{num 0.7 1}}</output>
|
||||
<input type="range" id="temperature" min="0" max="2" step="0.1" value="0.7">
|
||||
<span class="opt">lower is steadier, higher more varied</span></label>
|
||||
<span class="opt">{{t "chat.settings.temperature_hint"}}</span></label>
|
||||
</details>
|
||||
|
||||
<p id="sim-note" class="note" hidden>
|
||||
This model is simulated: it exercises scheduling and reports timings, and its
|
||||
replies are placeholder text, not inference.
|
||||
</p>
|
||||
<p id="sim-note" class="note" hidden>{{t "chat.note.simulated"}}</p>
|
||||
|
||||
<p id="ondemand-note" class="note" hidden>
|
||||
This model is not running. The first message loads it onto a node — fetching
|
||||
its weights and starting the engine, minutes for a large model — and is sent
|
||||
once it is up.
|
||||
</p>
|
||||
<p id="ondemand-note" class="note" hidden>{{t "chat.note.on_demand"}}</p>
|
||||
|
||||
<div id="log" class="chat-log" aria-live="polite"></div>
|
||||
|
||||
<form id="composer" class="chat-composer">
|
||||
<textarea id="input" rows="3" placeholder="Ask something…" required></textarea>
|
||||
<button type="submit" id="send">Send</button>
|
||||
<textarea id="input" rows="3" placeholder="{{t "chat.input_placeholder"}}" required></textarea>
|
||||
<button type="submit" id="send">{{t "chat.send"}}</button>
|
||||
</form>
|
||||
<p class="note">The conversation is kept in this browser, so a reload does not lose it;
|
||||
"New conversation" clears it. Nothing of it is stored on the gateway — what is
|
||||
recorded there is the same usage any request records: tokens, cost and latency.</p>
|
||||
<p class="note">{{t "chat.kept"}}</p>
|
||||
{{else}}
|
||||
<p class="empty">No models are available to you right now.</p>
|
||||
<p class="note">Either nothing is placed yet, or your project's allowlist does
|
||||
not include anything that is. <code>/admin</code> shows the cluster if you have
|
||||
access to it.</p>
|
||||
<p class="empty">{{t "chat.empty"}}</p>
|
||||
<p class="note">{{th "chat.empty_why"}}</p>
|
||||
{{end}}
|
||||
|
||||
<footer><span>llmgw {{.Version}}</span><span>{{.Now}}</span></footer>
|
||||
<footer><span>llmgw {{.Version}}</span><span>{{.Now}}</span>{{template "langs"}}</footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// What the script says, in the page's language. The template writes each
|
||||
// text as a JavaScript string; {name} marks where a value goes, so a
|
||||
// language can put it where its grammar wants it.
|
||||
const say = {
|
||||
preparing: {{t "chat.js.preparing"}},
|
||||
downloadFailed: {{t "chat.js.download_failed"}},
|
||||
stageWaiting: {{t "chat.js.stage.waiting"}},
|
||||
stageDownloading: {{t "chat.js.stage.downloading"}},
|
||||
stageStarting: {{t "chat.js.stage.starting"}},
|
||||
stageReady: {{t "chat.js.stage.ready"}},
|
||||
of: {{t "chat.js.of"}},
|
||||
couldNotStart: {{t "chat.js.could_not_start"}},
|
||||
tokens: {{t "chat.js.tokens"}},
|
||||
tokPerS: {{t "chat.js.tok_per_s"}},
|
||||
firstToken: {{t "chat.js.first_token"}},
|
||||
seconds: {{t "chat.js.seconds"}},
|
||||
stopped: {{t "chat.js.stopped"}},
|
||||
stop: {{t "chat.js.stop"}},
|
||||
send: {{t "chat.send"}},
|
||||
refused: {{t "chat.js.refused"}},
|
||||
downloadZip: {{t "chat.js.download_zip"}},
|
||||
stoppedByPolicy: {{t "chat.js.stopped_by_policy"}},
|
||||
cutOff: {{t "chat.js.cut_off"}},
|
||||
stoppedByPolicyEmpty: {{t "chat.js.stopped_by_policy_empty"}},
|
||||
stoppedEmpty: {{t "chat.js.stopped_empty"}},
|
||||
noContent: {{t "chat.js.no_content"}},
|
||||
decimal: {{t "_meta.decimal"}},
|
||||
};
|
||||
// fill puts values into a text from say.
|
||||
function fill(s, vals) { return s.replace(/\{(\w+)\}/g, (m, k) => (k in vals ? String(vals[k]) : m)); }
|
||||
// fixed is toFixed with the language's decimal separator.
|
||||
function fixed(n, places) { return n.toFixed(places).replace(".", say.decimal); }
|
||||
// The policy a guardrail acted by, when the response says.
|
||||
function policySuffix(resp) {
|
||||
const p = resp.headers.get("x-llmgw-guard-policy");
|
||||
@@ -111,7 +134,7 @@ access to it.</p>
|
||||
system: sys.value, temperature: temp.value }));
|
||||
} catch (_) { /* no storage: nothing kept */ }
|
||||
};
|
||||
temp.addEventListener("input", () => { tempOut.textContent = (+temp.value).toFixed(1); save(); });
|
||||
temp.addEventListener("input", () => { tempOut.textContent = fixed(+temp.value, 1); save(); });
|
||||
sys.addEventListener("change", save);
|
||||
|
||||
document.getElementById("reset").onclick = () => { messages = []; log.textContent = ""; save(); };
|
||||
@@ -214,7 +237,7 @@ access to it.</p>
|
||||
async function downloadCode(reply, btn) {
|
||||
const was = btn.textContent;
|
||||
btn.disabled = true;
|
||||
btn.textContent = "Preparing…";
|
||||
btn.textContent = say.preparing;
|
||||
try {
|
||||
const resp = await fetch("/chat/download", {
|
||||
method: "POST",
|
||||
@@ -234,7 +257,7 @@ access to it.</p>
|
||||
URL.revokeObjectURL(url);
|
||||
btn.textContent = was;
|
||||
} catch (err) {
|
||||
btn.textContent = "download failed";
|
||||
btn.textContent = say.downloadFailed;
|
||||
} finally {
|
||||
btn.disabled = false;
|
||||
}
|
||||
@@ -242,12 +265,12 @@ access to it.</p>
|
||||
|
||||
const ctxValue = () => (document.getElementById("context") || {}).value || "";
|
||||
const stages = {
|
||||
waiting: "Waiting for a node with room",
|
||||
downloading: "Downloading weights",
|
||||
starting: "Starting the engine",
|
||||
ready: "Ready",
|
||||
waiting: say.stageWaiting,
|
||||
downloading: say.stageDownloading,
|
||||
starting: say.stageStarting,
|
||||
ready: say.stageReady,
|
||||
};
|
||||
function mib(n) { return (n / 1048576).toFixed(0) + " MiB"; }
|
||||
function mib(n) { return fixed(n / 1048576, 0) + " MiB"; }
|
||||
|
||||
// Loads a model that is not running and shows how far along it is, in the
|
||||
// reply's own bubble. Resolves true once it answers, false if it cannot.
|
||||
@@ -277,8 +300,8 @@ access to it.</p>
|
||||
st = await resp.json();
|
||||
for (;;) {
|
||||
const secs = Math.round((Date.now() - started) / 1000);
|
||||
let text = (stages[st.state] || st.state) + " — " + secs + "s";
|
||||
if (st.state === "downloading" && st.total) text += " · " + mib(st.done) + " of " + mib(st.total);
|
||||
let text = (stages[st.state] || st.state) + " — " + fill(say.seconds, { n: secs });
|
||||
if (st.state === "downloading" && st.total) text += " · " + fill(say.of, { done: mib(st.done), total: mib(st.total) });
|
||||
label.textContent = text;
|
||||
// Indeterminate (no value) unless there is a real number: a bar that
|
||||
// sits at 0% for the engine start says it is stuck when it is not.
|
||||
@@ -288,7 +311,7 @@ access to it.</p>
|
||||
// control plane places its replacement, so one sighting is not final.
|
||||
failures = st.state === "failed" ? failures + 1 : 0;
|
||||
if (st.state === "stopped" || failures >= 5) {
|
||||
throw new Error(st.message || "the model could not be started");
|
||||
throw new Error(st.message || say.couldNotStart);
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 1500));
|
||||
const r = await fetch("/chat/model-status?model=" + encodeURIComponent(name) +
|
||||
@@ -314,11 +337,11 @@ access to it.</p>
|
||||
// What answered: a model with replicas on a card and on CPUs is served
|
||||
// by either, and the speed below means nothing without knowing which.
|
||||
if (hw) parts.push(hw === "cpu" ? "CPU" : "GPU " + hw);
|
||||
if (tokens) parts.push(tokens + " tokens");
|
||||
if (tokens && tFirst && tEnd > tFirst) parts.push((tokens / ((tEnd - tFirst) / 1000)).toFixed(1) + " tok/s");
|
||||
if (tFirst) parts.push("first token " + ((tFirst - t0) / 1000).toFixed(2) + " s");
|
||||
parts.push(((tEnd - t0) / 1000).toFixed(1) + " s");
|
||||
if (stopped) parts.push("stopped");
|
||||
if (tokens) parts.push(fill(say.tokens, { n: tokens }));
|
||||
if (tokens && tFirst && tEnd > tFirst) parts.push(fill(say.tokPerS, { n: fixed(tokens / ((tEnd - tFirst) / 1000), 1) }));
|
||||
if (tFirst) parts.push(fill(say.firstToken, { n: fixed((tFirst - t0) / 1000, 2) }));
|
||||
parts.push(fill(say.seconds, { n: fixed((tEnd - t0) / 1000, 1) }));
|
||||
if (stopped) parts.push(say.stopped);
|
||||
p.textContent = parts.join(" · ");
|
||||
out.after(p);
|
||||
}
|
||||
@@ -340,7 +363,7 @@ access to it.</p>
|
||||
let tokens = 0, pieces = 0, stopped = false;
|
||||
const opt = model.selectedOptions[0];
|
||||
busy = new AbortController();
|
||||
send.textContent = "Stop";
|
||||
send.textContent = say.stop;
|
||||
send.classList.add("stop");
|
||||
const t0 = performance.now();
|
||||
let tFirst = 0;
|
||||
@@ -377,7 +400,7 @@ access to it.</p>
|
||||
const e = JSON.parse(text).error;
|
||||
if (e && e.code === "content_policy_violation") {
|
||||
const policy = resp.headers.get("x-llmgw-guard-policy");
|
||||
shown = "Refused by the gateway's policy" + (policy ? " " + policy : "") + ": " + e.message;
|
||||
shown = fill(say.refused, { policy: policy ? " " + policy : "", message: e.message });
|
||||
} else if (e && e.code === "no_store") {
|
||||
shown = e.message;
|
||||
}
|
||||
@@ -437,14 +460,14 @@ access to it.</p>
|
||||
const dl = document.createElement("button");
|
||||
dl.type = "button";
|
||||
dl.className = "link download";
|
||||
dl.textContent = "Download as .zip";
|
||||
dl.textContent = say.downloadZip;
|
||||
dl.onclick = () => downloadCode(reply, dl);
|
||||
out.after(dl);
|
||||
}
|
||||
if (finish === "content_filter") {
|
||||
const note = document.createElement("p");
|
||||
note.className = "note truncated";
|
||||
note.textContent = "Stopped by the gateway's policy" + policySuffix(resp) + ".";
|
||||
note.textContent = fill(say.stoppedByPolicy, { policy: policySuffix(resp) });
|
||||
out.after(note);
|
||||
}
|
||||
if (finish === "length") {
|
||||
@@ -452,7 +475,7 @@ access to it.</p>
|
||||
// placed with textContent, and this is ours.
|
||||
const note = document.createElement("p");
|
||||
note.className = "note truncated";
|
||||
note.textContent = "Cut off at the length limit — ask it to continue.";
|
||||
note.textContent = say.cutOff;
|
||||
out.after(note);
|
||||
}
|
||||
stats(out, tokens || pieces, t0, tFirst, performance.now(), stopped, resp.headers.get("x-llmgw-hardware"));
|
||||
@@ -462,14 +485,14 @@ access to it.</p>
|
||||
renderMath(out);
|
||||
}
|
||||
else if (finish === "content_filter") {
|
||||
out.textContent = "(stopped by the gateway's policy" + policySuffix(resp) + " before anything was shown)";
|
||||
out.textContent = fill(say.stoppedByPolicyEmpty, { policy: policySuffix(resp) });
|
||||
out.classList.add("failed"); messages.pop();
|
||||
}
|
||||
else if (stopped) { out.textContent = "(stopped before anything came back)"; out.classList.add("failed"); messages.pop(); }
|
||||
else { out.textContent = "(no content came back)"; out.classList.add("failed"); }
|
||||
else if (stopped) { out.textContent = say.stoppedEmpty; out.classList.add("failed"); messages.pop(); }
|
||||
else { out.textContent = say.noContent; out.classList.add("failed"); }
|
||||
} catch (err) {
|
||||
if (err.name === "AbortError") {
|
||||
out.textContent = "(stopped before anything came back)";
|
||||
out.textContent = say.stoppedEmpty;
|
||||
messages.pop();
|
||||
} else {
|
||||
out.textContent = "(" + err + ")";
|
||||
@@ -477,7 +500,7 @@ access to it.</p>
|
||||
out.classList.add("failed");
|
||||
} finally {
|
||||
busy = null;
|
||||
send.textContent = "Send";
|
||||
send.textContent = say.send;
|
||||
send.classList.remove("stop");
|
||||
save();
|
||||
input.focus();
|
||||
@@ -490,7 +513,7 @@ access to it.</p>
|
||||
const kept = load_();
|
||||
if (!kept) return;
|
||||
if (kept.system) sys.value = kept.system;
|
||||
if (kept.temperature != null) { temp.value = kept.temperature; tempOut.textContent = (+temp.value).toFixed(1); }
|
||||
if (kept.temperature != null) { temp.value = kept.temperature; tempOut.textContent = fixed(+temp.value, 1); }
|
||||
// Open when there is a prompt in it, so it is not a hidden surprise.
|
||||
document.getElementById("settings").open = !!kept.system;
|
||||
if (kept.model && [...model.options].some((o) => o.value === kept.model)) { model.value = kept.model; showSimNote(); }
|
||||
|
||||
Reference in new issue
Block a user