38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
// Models page: posts the chosen action to /agent/models/<action>.
|
|||
|
|
(function () {
|
||
|
|
"use strict";
|
||
|
|
var $ = function (id) { return document.getElementById(id); };
|
||
|
|
var routes = {
|
||
|
|
generate: "/agent/models/generate", count: "/agent/models/count",
|
||
|
|
embed: "/agent/models/embed", claude: "/agent/models/claude",
|
||
|
|
list: "/agent/models/list", image: "/agent/models/image",
|
||
|
|
music: "/agent/models/music", video: "/agent/models/video"
|
||
|
|
};
|
||
|
|
var MAX_OUT = 20000;
|
||
|
|
|
||
|
|
fetch("/agent/models/status").then(function (r) { return r.json(); }).then(function (s) {
|
||
|
|
$("m-config").textContent = s.configured
|
||
|
|
? "Credential found. Mode: " + s.mode + ". Default model: " + s.default_model + "."
|
||
|
|
: "No Google credential configured: calls answer 503 until GOOGLE_API_KEY is set.";
|
||
|
|
}).catch(function () { $("m-config").textContent = "Status unavailable."; });
|
||
|
|
|
||
|
|
$("m-run").addEventListener("click", function () {
|
||
|
|
var action = $("m-action").value;
|
||
|
|
var prompt = $("m-prompt").value;
|
||
|
|
var body = { prompt: prompt };
|
||
|
|
if (action === "embed") body = { text: prompt };
|
||
|
|
if ($("m-model").value) body.model = $("m-model").value;
|
||
|
|
$("m-error").textContent = "";
|
||
|
|
$("m-out").textContent = "...";
|
||
|
|
fetch(routes[action], {
|
||
|
|
method: "POST", headers: { "Content-Type": "application/json" },
|
||
|
|
body: JSON.stringify(body)
|
||
|
|
}).then(function (r) {
|
||
|
|
return r.text().then(function (t) { return { ok: r.ok, text: t }; });
|
||
|
|
}).then(function (res) {
|
||
|
|
if (!res.ok) { $("m-error").textContent = res.text.slice(0, 300); $("m-out").textContent = ""; return; }
|
||
|
|
$("m-out").textContent = res.text.slice(0, MAX_OUT);
|
||
|
|
}).catch(function (e) { $("m-error").textContent = String(e); });
|
||
|
|
});
|
||
|
|
})();
|