// Cohere page: thin client over /ai/cohere/* (all limits server side). (function () { "use strict"; var $ = function (id) { return document.getElementById(id); }; var out = $("co-out"), err = $("co-error"); var templates = { "chat": { prompt: "Tell me about LLMs", max_tokens: 256, thinking: "disabled" }, "stream": { prompt: "Count to five.", max_tokens: 128 }, "tools": { prompt: "Weather in Paris?", tool_choice: "REQUIRED" }, "embed": { texts: ["hello world"], input_type: "search_document", embedding_types: ["float"] }, "rerank": { query: "capital of the United States", documents: ["Carson City is the capital of Nevada.", "Washington, D.C. is the capital of the United States."], top_n: 2 }, "classify": { inputs: ["win a free prize now"], examples: [ { text: "free money", label: "spam" }, { text: "claim your prize", label: "spam" }, { text: "meeting at noon", label: "ok" }, { text: "see attached notes", label: "ok" }] }, "tokenize": { text: "tokenize me! :D" }, "detokenize": { tokens: [10002, 2261, 2012, 8, 2792, 43] }, "parse": { model: "MODEL", image_url: "https://example.com/page.png", output_format: "markdown" }, "models": { action: "list", endpoint: "chat" }, "key": {}, "datasets": { action: "list" }, "batches": { action: "list" }, "embedjobs": { action: "list" }, "connectors": { action: "list" }, "finetune": { action: "list" }, "legacy": { action: "summarize", body: { text: "Paste at least a few sentences of text here to summarize." } } }; var sel = $("co-route"); Object.keys(templates).forEach(function (k) { var o = document.createElement("option"); o.value = k; o.textContent = k; sel.appendChild(o); }); function fill() { $("co-body").value = JSON.stringify(templates[sel.value], null, 1); } sel.onchange = fill; fill(); function send(confirm) { var body; try { body = JSON.parse($("co-body").value || "{}"); } catch (e) { err.textContent = "Body is not valid JSON"; return; } if (confirm) body.confirm = true; err.textContent = ""; out.textContent = "..."; fetch("/ai/cohere/" + 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 = ""; }); } $("co-send").onclick = function () { send(false); }; $("co-confirm").onclick = function () { send(true); }; fetch("/ai/cohere/status").then(function (r) { return r.json(); }).then(function (s) { $("co-config").textContent = s.configured ? "COHERE_API_KEY found. Calls are real; paid ones need confirm." : "No COHERE_API_KEY: calls answer 503 until one is configured; dry runs still work."; }); })();