52 lines
2.6 KiB
JavaScript
52 lines
2.6 KiB
JavaScript
(function () {
|
|||
|
|
var $ = function (id) { return document.getElementById(id); };
|
||
|
|
var samples = {
|
||
|
|
"responses": '{"model":"muse-spark-1.3","input":"Say hi in five words.","reasoning_effort":"low"}',
|
||
|
|
"responses/count": '{"model":"muse-spark-1.3","input":"How many tokens?"}',
|
||
|
|
"responses/get": '{"id":"resp_..."}',
|
||
|
|
"responses/cancel": '{"id":"resp_..."}',
|
||
|
|
"responses/delete": '{"id":"resp_..."}',
|
||
|
|
"chat": '{"model":"muse-spark-1.3","message":"Hello"}',
|
||
|
|
"messages": '{"model":"muse-spark-1.3","message":"Hello","max_tokens":256}',
|
||
|
|
"models": '{}',
|
||
|
|
"files": '{"action":"list"}',
|
||
|
|
"images": '{"prompt":"a red fox in snow","n":1}',
|
||
|
|
"segment": '{"prompt":"yellow school bus","image_url":"https://example.com/bus.jpg"}',
|
||
|
|
"transcribe": '{"audio_b64":"","mode":"ENDPOINTING"}',
|
||
|
|
"platform": '{}',
|
||
|
|
"code": '{}'
|
||
|
|
};
|
||
|
|
function show(text, isError) {
|
||
|
|
$("meta-out").textContent = text;
|
||
|
|
$("meta-error").textContent = isError ? "Request failed" : "";
|
||
|
|
}
|
||
|
|
function send() {
|
||
|
|
var route = $("meta-route").value;
|
||
|
|
var body;
|
||
|
|
try { body = JSON.parse($("meta-body").value || "{}"); } catch (e) { show("Body is not valid JSON", true); return; }
|
||
|
|
if ($("meta-confirm").checked) body.confirm = true;
|
||
|
|
$("meta-send").disabled = true;
|
||
|
|
fetch("/ai/meta/" + route, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) })
|
||
|
|
.then(function (r) { return r.text().then(function (t) { return { ok: r.ok, t: t }; }); })
|
||
|
|
.then(function (r) {
|
||
|
|
var pretty = r.t;
|
||
|
|
try { pretty = JSON.stringify(JSON.parse(r.t), null, 2); } catch (e) { /* keep text */ }
|
||
|
|
show(pretty, !r.ok);
|
||
|
|
})
|
||
|
|
.catch(function () { show("Network error", true); })
|
||
|
|
.then(function () { $("meta-send").disabled = false; });
|
||
|
|
}
|
||
|
|
fetch("/ai/meta/status").then(function (r) { return r.json(); }).then(function (s) {
|
||
|
|
$("meta-config").textContent = s.configured ? "Credential found (" + s.key_env + ")." : "No credential: set " + s.key_env + ". Reads and dry runs still work.";
|
||
|
|
var box = $("meta-models");
|
||
|
|
box.textContent = "";
|
||
|
|
s.models.forEach(function (m) {
|
||
|
|
var p = document.createElement("div");
|
||
|
|
p.textContent = m.id + " - " + m.family + (m.hosted ? "" : " (self-hosted)") + ": " + m.note;
|
||
|
|
box.appendChild(p);
|
||
|
|
});
|
||
|
|
}).catch(function () { $("meta-config").textContent = "Status unavailable."; });
|
||
|
|
$("meta-route").addEventListener("change", function () { $("meta-body").value = samples[$("meta-route").value] || "{}"; });
|
||
|
|
$("meta-send").addEventListener("click", send);
|
||
|
|
})();
|