feat(clients): cloudai: Translation, Vision, Language, Video, Document AI, Speech v2, long audio TTS
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
// Routes: POST /google/cloudai/{video/annotate,documentai/*,speech/*,tts/*,operation,call}
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
const char* j = "application/json";
|
||||
// video
|
||||
std::string v = "{\"inputUri\":\"gs://b/v.mp4\",\"features\":[\"LABEL_DETECTION\"]";
|
||||
check(f.client->post("/google/cloudai/video/annotate", v + "}", j).status == 200, "video dry run");
|
||||
check(f.client->post("/google/cloudai/video/annotate", v + ",\"confirm\":true}", j).status == 503, "video confirmed is 503");
|
||||
check(f.client->post("/google/cloudai/video/annotate", "{\"inputUri\":\"gs://b/v\",\"features\":[\"X\"]}", j).status == 422, "bad feature");
|
||||
check(f.client->post("/google/cloudai/video/annotate", "{}", j).status == 422, "features required");
|
||||
// document ai
|
||||
std::string d = "{\"processorId\":\"abc\",\"gcsUri\":\"gs://b/d.pdf\",\"mimeType\":\"application/pdf\"";
|
||||
auto dd = f.client->post("/google/cloudai/documentai/process", d + "}", j);
|
||||
check(dd.status == 200 && contains(dd.body, "gcsDocument"), "process dry run");
|
||||
check(f.client->post("/google/cloudai/documentai/process", d + ",\"confirm\":true}", j).status == 503, "process confirmed is 503");
|
||||
auto inline_doc = f.client->post("/google/cloudai/documentai/process",
|
||||
"{\"processorId\":\"abc\",\"content\":\"" + std::string(1000, 'A') + "\",\"mimeType\":\"application/pdf\"}", j);
|
||||
check(inline_doc.status == 200 && contains(inline_doc.body, "1000 characters") && !contains(inline_doc.body, "AAAAAAAAAA"), "long content is not echoed");
|
||||
check(f.client->post("/google/cloudai/documentai/process", "{\"processorId\":\"a/b\",\"gcsUri\":\"gs://b/d\",\"mimeType\":\"application/pdf\"}", j).status == 422, "bad processor id");
|
||||
check(f.client->post("/google/cloudai/documentai/process", "{\"processorId\":\"a\",\"gcsUri\":\"gs://b/d\",\"mimeType\":\"x/y\"}", j).status == 422, "bad mime");
|
||||
check(f.client->post("/google/cloudai/documentai/list", "{\"what\":\"processors\",\"location\":\"eu\"}", j).status == 503, "list is 503");
|
||||
check(f.client->post("/google/cloudai/documentai/list", "{\"what\":\"versions\"}", j).status == 422, "versions need processorId");
|
||||
// speech
|
||||
std::string s = "{\"languages\":[\"nl-NL\"],\"uri\":\"gs://b/a.wav\"";
|
||||
check(f.client->post("/google/cloudai/speech/recognize", s + "}", j).status == 200, "recognize dry run");
|
||||
check(f.client->post("/google/cloudai/speech/recognize", s + ",\"confirm\":true}", j).status == 503, "recognize confirmed is 503");
|
||||
check(f.client->post("/google/cloudai/speech/recognize", "{\"uri\":\"gs://b/a\"}", j).status == 422, "languages required");
|
||||
check(f.client->post("/google/cloudai/speech/recognize", "{\"languages\":[\"nl\"],\"uri\":\"gs://b/a\",\"model\":\"Bad Model\"}", j).status == 422, "bad model");
|
||||
check(f.client->post("/google/cloudai/speech/list", "{\"what\":\"recognizers\"}", j).status == 503, "speech list is 503");
|
||||
// long audio
|
||||
std::string t = "{\"text\":\"Hello\",\"language\":\"en-US\",\"outputUri\":\"gs://b/o.wav\"";
|
||||
auto td = f.client->post("/google/cloudai/tts/long", t + "}", j);
|
||||
check(td.status == 200 && contains(td.body, "synthesizeLongAudio"), "long audio dry run");
|
||||
check(f.client->post("/google/cloudai/tts/long", t + ",\"confirm\":true}", j).status == 503, "long audio confirmed is 503");
|
||||
check(f.client->post("/google/cloudai/tts/long", "{\"text\":\"x\",\"language\":\"en-US\",\"outputUri\":\"o.wav\"}", j).status == 422, "bad outputUri");
|
||||
check(f.client->post("/google/cloudai/tts/voices", "{}", j).status == 503, "voices is 503");
|
||||
check(f.client->post("/google/cloudai/tts/voices", "{\"language\":\"n l\"}", j).status == 422, "bad language");
|
||||
// operation
|
||||
check(f.client->post("/google/cloudai/operation", "{\"api\":\"video\",\"name\":\"projects/1/locations/us-east1/operations/2\"}", j).status == 503, "operation get is 503");
|
||||
check(f.client->post("/google/cloudai/operation", "{\"api\":\"video\",\"name\":\"operations/2\"}", j).status == 422, "bad operation name");
|
||||
check(f.client->post("/google/cloudai/operation", "{\"api\":\"other\",\"name\":\"x\"}", j).status == 422, "bad api");
|
||||
// generic call
|
||||
check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.list\",\"name\":\"projects/p/locations/global\"}", j).status == 503, "GET row runs, 503");
|
||||
auto cd = f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.delete\",\"name\":\"projects/p/locations/global/glossaries/g\"}", j);
|
||||
check(cd.status == 200 && contains(cd.body, "\"dry_run\":true") && contains(cd.body, "\"http\":\"DELETE\""), "DELETE row is a dry run");
|
||||
check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.delete\",\"name\":\"projects/p/locations/global/glossaries/g\",\"confirm\":true}", j).status == 503, "confirmed DELETE is 503");
|
||||
check(f.client->post("/google/cloudai/call", "{\"rpc\":\"nope\"}", j).status == 422, "unknown rpc");
|
||||
check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.translateText\",\"name\":\"projects/p/locations/global\",\"body\":{\"bogus\":1}}", j).status == 422, "unknown request field");
|
||||
check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.list\",\"name\":\"projects/p\"}", j).status == 422, "name not matching the pattern");
|
||||
check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.list\",\"name\":\"projects/p/locations/global\",\"query\":{\"bogus\":\"1\"}}", j).status == 422, "unknown query parameter");
|
||||
check(f.client->get("/google/cloudai/call").status == 405, "get is 405");
|
||||
check(rig.mock->send_count() == 0, "nothing reached Google");
|
||||
return finish("google/cloudai/media");
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Routes: GET /google/cloudai, /google/cloudai/status, /google/cloudai/calls
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
auto page = f.client->get("/google/cloudai");
|
||||
check(page.status == 200, "page 200 without a credential");
|
||||
check(contains(page.headers.get("Content-Type"), "text/html"), "html");
|
||||
check(contains(page.body, "Cloud AI") && contains(page.body, "viewport"), "page and mobile viewport");
|
||||
check(contains(page.body, "/embedded/google_cloudai.js"), "script wired");
|
||||
auto status = f.client->get("/google/cloudai/status");
|
||||
check(status.status == 200 && contains(status.body, "\"configured\":false"), "status without credential");
|
||||
check(contains(status.body, "documentai v1") && contains(status.body, "mediatranslation"), "lists apis and the gap");
|
||||
auto calls = f.client->get("/google/cloudai/calls");
|
||||
check(calls.status == 200 && contains(calls.body, "translate.projects.locations.translateText"), "call table");
|
||||
check(contains(calls.body, "documentai.projects.locations.processors.process"), "document ai rows");
|
||||
check(f.client->post("/google/cloudai", "{}", "application/json").status == 405, "post page is 405");
|
||||
check(f.client->post("/google/cloudai/status", "{}", "application/json").status == 405, "post status is 405");
|
||||
check(rig.mock->send_count() == 0, "no network");
|
||||
return finish("google/cloudai/page");
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Routes: POST /google/cloudai/translate{,/detect,/list,/glossary}
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
const char* j = "application/json";
|
||||
auto dry = f.client->post("/google/cloudai/translate", "{\"texts\":[\"hi\"],\"target\":\"nl\"}", j);
|
||||
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true") && contains(dry.body, "targetLanguageCode"), "default is a dry run");
|
||||
auto real = f.client->post("/google/cloudai/translate", "{\"text\":\"hi\",\"target\":\"nl\",\"confirm\":true}", j);
|
||||
check(real.status == 503 && contains(real.body, "google_not_configured"), "confirmed without credential is 503");
|
||||
check(f.client->post("/google/cloudai/translate", "{}", j).status == 422, "missing target is 422");
|
||||
check(f.client->post("/google/cloudai/translate", "{\"text\":\"hi\",\"target\":\"n l\"}", j).status == 422, "bad language is 422");
|
||||
check(f.client->post("/google/cloudai/translate", "{\"texts\":[],\"target\":\"nl\"}", j).status == 422, "no text is 422");
|
||||
check(f.client->post("/google/cloudai/translate", "{\"text\":\"hi\",\"target\":\"nl\",\"confirm\":\"yes\"}", j).status == 422, "non-bool confirm is 422");
|
||||
check(f.client->post("/google/cloudai/translate", "{\"text\":\"hi\",\"target\":\"nl\",\"location\":\"../x\"}", j).status == 422, "bad location is 422");
|
||||
check(f.client->post("/google/cloudai/translate", "not json", j).status == 422, "bad json is 422");
|
||||
check(f.client->get("/google/cloudai/translate").status == 405, "get is 405");
|
||||
check(f.client->post("/google/cloudai/translate/detect", "{\"text\":\"bonjour\"}", j).status == 200, "detect dry run");
|
||||
auto det = f.client->post("/google/cloudai/translate/detect", "{\"text\":\"bonjour\",\"confirm\":true}", j);
|
||||
check(det.status == 503, "detect confirmed is 503");
|
||||
check(f.client->post("/google/cloudai/translate/detect", "{}", j).status == 422, "detect needs text");
|
||||
auto lang = f.client->post("/google/cloudai/translate/list", "{\"what\":\"languages\"}", j);
|
||||
check(lang.status == 503 && contains(lang.body, "google_not_configured"), "read without credential is 503");
|
||||
check(f.client->post("/google/cloudai/translate/list", "{\"what\":\"nope\"}", j).status == 422, "bad what is 422");
|
||||
check(f.client->post("/google/cloudai/translate/list", "{\"what\":\"glossaries\",\"location\":\"bad loc\"}", j).status == 422, "bad location");
|
||||
auto gdry = f.client->post("/google/cloudai/translate/glossary", "{\"action\":\"delete\",\"id\":\"g1\"}", j);
|
||||
check(gdry.status == 200 && contains(gdry.body, "\"dry_run\":true"), "glossary delete is a dry run");
|
||||
auto gmake = f.client->post("/google/cloudai/translate/glossary",
|
||||
"{\"action\":\"create\",\"id\":\"g1\",\"inputUri\":\"gs://b/g.csv\",\"source\":\"en\",\"target\":\"nl\"}", j);
|
||||
check(gmake.status == 200 && contains(gmake.body, "languagePair"), "glossary create is a dry run");
|
||||
auto greal = f.client->post("/google/cloudai/translate/glossary", "{\"action\":\"delete\",\"id\":\"g1\",\"confirm\":true}", j);
|
||||
check(greal.status == 503, "confirmed delete without credential is 503");
|
||||
check(f.client->post("/google/cloudai/translate/glossary", "{\"action\":\"create\",\"id\":\"g1\",\"inputUri\":\"http://x\",\"source\":\"en\",\"target\":\"nl\"}", j).status == 422, "bad inputUri is 422");
|
||||
check(f.client->post("/google/cloudai/translate/glossary", "{\"action\":\"get\",\"id\":\"a/b\"}", j).status == 422, "bad id is 422");
|
||||
check(rig.mock->send_count() == 0, "nothing reached Google");
|
||||
return finish("google/cloudai/translate");
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Routes: POST /google/cloudai/vision/{annotate,list}, /google/cloudai/language/analyze
|
||||
#include "support/GoogleRig.hpp"
|
||||
|
||||
using namespace molo::example::test;
|
||||
|
||||
int main() {
|
||||
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
|
||||
GoogleRig rig(false);
|
||||
Fixture f(rig.client);
|
||||
const char* j = "application/json";
|
||||
std::string ok = "{\"images\":[{\"uri\":\"gs://b/i.png\"}],\"features\":[{\"type\":\"LABEL_DETECTION\",\"maxResults\":3}]";
|
||||
auto dry = f.client->post("/google/cloudai/vision/annotate", ok + "}", j);
|
||||
check(dry.status == 200 && contains(dry.body, "\"dry_run\":true") && contains(dry.body, "gcsImageUri"), "annotate dry run");
|
||||
check(f.client->post("/google/cloudai/vision/annotate", ok + ",\"confirm\":true}", j).status == 503, "confirmed is 503");
|
||||
check(f.client->post("/google/cloudai/vision/annotate", "{}", j).status == 422, "images required");
|
||||
check(f.client->post("/google/cloudai/vision/annotate", "{\"images\":[{\"uri\":\"gs://b/i\"}],\"features\":[\"NOPE\"]}", j).status == 422, "unknown feature is 422");
|
||||
check(f.client->post("/google/cloudai/vision/annotate", "{\"images\":[{}],\"features\":[\"LABEL_DETECTION\"]}", j).status == 422, "empty image is 422");
|
||||
check(f.client->post("/google/cloudai/vision/annotate", "{\"images\":[{\"uri\":\"gs://b/i\"}],\"features\":[{\"type\":\"LABEL_DETECTION\",\"maxResults\":500}]}", j).status == 422, "maxResults over cap is 422");
|
||||
auto small = f.client->post("/google/cloudai/vision/annotate", "{\"images\":[{\"content\":\"" + std::string(100, 'A') + "\"}],\"features\":[\"LABEL_DETECTION\"]}", j);
|
||||
check(small.status == 200, "small inline image dry run");
|
||||
auto sets = f.client->post("/google/cloudai/vision/list", "{\"what\":\"productSets\"}", j);
|
||||
check(sets.status == 503, "list without credential is 503");
|
||||
check(f.client->post("/google/cloudai/vision/list", "{\"what\":\"referenceImages\"}", j).status == 422, "productId required");
|
||||
check(f.client->get("/google/cloudai/vision/list").status == 405, "get is 405");
|
||||
|
||||
auto nl = f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"sentiment\",\"content\":\"great\"}", j);
|
||||
check(nl.status == 200 && contains(nl.body, "\"dry_run\":true"), "analyze dry run");
|
||||
check(f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"sentiment\",\"content\":\"great\",\"confirm\":true}", j).status == 503, "confirmed is 503");
|
||||
check(f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"syntax\",\"content\":\"great\",\"confirm\":true}", j).status == 503, "v1 syntax is 503");
|
||||
check(f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"sentiment\"}", j).status == 422, "content required");
|
||||
check(f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"other\",\"content\":\"x\"}", j).status == 422, "unknown kind");
|
||||
check(f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"annotate\",\"content\":\"x\"}", j).status == 422, "annotate needs a feature");
|
||||
check(f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"annotate\",\"content\":\"x\",\"classifyText\":true}", j).status == 200, "annotate with a feature");
|
||||
check(f.client->post("/google/cloudai/language/analyze", "{\"kind\":\"sentiment\",\"content\":\"x\",\"type\":\"MD\"}", j).status == 422, "bad type");
|
||||
check(rig.mock->send_count() == 0, "nothing reached Google");
|
||||
return finish("google/cloudai/vision_language");
|
||||
}
|
||||
Reference in New Issue
Block a user