feat(clients): bedrock: SigV4 signer, Converse, event streams, guardrails, agents, KB, batch
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// Bedrock page: thin client over /ai/bedrock/* (all limits server side).
|
||||
(function () {
|
||||
"use strict";
|
||||
var $ = function (id) { return document.getElementById(id); };
|
||||
var out = $("bk-out"), err = $("bk-error");
|
||||
var templates = {
|
||||
"converse": { prompt: "Hello!", system: "Be brief.", max_tokens: 256, temperature: 0.5 },
|
||||
"converse-stream": { prompt: "Count to five.", max_tokens: 128 },
|
||||
"invoke": { model: "amazon.titan-embed-text-v2:0", body: { inputText: "hello" } },
|
||||
"invoke-stream": { model: "anthropic.claude-3-haiku-20240307-v1:0", body: { anthropic_version: "bedrock-2023-05-31", max_tokens: 64, messages: [{ role: "user", content: "Hi" }] } },
|
||||
"count-tokens": { prompt: "How many tokens is this?" },
|
||||
"guardrail": { guardrail_id: "", version: "DRAFT", source: "INPUT", text: "my card number is 4111 1111 1111 1111" },
|
||||
"agent": { agent_id: "", alias_id: "", session_id: "demo-session-1", prompt: "Hello" },
|
||||
"retrieve": { knowledge_base_id: "", query: "What is AWS?", number_of_results: 5 },
|
||||
"models": { action: "list", provider: "Anthropic", output_modality: "TEXT" },
|
||||
"profiles": { action: "list", type: "SYSTEM_DEFINED" },
|
||||
"guardrails": { action: "list" },
|
||||
"batch": { action: "list" },
|
||||
"sign": { method: "POST", path: "/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse", body: "{}", host: "bedrock-runtime.us-east-1.amazonaws.com" }
|
||||
};
|
||||
var sel = $("bk-route");
|
||||
Object.keys(templates).forEach(function (k) {
|
||||
var o = document.createElement("option");
|
||||
o.value = k; o.textContent = k;
|
||||
sel.appendChild(o);
|
||||
});
|
||||
function fill() { $("bk-body").value = JSON.stringify(templates[sel.value], null, 1); }
|
||||
sel.onchange = fill;
|
||||
fill();
|
||||
|
||||
function send(confirm) {
|
||||
var body;
|
||||
try { body = JSON.parse($("bk-body").value || "{}"); }
|
||||
catch (e) { err.textContent = "Body is not valid JSON"; return; }
|
||||
if (confirm) body.confirm = true;
|
||||
err.textContent = "";
|
||||
out.textContent = "...";
|
||||
fetch("/ai/bedrock/" + 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 = ""; });
|
||||
}
|
||||
$("bk-send").onclick = function () { send(false); };
|
||||
$("bk-confirm").onclick = function () { send(true); };
|
||||
|
||||
fetch("/ai/bedrock/status").then(function (r) { return r.json(); }).then(function (s) {
|
||||
$("bk-config").textContent = s.configured
|
||||
? "Credential found (" + s.auth_mode + ", " + s.region + "). Calls are real; paid ones need confirm."
|
||||
: "No AWS_BEARER_TOKEN_BEDROCK or AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY: calls answer 503 until one is set; dry runs and /sign still work.";
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user