feat(clients): meta: Meta Model API module, Muse Code protocol client, demo and tests
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Routes: GET /ai/meta, /ai/meta/status, /ai/meta/calls (no credential, no upstream)
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
Fixture f;
|
||||
auto page = f.client->get("/ai/meta");
|
||||
check(page.status == 200, "page 200");
|
||||
check(contains(page.headers.get("Content-Type"), "text/html"), "page is html");
|
||||
check(contains(page.body, "Meta Model API") && contains(page.body, "/embedded/ai_meta.js"),
|
||||
"page names the product and loads its script");
|
||||
|
||||
auto status = f.client->get("/ai/meta/status");
|
||||
check(status.status == 200, "status 200");
|
||||
check(contains(status.headers.get("Content-Type"), "application/json"), "status is json");
|
||||
check(contains(status.body, "https://api.meta.ai/v1"), "base url shown");
|
||||
check(contains(status.body, "muse-spark-1.3") && contains(status.body, "sam-3.1"), "models listed");
|
||||
check(contains(status.body, "\"hosted\":false"), "open-weight models flagged as self-hosted");
|
||||
check(!contains(status.body, "LLM_"), "no credential material shown");
|
||||
|
||||
auto calls = f.client->get("/ai/meta/calls");
|
||||
check(calls.status == 200 && contains(calls.body, "/responses/{response_id}/cancel") &&
|
||||
contains(calls.body, "/asr/realtime"),
|
||||
"call table listed");
|
||||
|
||||
check(f.client->post("/ai/meta").status == 405, "post to page is 405");
|
||||
check(f.client->post("/ai/meta/status").status == 405, "post to status is 405");
|
||||
check(f.client->get("/ai/meta/responses").status == 405, "get on a vendor route is 405");
|
||||
return finish("ai/meta/page");
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
// POST routes under /ai/meta: 422 on bad input, dry runs for paid/destructive
|
||||
// calls, 503 not_configured without a credential. No vendor reply is scripted.
|
||||
#include <cstdlib>
|
||||
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
unsetenv("META_API_KEY");
|
||||
unsetenv("MODEL_API_KEY");
|
||||
Fixture f;
|
||||
auto post = [&](const std::string& path, const std::string& body) { return f.client->post(path, body); };
|
||||
|
||||
// 422 before any credential check.
|
||||
check(post("/ai/meta/responses", "{}").status == 422, "responses: model required");
|
||||
check(post("/ai/meta/responses", "not json").status == 422, "responses: invalid JSON");
|
||||
check(post("/ai/meta/responses", R"({"model":"muse-spark-1.3","input":"x","max_output_tokens":15})").status == 422,
|
||||
"responses: max_output_tokens below 16");
|
||||
check(post("/ai/meta/responses", R"({"model":"muse-spark-1.3","input":"x","reasoning_effort":"none"})").status == 422,
|
||||
"responses: reasoning none rejected");
|
||||
check(post("/ai/meta/responses", R"({"model":"muse-spark-1.2","input":"x","reasoning_effort":"max"})").status == 422,
|
||||
"responses: max effort needs wonder or spark 1.3");
|
||||
check(post("/ai/meta/chat", R"({"model":"muse-spark-1.3"})").status == 422, "chat: message required");
|
||||
check(post("/ai/meta/messages", R"({"model":"muse-spark-1.3","message":"hi"})").status == 422, "messages: max_tokens required");
|
||||
check(post("/ai/meta/responses/get", R"({"id":"../x"})").status == 422, "id path guard");
|
||||
check(post("/ai/meta/files", R"({"action":"explode"})").status == 422, "files: unknown action");
|
||||
check(post("/ai/meta/files", R"({"action":"get"})").status == 422, "files: id required");
|
||||
check(post("/ai/meta/images", R"({"prompt":"x","n":11})").status == 422, "images: n above 10");
|
||||
check(post("/ai/meta/images", R"({"prompt":"x","size":"3200x100"})").status == 422, "images: aspect over 16:1");
|
||||
check(post("/ai/meta/segment", R"({"prompt":"bus, bicycle","image_url":"https://e.x/a.jpg"})").status == 422,
|
||||
"segment: one concept per request");
|
||||
check(post("/ai/meta/segment", R"({"prompt":"bus"})").status == 422, "segment: media required");
|
||||
check(post("/ai/meta/transcribe", R"({"audio_b64":"%%%"})").status == 422, "transcribe: bad base64");
|
||||
check(post("/ai/meta/transcribe", R"({"audio_b64":"AAAA"})").status == 422, "transcribe: not a WAV");
|
||||
check(post("/ai/meta/responses", std::string(9 * 1024 * 1024, 'x')).status == 413, "body cap");
|
||||
|
||||
// Dry runs need no credential.
|
||||
auto img = post("/ai/meta/images", R"({"prompt":"a red fox"})");
|
||||
check(img.status == 200 && contains(img.body, "\"dry_run\":true"), "images: dry run without confirm");
|
||||
auto del = post("/ai/meta/responses/delete", R"({"id":"resp_1"})");
|
||||
check(del.status == 200 && contains(del.body, "\"dry_run\":true"), "delete response: dry run");
|
||||
auto fdel = post("/ai/meta/files", R"({"action":"delete","id":"file-1"})");
|
||||
check(fdel.status == 200 && contains(fdel.body, "\"dry_run\":true"), "delete file: dry run");
|
||||
auto seg = post("/ai/meta/segment", R"({"prompt":"yellow school bus","image_url":"https://e.x/a.jpg"})");
|
||||
check(seg.status == 200 && contains(seg.body, "\"dry_run\":true"), "segment: dry run");
|
||||
auto code = post("/ai/meta/code", "{}");
|
||||
check(code.status == 200 && contains(code.body, "muse serve"), "muse code: dry run names the command");
|
||||
|
||||
// 503 without a credential.
|
||||
check(post("/ai/meta/responses", R"({"model":"muse-spark-1.3","input":"hi"})").status == 503, "responses: 503");
|
||||
check(contains(post("/ai/meta/responses", R"({"model":"muse-spark-1.3","input":"hi"})").body, "not_configured"),
|
||||
"responses: error code not_configured");
|
||||
check(post("/ai/meta/responses/count", R"({"model":"muse-spark-1.3","input":"hi"})").status == 503, "count: 503");
|
||||
check(post("/ai/meta/chat", R"({"model":"muse-spark-1.3","message":"hi"})").status == 503, "chat: 503");
|
||||
check(post("/ai/meta/messages", R"({"model":"muse-spark-1.3","message":"hi","max_tokens":64})").status == 503, "messages: 503");
|
||||
check(post("/ai/meta/models", "{}").status == 503, "models: 503");
|
||||
check(post("/ai/meta/files", R"({"action":"list"})").status == 503, "files list: 503");
|
||||
check(post("/ai/meta/responses/get", R"({"id":"resp_1"})").status == 503, "retrieve: 503");
|
||||
check(post("/ai/meta/images", R"({"prompt":"x","confirm":true})").status == 503, "images confirmed: 503");
|
||||
check(post("/ai/meta/files", R"({"action":"delete","id":"file-1","confirm":true})").status == 503, "file delete confirmed: 503");
|
||||
return finish("ai/meta/routes");
|
||||
}
|
||||
Reference in New Issue
Block a user