64 lines
2.7 KiB
JavaScript
64 lines
2.7 KiB
JavaScript
// Mistral page: thin client over /ai/mistral/* (all limits server side).
|
|||
|
|
(function () {
|
||
|
|
"use strict";
|
||
|
|
var $ = function (id) { return document.getElementById(id); };
|
||
|
|
var out = $("mi-out"), err = $("mi-error");
|
||
|
|
var templates = {
|
||
|
|
"chat": { prompt: "Hello!", max_tokens: 256 },
|
||
|
|
"stream": { prompt: "Count to five.", max_tokens: 128 },
|
||
|
|
"agent": { agent_id: "ag_...", prompt: "Hello!" },
|
||
|
|
"fim": { prompt: "def fib(n):", suffix: " return fib(n-1) + fib(n-2)", max_tokens: 128 },
|
||
|
|
"embeddings": { inputs: ["Embed this sentence.", "As well as this one."] },
|
||
|
|
"moderation": { input: "I love sunny days." },
|
||
|
|
"classify": { model: "ft:classifier:...", input: "Great product" },
|
||
|
|
"ocr": { kind: "document_url", reference: "https://arxiv.org/pdf/2201.04234", pages: [0] },
|
||
|
|
"transcribe": { file_url: "https://example.com/audio.mp3", language: "en" },
|
||
|
|
"models": { action: "list" },
|
||
|
|
"files": { action: "list", page_size: 20 },
|
||
|
|
"batch": { action: "list" },
|
||
|
|
"finetune": { action: "list" },
|
||
|
|
"agents": { action: "list" },
|
||
|
|
"conversations": { action: "start", prompt: "Hello!" },
|
||
|
|
"libraries": { action: "list" },
|
||
|
|
"operation": { op: "list_models_v1_models_get", ids: [], query: {} }
|
||
|
|
};
|
||
|
|
var sel = $("mi-route");
|
||
|
|
Object.keys(templates).forEach(function (k) {
|
||
|
|
var o = document.createElement("option");
|
||
|
|
o.value = k; o.textContent = k;
|
||
|
|
sel.appendChild(o);
|
||
|
|
});
|
||
|
|
function fill() { $("mi-body").value = JSON.stringify(templates[sel.value], null, 1); }
|
||
|
|
sel.onchange = fill;
|
||
|
|
fill();
|
||
|
|
|
||
|
|
function send(confirm) {
|
||
|
|
var body;
|
||
|
|
try { body = JSON.parse($("mi-body").value || "{}"); }
|
||
|
|
catch (e) { err.textContent = "Body is not valid JSON"; return; }
|
||
|
|
if (confirm) body.confirm = true;
|
||
|
|
err.textContent = "";
|
||
|
|
out.textContent = "...";
|
||
|
|
fetch("/ai/mistral/" + 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 = ""; });
|
||
|
|
}
|
||
|
|
$("mi-send").onclick = function () { send(false); };
|
||
|
|
$("mi-confirm").onclick = function () { send(true); };
|
||
|
|
|
||
|
|
fetch("/ai/mistral/status").then(function (r) { return r.json(); }).then(function (s) {
|
||
|
|
$("mi-config").textContent = s.configured
|
||
|
|
? "MISTRAL_API_KEY found. Calls are real; paid ones need confirm."
|
||
|
|
: "No MISTRAL_API_KEY: calls answer 503 until one is configured; dry runs still work.";
|
||
|
|
});
|
||
|
|
})();
|