60 lines
2.7 KiB
JavaScript
60 lines
2.7 KiB
JavaScript
// Hugging Face page: thin client over /ai/huggingface/* (all limits server side).
|
|
(function () {
|
|
"use strict";
|
|
var $ = function (id) { return document.getElementById(id); };
|
|
var out = $("hf-out"), err = $("hf-error");
|
|
var templates = {
|
|
"hub/list": { kind: "models", search: "bert", sort: "downloads", limit: 10 },
|
|
"hub/repo": { action: "info", kind: "models", id: "openai-community/gpt2" },
|
|
"hub/search": { action: "quicksearch", q: "llama", limit: 5 },
|
|
"hub/whoami": {},
|
|
"hub/discussions": { action: "list", kind: "models", id: "openai-community/gpt2" },
|
|
"hub/collections": { action: "list", owner: "nvidia", limit: 5 },
|
|
"hub/webhooks": { action: "list" },
|
|
"chat": { model: "openai/gpt-oss-20b:fastest", prompt: "Hello!", max_tokens: 64 },
|
|
"chat/stream": { model: "openai/gpt-oss-20b:fastest", prompt: "Count to five.", max_tokens: 64 },
|
|
"task": { task: "text-classification", model: "distilbert/distilbert-base-uncased-finetuned-sst-2-english", inputs: "I like you" },
|
|
"endpoints": { action: "vendors" },
|
|
"tgi": { url: "http://127.0.0.1:8080", action: "health" },
|
|
"tei": { url: "http://127.0.0.1:8081", action: "health" }
|
|
};
|
|
var sel = $("hf-route");
|
|
Object.keys(templates).forEach(function (k) {
|
|
var o = document.createElement("option");
|
|
o.value = k; o.textContent = k;
|
|
sel.appendChild(o);
|
|
});
|
|
function fill() { $("hf-body").value = JSON.stringify(templates[sel.value], null, 1); }
|
|
sel.onchange = fill;
|
|
fill();
|
|
|
|
function send(confirm) {
|
|
var body;
|
|
try { body = JSON.parse($("hf-body").value || "{}"); }
|
|
catch (e) { err.textContent = "Body is not valid JSON"; return; }
|
|
if (confirm) body.confirm = true;
|
|
err.textContent = "";
|
|
out.textContent = "...";
|
|
fetch("/ai/huggingface/" + sel.value, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body)
|
|
}).then(function (res) {
|
|
return res.text().then(function (t) {
|
|
var j;
|
|
try { j = JSON.parse(t); } catch (e) { j = { message: t }; }
|
|
if (!res.ok) { err.textContent = j.message || ("HTTP " + res.status); out.textContent = ""; }
|
|
else { out.textContent = JSON.stringify(j, null, 2); }
|
|
});
|
|
}).catch(function (e) { err.textContent = String(e); out.textContent = ""; });
|
|
}
|
|
$("hf-send").onclick = function () { send(false); };
|
|
$("hf-confirm").onclick = function () { send(true); };
|
|
|
|
fetch("/ai/huggingface/status").then(function (r) { return r.json(); }).then(function (s) {
|
|
$("hf-config").textContent = s.configured
|
|
? "HF_TOKEN found. Calls are real; paid and changing ones need confirm."
|
|
: "No HF_TOKEN: calls answer 503 until one is configured; dry runs still work.";
|
|
});
|
|
})();
|