Files
retoorandClaude Sonnet 5.5 3404392887 feat(clients): perplexity: Sonar, Search, Agent, embeddings, decisions, batches, skills, orchestrator
Package molo::perplexity covering all 39 operations of the five published
OpenAPI documents, PerplexityChatModel, demo routes under /ai/perplexity,
check_spec.py, SPEC.md, 46 unit cases and 111 route checks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 15:01:55 +01:00

59 lines
2.9 KiB
JavaScript

// Perplexity page: thin client over /ai/perplexity/* (all limits server side).
(function () {
"use strict";
var $ = function (id) { return document.getElementById(id); };
var out = $("pp-out"), err = $("pp-error");
var templates = {
"sonar": { prompt: "What changed in the latest Mars rover mission?", model: "sonar", search_recency_filter: "month", return_related_questions: true, max_tokens: 256 },
"stream": { prompt: "Explain quantum computing in two sentences.", model: "sonar", max_tokens: 128 },
"async": { action: "create", prompt: "Compare solid-state battery makers.", model: "sonar-deep-research" },
"search": { query: "Perplexity Search API", max_results: 5, max_tokens_per_page: 512 },
"embeddings": { input: ["first text", "second text"], model: "pplx-embed-v1-0.6b", dimensions: 256 },
"agent": { input: "Summarize today's top AI news.", effort: "fast", tools: ["web_search"], max_steps: 5 },
"orchestrator": { api: "chat", model: "perplexity/kimi-k3", prompt: "Say hello." },
"decisions": { state: "The battery stopped charging.", questions: { defect: { type: "noul", instructions: "Does this report a defect?" } } },
"models": { kind: "agent" },
"usage": { dataset: "credit_usage", start_time: 1746057600, limit: 7 },
"batches": { action: "list", limit: 20 },
"skills": { action: "list", limit: 20 }
};
var sel = $("pp-route");
Object.keys(templates).forEach(function (k) {
var o = document.createElement("option");
o.value = k; o.textContent = k;
sel.appendChild(o);
});
function fill() { $("pp-body").value = JSON.stringify(templates[sel.value], null, 1); }
sel.onchange = fill;
fill();
function send(confirm) {
var body;
try { body = JSON.parse($("pp-body").value || "{}"); }
catch (e) { err.textContent = "Body is not valid JSON"; return; }
if (confirm) body.confirm = true;
err.textContent = "";
out.textContent = "...";
fetch("/ai/perplexity/" + 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 = ""; });
}
$("pp-send").onclick = function () { send(false); };
$("pp-confirm").onclick = function () { send(true); };
fetch("/ai/perplexity/status").then(function (r) { return r.json(); }).then(function (s) {
$("pp-config").textContent = s.configured
? "PERPLEXITY_API_KEY found. Calls are real; paid ones need confirm."
: "No PERPLEXITY_API_KEY (create one at " + s.key_page + "): calls answer 503 until one is configured; dry runs still work.";
});
})();