feat(clients): openai platform: 188-call table, 217 events, WebSocket sessions, checker, demo
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Routes: POST /ai/openai/platform/realtime/{event,parse,catalog,socket}, /batch/file, /uploads/plan
|
||||
#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 b = "/ai/openai/platform";
|
||||
auto ev = f.client->post(b + "/realtime/event", "{\"type\":\"session.update\",\"fields\":{\"session\":{\"type\":\"realtime\"}}}", kJson);
|
||||
check(ev.status == 200 && contains(ev.body, "\"type\":\"session.update\""), "event builds without a key");
|
||||
check(f.client->post(b + "/realtime/event", "{\"type\":\"session.update\"}", kJson).status == 422, "missing required field is 422");
|
||||
check(f.client->post(b + "/realtime/event", "{\"type\":\"nope\"}", kJson).status == 422, "unknown event is 422");
|
||||
check(f.client->post(b + "/realtime/event", "{\"profile\":\"x\",\"type\":\"a\"}", kJson).status == 422, "unknown profile is 422");
|
||||
auto parse = f.client->post(b + "/realtime/parse", "{\"text\":\"{\\\"type\\\":\\\"error\\\",\\\"error\\\":{\\\"message\\\":\\\"boom\\\"}}\"}", kJson);
|
||||
check(parse.status == 200 && contains(parse.body, "\"is_error\":true") && contains(parse.body, "boom"), "error event parses");
|
||||
check(f.client->post(b + "/realtime/parse", "{\"text\":\"nope\"}", kJson).status == 422, "bad event text is 422");
|
||||
auto cat = f.client->post(b + "/realtime/catalog", "{\"profile\":\"live\",\"direction\":\"client\"}", kJson);
|
||||
check(cat.status == 200 && contains(cat.body, "session.start"), "catalog lists live client events");
|
||||
check(f.client->post(b + "/realtime/catalog", "{\"direction\":\"x\"}", kJson).status == 422, "bad direction is 422");
|
||||
auto batch = f.client->post(b + "/batch/file", "{\"endpoint\":\"/v1/embeddings\",\"requests\":[{\"custom_id\":\"a\",\"body\":{\"model\":\"m\",\"input\":\"x\"}}]}", kJson);
|
||||
check(batch.status == 200 && contains(batch.body, "\"requests\":1"), "batch file builds");
|
||||
check(f.client->post(b + "/batch/file", "{\"endpoint\":\"/v1/embeddings\",\"requests\":[{\"custom_id\":\"a\",\"body\":{}},{\"custom_id\":\"a\",\"body\":{}}]}", kJson).status == 422, "duplicate custom_id is 422");
|
||||
check(f.client->post(b + "/batch/file", "{\"endpoint\":\"/v1/nope\",\"requests\":[{\"custom_id\":\"a\"}]}", kJson).status == 422, "bad endpoint is 422");
|
||||
auto plan = f.client->post(b + "/uploads/plan", "{\"bytes\":100,\"part_bytes\":30}", kJson);
|
||||
check(plan.status == 200 && contains(plan.body, "\"parts\":4"), "upload plan");
|
||||
check(f.client->post(b + "/uploads/plan", "{\"bytes\":0}", kJson).status == 422, "empty upload is 422");
|
||||
check(f.client->post(b + "/uploads/plan", "{\"bytes\":100,\"part_bytes\":999999999999}", kJson).status == 422, "part over 64 MiB is 422");
|
||||
auto dry = f.client->post(b + "/realtime/socket", "{\"kind\":\"realtime\",\"model\":\"gpt-realtime\"}", kJson);
|
||||
check(dry.status == 200 && contains(dry.body, "wss://api.openai.com/v1/realtime?model=gpt-realtime"), "socket dry run");
|
||||
check(f.client->post(b + "/realtime/socket", "{\"kind\":\"realtime\",\"model\":\"gpt-realtime\",\"confirm\":true}", kJson).status == 503, "confirmed socket without key is 503");
|
||||
check(f.client->post(b + "/realtime/socket", "{\"kind\":\"realtime\"}", kJson).status == 422, "model required is 422");
|
||||
check(f.client->post(b + "/realtime/socket", "{\"kind\":\"x\"}", kJson).status == 422, "bad kind is 422");
|
||||
check(f.client->post(b + "/realtime/socket", "{\"kind\":\"live\",\"seconds\":999}", kJson).status == 422, "seconds over cap is 422");
|
||||
check(f.client->get(b + "/realtime/socket").status == 405, "get socket is 405");
|
||||
return finish("ai/openai/platform/helpers");
|
||||
}
|
||||
Reference in New Issue
Block a user