34 lines
1.6 KiB
C++
34 lines
1.6 KiB
C++
// Routes: GET /ai/cohere (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("COHERE_API_KEY");
|
||
|
|
unsetenv("CO_API_KEY");
|
||
|
|
Fixture f;
|
||
|
|
auto page = f.client->get("/ai/cohere");
|
||
|
|
check(page.status == 200, "page 200");
|
||
|
|
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
|
||
|
|
check(contains(page.body, "Cohere API") && contains(page.body, "viewport"), "title and mobile viewport");
|
||
|
|
check(contains(page.body, "/embedded/ai_cohere.js"), "script wired");
|
||
|
|
check(f.client->post("/ai/cohere", "{}", "application/json").status == 405, "post page is 405");
|
||
|
|
|
||
|
|
auto st = f.client->get("/ai/cohere/status");
|
||
|
|
check(st.status == 200 && contains(st.body, "\"configured\":false"), "status without a key");
|
||
|
|
check(contains(st.body, "COHERE_API_KEY") && contains(st.body, "command-a-03-2025") &&
|
||
|
|
contains(st.body, "embed-v4.0") && contains(st.body, "rerank-v3.5"),
|
||
|
|
"status names credential env and models");
|
||
|
|
check(f.client->post("/ai/cohere/status", "{}", "application/json").status == 405, "post status is 405");
|
||
|
|
|
||
|
|
auto calls = f.client->get("/ai/cohere/calls");
|
||
|
|
check(calls.status == 200 && contains(calls.body, "/v2/chat") && contains(calls.body, "/v2/embed") &&
|
||
|
|
contains(calls.body, "/v1/check-api-key") && contains(calls.body, "/v2/batches/{id}:cancel"),
|
||
|
|
"call table listed");
|
||
|
|
check(f.client->post("/ai/cohere/calls", "{}", "application/json").status == 405, "post calls is 405");
|
||
|
|
return finish("ai/cohere/page");
|
||
|
|
}
|