Files

36 lines
2.6 KiB
C++
Raw Permalink Normal View History

// Route: POST /ai/openai/platform/call (table driven)
#include "support/Assert.hpp"
using namespace molo::example::test;
static const char* kJson = "application/json";
int main() {
setenv("MOLO_ENV_FILES", "off", 1);
unsetenv("OPENAI_API_KEY");
Fixture f;
const std::string url = "/ai/openai/platform/call";
auto list = f.client->post(url, "{\"operation\":\"listFiles\",\"query\":{\"limit\":1}}", kJson);
check(list.status == 503 && contains(list.body, "not_configured"), "read-only call without key is 503");
check(f.client->post(url, "{}", kJson).status == 422, "operation required is 422");
check(f.client->post(url, "{\"operation\":\"nope\"}", kJson).status == 422, "unknown operation is 422");
check(f.client->post(url, "{\"operation\":\"retrieveFile\"}", kJson).status == 422, "missing id is 422");
check(f.client->post(url, "{\"operation\":\"retrieveFile\",\"ids\":{\"file_id\":\"a/b\"}}", kJson).status == 422, "bad id is 422");
check(f.client->post(url, "{\"operation\":\"listFiles\",\"query\":{\"bogus\":1}}", kJson).status == 422, "unknown query is 422");
check(f.client->post(url, "{\"operation\":\"createAssistant\",\"body\":{}}", kJson).status == 422, "missing required field is 422");
check(f.client->post(url, "{\"operation\":\"createFile\"}", kJson).status == 422, "multipart-only call is 422");
check(f.client->post(url, "{\"operation\":\"downloadFile\",\"ids\":{\"file_id\":\"f\"}}", kJson).status == 422, "binary call is 422");
check(f.client->post(url, "not json", kJson).status == 422, "bad json is 422");
check(f.client->post(url, "[1]", kJson).status == 422, "non-object is 422");
auto paid = f.client->post(url, "{\"operation\":\"createBatch\",\"body\":{\"input_file_id\":\"file-1\",\"endpoint\":\"/v1/embeddings\",\"completion_window\":\"24h\"}}", kJson);
check(paid.status == 200 && contains(paid.body, "\"dry_run\":true") && contains(paid.body, "POST /batches"), "paid call is a dry run");
auto del = f.client->post(url, "{\"operation\":\"deleteFile\",\"ids\":{\"file_id\":\"file-1\"}}", kJson);
check(del.status == 200 && contains(del.body, "\"dry_run\":true") && contains(del.body, "destructive"), "delete is a dry run");
auto beta = f.client->post(url, "{\"operation\":\"deleteThread\",\"ids\":{\"thread_id\":\"t\"}}", kJson);
check(contains(beta.body, "assistants=v2"), "dry run shows the beta header");
auto run = f.client->post(url, "{\"operation\":\"deleteFile\",\"ids\":{\"file_id\":\"file-1\"},\"confirm\":true}", kJson);
check(run.status == 503, "confirmed call without key is 503");
check(f.client->get(url).status == 405, "get is 405");
return finish("ai/openai/platform/call");
}