feat(clients): mistral: La Plateforme package, 347-op call table, typed services, ChatModel, demo
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
// Routes: GET /ai/mistral (page), /status, /calls (no credential needed)
|
||||
#include <cstdlib>
|
||||
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("MOLO_ENV_FILES", "off", 1);
|
||||
unsetenv("MISTRAL_API_KEY");
|
||||
Fixture f;
|
||||
auto page = f.client->get("/ai/mistral");
|
||||
check(page.status == 200, "page 200");
|
||||
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
|
||||
check(contains(page.body, "Mistral La Plateforme") && contains(page.body, "viewport"), "title and mobile viewport");
|
||||
check(contains(page.body, "/embedded/ai_mistral.js"), "script wired");
|
||||
check(f.client->post("/ai/mistral", "{}", "application/json").status == 405, "post page is 405");
|
||||
|
||||
auto st = f.client->get("/ai/mistral/status");
|
||||
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without a key");
|
||||
check(contains(st.body, "MISTRAL_API_KEY") && contains(st.body, "mistral-small-latest") &&
|
||||
contains(st.body, "codestral-latest") && contains(st.body, "mistral-embed"),
|
||||
"status names credential env and default models");
|
||||
check(contains(st.body, "\"calls\":347"), "status counts the call table");
|
||||
check(f.client->post("/ai/mistral/status", "{}", "application/json").status == 405, "post status is 405");
|
||||
|
||||
auto calls = f.client->get("/ai/mistral/calls");
|
||||
check(calls.status == 200 && contains(calls.body, "/v1/chat/completions") &&
|
||||
contains(calls.body, "/v1/fim/completions") && contains(calls.body, "/v1/ocr") &&
|
||||
contains(calls.body, "/v1/batch/jobs"),
|
||||
"call table listed");
|
||||
auto chat_only = f.client->get("/ai/mistral/calls?area=chat");
|
||||
check(chat_only.status == 200 && contains(chat_only.body, "/v1/chat/completions") &&
|
||||
!contains(chat_only.body, "/v1/ocr"),
|
||||
"call table filters by area");
|
||||
return finish("ai/mistral/page");
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// Routes: POST /ai/mistral/* (405, 422, dry runs, 503 without a credential)
|
||||
#include <cstdlib>
|
||||
|
||||
#include "support/Assert.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("MOLO_ENV_FILES", "off", 1);
|
||||
unsetenv("MISTRAL_API_KEY");
|
||||
Fixture f;
|
||||
auto post = [&](const std::string& route, const std::string& body) {
|
||||
return f.client->post("/ai/mistral/" + route, body, "application/json");
|
||||
};
|
||||
const char* all[] = {"chat", "stream", "agent", "fim", "embeddings", "moderation", "classify", "ocr",
|
||||
"transcribe", "models", "files", "batch", "finetune", "agents", "conversations",
|
||||
"libraries", "operation"};
|
||||
for (const char* r : all) {
|
||||
std::string route = std::string("/ai/mistral/") + r;
|
||||
check(f.client->get(route).status == 405, route + " get is 405");
|
||||
check(post(r, "not json").status == 422, route + " bad json is 422");
|
||||
check(post(r, "[1]").status == 422, route + " non-object is 422");
|
||||
}
|
||||
// 422: input rules run before anything else
|
||||
check(post("chat", "{}").status == 422, "chat needs prompt");
|
||||
check(post("chat", "{\"prompt\":\"hi\",\"temperature\":2}").status == 422, "temperature over 1.5");
|
||||
check(post("chat", "{\"prompt\":\"hi\",\"max_tokens\":-1}").status == 422, "negative max_tokens");
|
||||
check(post("chat", "{\"prompt\":\"hi\",\"effort\":\"loud\"}").status == 422, "bad effort");
|
||||
check(post("agent", "{\"prompt\":\"hi\"}").status == 422, "agent needs agent_id");
|
||||
check(post("agent", "{\"agent_id\":\"a/b\",\"prompt\":\"hi\"}").status == 422, "bad agent id");
|
||||
check(post("fim", "{}").status == 422, "fim needs prompt");
|
||||
check(post("embeddings", "{}").status == 422, "embeddings needs input");
|
||||
check(post("moderation", "{}").status == 422, "moderation needs input");
|
||||
check(post("classify", "{\"input\":\"x\"}").status == 422, "classify needs model");
|
||||
check(post("ocr", "{\"reference\":\"ftp://x\"}").status == 422, "ocr needs http(s)");
|
||||
check(post("ocr", "{\"kind\":\"video\",\"reference\":\"https://x.test/a\"}").status == 422, "bad ocr kind");
|
||||
check(post("transcribe", "{}").status == 422, "transcribe needs a source");
|
||||
check(post("transcribe", "{\"file_url\":\"https://x.test/a.mp3\",\"file_id\":\"f1\"}").status == 422, "one source only");
|
||||
check(post("files", "{\"action\":\"fly\"}").status == 422, "bad files action");
|
||||
check(post("files", "{\"action\":\"get\",\"id\":\"../x\"}").status == 422, "bad file id");
|
||||
check(post("files", "{\"action\":\"upload\",\"filename\":\"a.jsonl\",\"data_base64\":\"@@\"}").status == 422, "bad base64");
|
||||
check(post("files", "{\"action\":\"upload\",\"filename\":\"a/b\",\"data_base64\":\"aGVsbG8=\"}").status == 422, "bad filename");
|
||||
check(post("files", "{\"action\":\"list\",\"page_size\":101}").status == 422, "page_size over 100");
|
||||
check(post("batch", "{\"action\":\"create\",\"model\":\"m\"}").status == 422, "batch needs input files");
|
||||
check(post("batch", "{\"action\":\"get\"}").status == 422, "batch get needs id");
|
||||
check(post("finetune", "{\"action\":\"create\",\"model\":\"open-mistral-7b\"}").status == 422, "finetune needs files");
|
||||
check(post("agents", "{\"action\":\"create\",\"model\":\"m\"}").status == 422, "agent create needs name");
|
||||
check(post("conversations", "{\"action\":\"start\",\"prompt\":\"\"}").status == 422, "empty conversation prompt");
|
||||
check(post("libraries", "{\"action\":\"create\",\"name\":\"n\",\"chunk_size\":10}").status == 422, "chunk_size under 256");
|
||||
check(post("operation", "{}").status == 422, "operation needs op");
|
||||
check(post("operation", "{\"op\":\"nope\"}").status == 422, "unknown operation");
|
||||
check(post("operation", "{\"op\":\"files_api_routes_upload_file\"}").status == 422, "multipart operation refused");
|
||||
check(post("operation", "{\"op\":\"chat_completion_v1_chat_completions_post\",\"body\":{\"bogus\":1}}").status == 422,
|
||||
"unknown body field refused");
|
||||
|
||||
// dry runs: paid or resource-changing routes show the exact request
|
||||
auto dry = post("chat", "{\"prompt\":\"hi\"}");
|
||||
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true") && contains(dry.body, "\"model\":\"mistral-small-latest\"") &&
|
||||
contains(dry.body, "/v1/chat/completions"),
|
||||
"chat is a dry run without confirm");
|
||||
check(contains(post("stream", "{\"prompt\":\"hi\"}").body, "\"stream\":true"), "stream preview");
|
||||
check(contains(post("agent", "{\"agent_id\":\"ag_1\",\"prompt\":\"hi\"}").body, "/v1/agents/completions"), "agent preview");
|
||||
check(contains(post("fim", "{\"prompt\":\"def f():\"}").body, "/v1/fim/completions"), "fim preview");
|
||||
check(contains(post("embeddings", "{\"input\":\"x\"}").body, "\"model\":\"mistral-embed\""), "embeddings preview");
|
||||
check(contains(post("moderation", "{\"input\":\"x\"}").body, "\"dry_run\":true"), "moderation is a dry run");
|
||||
check(contains(post("ocr", "{\"reference\":\"https://x.test/a.pdf\"}").body, "mistral-ocr-latest"), "ocr preview");
|
||||
check(contains(post("transcribe", "{\"file_url\":\"https://x.test/a.mp3\"}").body, "voxtral-mini-latest"), "transcribe preview");
|
||||
check(contains(post("files", "{\"action\":\"delete\",\"id\":\"f1\"}").body, "\"dry_run\":true"), "file delete is a dry run");
|
||||
check(contains(post("files", "{\"action\":\"upload\",\"filename\":\"a.jsonl\",\"data_base64\":\"aGVsbG8=\"}").body, "\"bytes\":5"),
|
||||
"upload is a dry run");
|
||||
check(contains(post("batch", "{\"action\":\"create\",\"model\":\"m\",\"input_files\":[\"f1\"]}").body, "/v1/batch/jobs"), "batch create preview");
|
||||
check(contains(post("batch", "{\"action\":\"cancel\",\"id\":\"b1\"}").body, "\"dry_run\":true"), "batch cancel is a dry run");
|
||||
check(contains(post("finetune", "{\"action\":\"create\",\"model\":\"open-mistral-7b\",\"training_files\":[\"f1\"],\"hyperparameters\":{\"training_steps\":10}}").body,
|
||||
"\"dry_run\":true"),
|
||||
"finetune create is a dry run");
|
||||
check(contains(post("agents", "{\"action\":\"delete\",\"id\":\"ag_1\"}").body, "\"dry_run\":true"), "agent delete is a dry run");
|
||||
check(contains(post("conversations", "{\"action\":\"start\",\"prompt\":\"hi\"}").body, "\"dry_run\":true"), "conversation start is a dry run");
|
||||
check(contains(post("libraries", "{\"action\":\"delete\",\"id\":\"lib_1\"}").body, "\"dry_run\":true"), "library delete is a dry run");
|
||||
check(contains(post("operation", "{\"op\":\"files_api_routes_delete_file\",\"ids\":[\"f1\"]}").body, "\"dry_run\":true"),
|
||||
"destructive operation is a dry run");
|
||||
check(contains(post("operation", "{\"op\":\"files_api_routes_delete_file\",\"ids\":[\"f1\"]}").body, "/v1/files/f1"),
|
||||
"operation preview renders the path");
|
||||
|
||||
// 503: free calls and confirmed calls need the credential
|
||||
check(post("models", "{}").status == 503 && contains(post("models", "{}").body, "mistral_not_configured"), "models without key is 503");
|
||||
check(post("files", "{\"action\":\"list\"}").status == 503, "files list without key is 503");
|
||||
check(post("files", "{\"action\":\"get\",\"id\":\"f1\"}").status == 503, "files get without key is 503");
|
||||
check(post("batch", "{\"action\":\"list\"}").status == 503, "batch list without key is 503");
|
||||
check(post("finetune", "{\"action\":\"list\"}").status == 503, "finetune list without key is 503");
|
||||
check(post("agents", "{\"action\":\"list\"}").status == 503, "agents list without key is 503");
|
||||
check(post("conversations", "{\"action\":\"list\"}").status == 503, "conversations list without key is 503");
|
||||
check(post("libraries", "{\"action\":\"list\"}").status == 503, "libraries list without key is 503");
|
||||
check(post("operation", "{\"op\":\"list_models_v1_models_get\"}").status == 503, "read operation without key is 503");
|
||||
check(post("chat", "{\"prompt\":\"hi\",\"confirm\":true}").status == 503, "confirmed chat without key is 503");
|
||||
check(post("stream", "{\"prompt\":\"hi\",\"confirm\":true}").status == 503, "confirmed stream without key is 503");
|
||||
check(post("embeddings", "{\"input\":\"x\",\"confirm\":true}").status == 503, "confirmed embeddings without key is 503");
|
||||
check(post("ocr", "{\"reference\":\"https://x.test/a.pdf\",\"confirm\":true}").status == 503, "confirmed ocr without key is 503");
|
||||
check(post("files", "{\"action\":\"delete\",\"id\":\"f1\",\"confirm\":true}").status == 503, "confirmed delete without key is 503");
|
||||
return finish("ai/mistral/routes");
|
||||
}
|
||||
Reference in New Issue
Block a user