Files

40 lines
2.2 KiB
C++

// Routes: GET /ai/azure (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);
for (const char* v : {"AZURE_OPENAI_ENDPOINT", "AZURE_OPENAI_API_KEY", "AZURE_OPENAI_API_VERSION", "AZURE_TENANT_ID",
"AZURE_CLIENT_ID", "AZURE_CLIENT_SECRET", "AZURE_AI_ENDPOINT", "AZURE_CONTENT_SAFETY_ENDPOINT",
"AZURE_CONTENT_SAFETY_KEY"})
unsetenv(v);
Fixture f;
auto page = f.client->get("/ai/azure");
check(page.status == 200, "page 200");
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
check(contains(page.body, "Azure OpenAI and AI Foundry") && contains(page.body, "viewport"), "title and mobile viewport");
check(contains(page.body, "/embedded/ai_azure.js"), "script wired");
check(f.client->post("/ai/azure", "{}", "application/json").status == 405, "post page is 405");
auto st = f.client->get("/ai/azure/status");
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without a key");
check(contains(st.body, "\"auth\":\"none\"") && contains(st.body, "\"api_version\":\"v1\""), "auth none, version v1");
check(contains(st.body, "AZURE_OPENAI_ENDPOINT") && contains(st.body, "AZURE_OPENAI_API_KEY") &&
contains(st.body, "AZURE_TENANT_ID") && contains(st.body, "AZURE_CLIENT_SECRET"),
"status names the credential variables");
check(contains(st.body, "\"calls\":147"), "status counts the call table");
check(f.client->post("/ai/azure/status", "{}", "application/json").status == 405, "post status is 405");
auto calls = f.client->get("/ai/azure/calls");
check(calls.status == 200 && contains(calls.body, "CreateChatCompletion") &&
contains(calls.body, "/deployments/{deployment-id}/chat/completions") &&
contains(calls.body, "\"v1_path\":\"/chat/completions\"") &&
contains(calls.body, "SafetyTextOperationsAnalyzeText"),
"call table listed with both api paths");
check(f.client->post("/ai/azure/calls", "{}", "application/json").status == 405, "post calls is 405");
return finish("ai/azure/page");
}