Merge branch 'worktree-agent-af2efb541856af61f'
This commit is contained in:
@@ -0,0 +1,189 @@
|
||||
# Cloud AI (Translation, Vision, Natural Language, Video Intelligence, Document AI, Speech v2, long-audio TTS) - Specification
|
||||
|
||||
Owned directory: `src/google/cloudai/`. Namespace `molo::google::cloudai`.
|
||||
Depends on the `src/google` foundation (`GoogleClient`, `Service`,
|
||||
`operation.h`, `resource.h`). Plan: `plans/18-breadth.md` section 1.
|
||||
|
||||
## 1. Scope
|
||||
|
||||
Seven Google APIs, every method of Discovery wrapped as a row of one call
|
||||
table (176 rows), with typed classes for the common paths:
|
||||
|
||||
| API | Discovery | Rows | Typed class |
|
||||
|---|---|---|---|
|
||||
| Cloud Translation | `translate` v3 | 51 | `Translation` (translate, detect, supported languages, romanize, glossaries, adaptive MT, models, datasets) |
|
||||
| Cloud Vision | `vision` v1 | 38 | `Vision` (images and files annotate, product search reads and writes) |
|
||||
| Natural Language | `language` v2 + two v1-only methods | 7 | `NaturalLanguage` (sentiment, entities, classify, moderate, annotateText; v1 entity sentiment and syntax) |
|
||||
| Video Intelligence | `videointelligence` v1 | 5 | `VideoIntelligence` (annotate start, operations) |
|
||||
| Document AI | `documentai` v1 | 42 | `DocumentAi` (process, processors, types, versions, schemas, batch start) |
|
||||
| Speech-to-Text v2 (Chirp) | `speech` v2 | 26 | `SpeechV2` (recognize, recognizers, phrase sets, custom classes, config) |
|
||||
| Text-to-Speech | `texttospeech` v1 | 7 | `LongAudio` (synthesizeLongAudio, voices, operations) |
|
||||
|
||||
Every row not covered by a typed method is still reachable and validated
|
||||
through `CloudAiService::invoke(Call, name, body, query)` and the `call()`
|
||||
member of each typed class.
|
||||
|
||||
Media Translation: not wrapped. It is not in Google's Discovery directory
|
||||
(`discovery.googleapis.com/discovery/v1/apis`, 2026-10-25) and its Discovery
|
||||
document answers 502, so no call can be derived (rule: never invent an
|
||||
endpoint). It is the only item of the plan row left out; listed in `## Gaps`.
|
||||
|
||||
Short text synthesis and the v1 speech recognizer stay in the foundation
|
||||
(`text_to_speech.h`, `speech_to_text.h`).
|
||||
|
||||
## 2. Module map
|
||||
|
||||
| File | Concern |
|
||||
|---|---|
|
||||
| `caps.h` | Static ceilings (`CloudAiCaps`) |
|
||||
| `call_enum.inc`, `calls_table.inc` | Generated from Discovery by `tools/check_discovery.py --generate`; do not edit |
|
||||
| `calls.h/.cpp` | `Call`, `CallSpec`, `render`, `query_of`, `check_body`, `endpoint_of`, `valid_enum`, the SCHEMAS / ENUMS / ENDPOINTS tables |
|
||||
| `cloudai_service.h/.cpp` | `CloudAiService`: `invoke`, `list`, `start`, `operation`, `wait`; shared input checks |
|
||||
| `translation.h/.cpp` | `Translation` |
|
||||
| `vision.h/.cpp` | `Vision` |
|
||||
| `natural_language.h/.cpp` | `NaturalLanguage` |
|
||||
| `video_intelligence.h/.cpp` | `VideoIntelligence` |
|
||||
| `document_ai.h/.cpp` | `DocumentAi` |
|
||||
| `speech_v2.h/.cpp` | `SpeechV2` |
|
||||
| `long_audio.h/.cpp` | `LongAudio` |
|
||||
| `tools/check_discovery.py` | Generator and checker against live Discovery |
|
||||
|
||||
## 3. Static caps (caps.h)
|
||||
|
||||
| Knob | Value |
|
||||
|---|---|
|
||||
| Resource name | 512 chars, each segment 1..128 of `[A-Za-z0-9._~-]`, never `.` or `..` |
|
||||
| Resource id (glossary, processor, recognizer, product) | 63 chars |
|
||||
| Request body (serialized) | 16 MiB |
|
||||
| Inline media (image, document, audio, video) | 10 MiB decoded |
|
||||
| Query parameters | 20, value 2048 chars |
|
||||
| List pages followed | 20 pages of 50 |
|
||||
| Translate texts / characters | 1024 texts, 30000 characters per request |
|
||||
| Natural Language document | 1,000,000 bytes |
|
||||
| Vision images / features / maxResults | 16 / 16 / 100; file pages 5 |
|
||||
| Video features | 9 |
|
||||
| Long audio text | 1,000,000 bytes |
|
||||
| Operation wait | foundation `OperationCaps` (600 s, 400 polls); the demo never waits |
|
||||
| Demo request body / shown response | 12 MiB / 1 MiB (larger shows a 64 KiB preview) |
|
||||
|
||||
## 4. Contracts
|
||||
|
||||
- Validation first. A resource name must match the Discovery `pattern` of the
|
||||
row's path variable (literal segments, `[^/]+`, trailing `.*` only); body
|
||||
top-level fields must be request fields of the row; query keys must be
|
||||
query parameters of the row. All of it throws `GoogleError::invalid`
|
||||
(HTTP 400 `INVALID_ARGUMENT`) before the credential check and before any
|
||||
traffic. No credential then throws `NotConfiguredError` (503).
|
||||
- Endpoints: `translation.googleapis.com/v3` (location only in the path),
|
||||
`vision.googleapis.com/v1`, `language.googleapis.com/v2` (and `/v1`),
|
||||
`videointelligence.googleapis.com/v1`, `texttospeech.googleapis.com/v1`.
|
||||
Document AI and Speech use `https://<api>.<location>.rep.googleapis.com`
|
||||
when Discovery lists the location in its `endpoints`; Speech `us` and `eu`
|
||||
use `https://<loc>-speech.googleapis.com` (product docs, see Unverified).
|
||||
- Long-running calls (`*_start`, `batch_process_start`,
|
||||
`synthesize_start`, `annotate_start`) answer the `Operation` and never wait.
|
||||
`wait()` polls with the foundation caps.
|
||||
- Writes and deletes are explicit methods without defaults
|
||||
(`create_glossary_start`, `delete_glossary_start`, `create_product_set`,
|
||||
`delete_product`, `create_processor`, `delete_processor_start`,
|
||||
`create_recognizer_start`, `delete_recognizer_start`, `cancel_operation`).
|
||||
- Paid calls: translate, detect, adaptive translate, annotate (Vision),
|
||||
NL analyze, video annotate, process, recognize, synthesize.
|
||||
|
||||
## 5. Example routes (`/google/cloudai`)
|
||||
|
||||
GET `/google/cloudai` (page), `/status`, `/calls` answer 2xx without a
|
||||
credential. Everything else is POST: 422 on bad input (checked before the
|
||||
credential), 503 `google_not_configured` without a credential. Paid calls and
|
||||
every write or delete are dry runs (200, `dry_run:true`, request shown with
|
||||
long strings redacted) unless the body has `"confirm":true`. Long-running
|
||||
starts answer 202 with the operation name. Optional `location` in every body
|
||||
(default per API: translate `global`, vision `us-west1`, document AI `us`,
|
||||
speech `us-central1`, video `us-east1`, TTS `global`); project from
|
||||
`GOOGLE_CLOUD_PROJECT`.
|
||||
|
||||
Routes: `translate`, `translate/detect`, `translate/list`,
|
||||
`translate/glossary`, `vision/annotate`, `vision/list`, `language/analyze`,
|
||||
`video/annotate`, `documentai/process`, `documentai/list`,
|
||||
`speech/recognize`, `speech/list`, `tts/long`, `tts/voices`, `operation`,
|
||||
`call` (any row by rpc id; GET rows run, others dry-run until confirm).
|
||||
Excluded from locust.
|
||||
|
||||
## Required APIs
|
||||
|
||||
Enable these on the project (placeholder project `example-214512124`). A disabled API answers 403 `SERVICE_DISABLED`.
|
||||
|
||||
- `translate.googleapis.com`: https://console.developers.google.com/apis/api/translate.googleapis.com/overview?project=example-214512124
|
||||
- `vision.googleapis.com`: https://console.developers.google.com/apis/api/vision.googleapis.com/overview?project=example-214512124
|
||||
- `language.googleapis.com`: https://console.developers.google.com/apis/api/language.googleapis.com/overview?project=example-214512124
|
||||
- `videointelligence.googleapis.com`: https://console.developers.google.com/apis/api/videointelligence.googleapis.com/overview?project=example-214512124
|
||||
- `documentai.googleapis.com`: https://console.developers.google.com/apis/api/documentai.googleapis.com/overview?project=example-214512124
|
||||
- `speech.googleapis.com`: https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=example-214512124
|
||||
- `texttospeech.googleapis.com`: https://console.developers.google.com/apis/api/texttospeech.googleapis.com/overview?project=example-214512124
|
||||
|
||||
Scope: `cloud-platform` for all (service account token as in the other
|
||||
modules). Translation, Vision, Natural Language, Speech and TTS also accept an
|
||||
API key; Document AI and Video Intelligence need OAuth in practice (unverified).
|
||||
|
||||
## Sources
|
||||
|
||||
- Discovery documents, fetched 2026-10-25: `https://<service>.googleapis.com/$discovery/rest?version=<v>`
|
||||
for `translate` v3 (rev 20260901), `vision` v1 (20260918), `language` v2 and
|
||||
v1 (20261019), `videointelligence` v1 (20260428), `documentai` v1
|
||||
(20261019), `speech` v2 (20261001), `texttospeech` v1 (20260827).
|
||||
- Directory: `https://discovery.googleapis.com/discovery/v1/apis` (no
|
||||
`mediatranslation`).
|
||||
- Product docs for semantics: Cloud Translation v3, Vision API, Natural
|
||||
Language, Video Intelligence, Document AI regional endpoints, Speech-to-Text
|
||||
v2 / Chirp, Text-to-Speech long audio.
|
||||
|
||||
## Verified against discovery
|
||||
|
||||
`python3 -I src/google/cloudai/tools/check_discovery.py` (2026-10-25): 176
|
||||
rows (HTTP method, path, request fields, query parameters, path variable and
|
||||
pattern), full coverage of the Discovery methods of the seven APIs (a new
|
||||
method fails the check until wrapped), all SCHEMAS field groups, the enum sets
|
||||
(vision features, video features, NL document type and encoding, TTS encoding
|
||||
and gender) and the regional locations of Document AI and Speech.
|
||||
|
||||
## Verified live
|
||||
|
||||
Service account of project `lisa-448004`, read-only, 2026-10-25
|
||||
(`tests/src/google/cloudai/test_cloudai_live.cpp`, `MOLO_LIVE_NET=1`):
|
||||
|
||||
| Call | Result |
|
||||
|---|---|
|
||||
| Vision `locations.productSets.list` (us-west1) | 200, 0 items |
|
||||
| Speech v2 `recognizers.list` (us-central1) | 200, 0 items |
|
||||
| Text-to-Speech `voices.list` (nl-NL) | 200, 34 voices |
|
||||
| Translation `getSupportedLanguages`, `glossaries.list`, `adaptiveMtDatasets.list`, `models.list` | 403 `PERMISSION_DENIED`: Cloud Translation API has not been used / is disabled (API NOT ENABLED) |
|
||||
| Document AI `processors.list`, `processorTypes.list` (us) | 403: Cloud Document AI API not enabled |
|
||||
| Video Intelligence `operations.list` | 403: Cloud Video Intelligence API not enabled |
|
||||
|
||||
The route, auth, regional host selection (Vision, Speech, TTS) and error
|
||||
mapping are proven by the three 200s. The three disabled APIs are ready to run
|
||||
once an owner enables them. No paid request was made (the single allowed one,
|
||||
a 5 character `translateText`, needs `MOLO_LIVE_PAID=1` and the Translation
|
||||
API enabled). Natural Language was not called live (paid per document).
|
||||
|
||||
## Unverified
|
||||
|
||||
- Response shapes are read tolerantly from Discovery schema names; only
|
||||
`Translation::translate` and the list helpers parse fields.
|
||||
- Speech multi-region hosts `us-speech.googleapis.com` / `eu-speech.googleapis.com`
|
||||
come from the product documentation, not Discovery.
|
||||
- Video `locationId` values (us-east1, us-west1, europe-west1, asia-east1) and
|
||||
product categories of Vision product search come from product docs.
|
||||
- Document AI `.rep.googleapis.com` hosts are Discovery-listed but not called
|
||||
live with a processor in this project.
|
||||
- Which APIs accept an API key versus OAuth only is not probed.
|
||||
- Nothing is created, changed or deleted live; all writes are verified by
|
||||
Discovery and by request-shape tests only.
|
||||
|
||||
## Gaps
|
||||
|
||||
- Media Translation: no Discovery document, not wrapped.
|
||||
- Typed response classes: replies are returned as `Json` except translate.
|
||||
- Streaming Speech recognition (gRPC) and Document AI `humanReviewConfig`
|
||||
flows beyond the raw call are not typed.
|
||||
- Upload of media is inline base64 or `gs://` only.
|
||||
@@ -0,0 +1,177 @@
|
||||
// Generated by tools/check_discovery.py --generate. Do not edit.
|
||||
kTranslateDetectLanguage,
|
||||
kTranslateGetSupportedLanguages,
|
||||
kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesAdaptiveMtSentencesList,
|
||||
kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesDelete,
|
||||
kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesGet,
|
||||
kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesList,
|
||||
kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtSentencesList,
|
||||
kTranslateLocationsAdaptiveMtDatasetsCreate,
|
||||
kTranslateLocationsAdaptiveMtDatasetsDelete,
|
||||
kTranslateLocationsAdaptiveMtDatasetsGet,
|
||||
kTranslateLocationsAdaptiveMtDatasetsImportAdaptiveMtFile,
|
||||
kTranslateLocationsAdaptiveMtDatasetsList,
|
||||
kTranslateLocationsAdaptiveMtTranslate,
|
||||
kTranslateLocationsBatchTranslateDocument,
|
||||
kTranslateLocationsBatchTranslateText,
|
||||
kTranslateLocationsDatasetsCreate,
|
||||
kTranslateLocationsDatasetsDelete,
|
||||
kTranslateLocationsDatasetsExamplesList,
|
||||
kTranslateLocationsDatasetsExportData,
|
||||
kTranslateLocationsDatasetsGet,
|
||||
kTranslateLocationsDatasetsImportData,
|
||||
kTranslateLocationsDatasetsList,
|
||||
kTranslateLocationsDetectLanguage,
|
||||
kTranslateLocationsGet,
|
||||
kTranslateLocationsGetSupportedLanguages,
|
||||
kTranslateLocationsGlossariesCreate,
|
||||
kTranslateLocationsGlossariesDelete,
|
||||
kTranslateLocationsGlossariesGet,
|
||||
kTranslateLocationsGlossariesGlossaryEntriesCreate,
|
||||
kTranslateLocationsGlossariesGlossaryEntriesDelete,
|
||||
kTranslateLocationsGlossariesGlossaryEntriesGet,
|
||||
kTranslateLocationsGlossariesGlossaryEntriesList,
|
||||
kTranslateLocationsGlossariesGlossaryEntriesPatch,
|
||||
kTranslateLocationsGlossariesList,
|
||||
kTranslateLocationsGlossariesPatch,
|
||||
kTranslateLocationsList,
|
||||
kTranslateLocationsModelsCreate,
|
||||
kTranslateLocationsModelsDelete,
|
||||
kTranslateLocationsModelsGet,
|
||||
kTranslateLocationsModelsList,
|
||||
kTranslateLocationsOperationsCancel,
|
||||
kTranslateLocationsOperationsDelete,
|
||||
kTranslateLocationsOperationsGet,
|
||||
kTranslateLocationsOperationsList,
|
||||
kTranslateLocationsOperationsWait,
|
||||
kTranslateLocationsRefineText,
|
||||
kTranslateLocationsRomanizeText,
|
||||
kTranslateLocationsTranslateDocument,
|
||||
kTranslateLocationsTranslateText,
|
||||
kTranslateRomanizeText,
|
||||
kTranslateTranslateText,
|
||||
kVisionFilesAnnotate,
|
||||
kVisionFilesAsyncBatchAnnotate,
|
||||
kVisionImagesAnnotate,
|
||||
kVisionImagesAsyncBatchAnnotate,
|
||||
kVisionLocationsOperationsGet,
|
||||
kVisionOperationsCancel,
|
||||
kVisionOperationsDelete,
|
||||
kVisionOperationsGet,
|
||||
kVisionOperationsList,
|
||||
kVisionProjectsFilesAnnotate,
|
||||
kVisionProjectsFilesAsyncBatchAnnotate,
|
||||
kVisionProjectsImagesAnnotate,
|
||||
kVisionProjectsImagesAsyncBatchAnnotate,
|
||||
kVisionLocationsFilesAnnotate,
|
||||
kVisionLocationsFilesAsyncBatchAnnotate,
|
||||
kVisionLocationsImagesAnnotate,
|
||||
kVisionLocationsImagesAsyncBatchAnnotate,
|
||||
kVisionProjectsLocationsOperationsGet,
|
||||
kVisionLocationsProductSetsAddProduct,
|
||||
kVisionLocationsProductSetsCreate,
|
||||
kVisionLocationsProductSetsDelete,
|
||||
kVisionLocationsProductSetsGet,
|
||||
kVisionLocationsProductSetsImport,
|
||||
kVisionLocationsProductSetsList,
|
||||
kVisionLocationsProductSetsPatch,
|
||||
kVisionLocationsProductSetsProductsList,
|
||||
kVisionLocationsProductSetsRemoveProduct,
|
||||
kVisionLocationsProductsCreate,
|
||||
kVisionLocationsProductsDelete,
|
||||
kVisionLocationsProductsGet,
|
||||
kVisionLocationsProductsList,
|
||||
kVisionLocationsProductsPatch,
|
||||
kVisionLocationsProductsPurge,
|
||||
kVisionLocationsProductsReferenceImagesCreate,
|
||||
kVisionLocationsProductsReferenceImagesDelete,
|
||||
kVisionLocationsProductsReferenceImagesGet,
|
||||
kVisionLocationsProductsReferenceImagesList,
|
||||
kVisionProjectsOperationsGet,
|
||||
kLanguageDocumentsAnalyzeEntities,
|
||||
kLanguageDocumentsAnalyzeSentiment,
|
||||
kLanguageDocumentsAnnotateText,
|
||||
kLanguageDocumentsClassifyText,
|
||||
kLanguageDocumentsModerateText,
|
||||
kLanguageV1DocumentsAnalyzeEntitySentiment,
|
||||
kLanguageV1DocumentsAnalyzeSyntax,
|
||||
kVideoLocationsOperationsCancel,
|
||||
kVideoLocationsOperationsDelete,
|
||||
kVideoLocationsOperationsGet,
|
||||
kVideoLocationsOperationsList,
|
||||
kVideoVideosAnnotate,
|
||||
kDocumentaiOperationsDelete,
|
||||
kDocumentaiLocationsFetchProcessorTypes,
|
||||
kDocumentaiLocationsGet,
|
||||
kDocumentaiLocationsList,
|
||||
kDocumentaiLocationsOperationsCancel,
|
||||
kDocumentaiLocationsOperationsGet,
|
||||
kDocumentaiLocationsOperationsList,
|
||||
kDocumentaiLocationsProcessorTypesGet,
|
||||
kDocumentaiLocationsProcessorTypesList,
|
||||
kDocumentaiLocationsProcessorsBatchProcess,
|
||||
kDocumentaiLocationsProcessorsCreate,
|
||||
kDocumentaiLocationsProcessorsDelete,
|
||||
kDocumentaiLocationsProcessorsDisable,
|
||||
kDocumentaiLocationsProcessorsEnable,
|
||||
kDocumentaiLocationsProcessorsGet,
|
||||
kDocumentaiLocationsProcessorsHumanReviewConfigReviewDocument,
|
||||
kDocumentaiLocationsProcessorsList,
|
||||
kDocumentaiLocationsProcessorsProcess,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsBatchProcess,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsDelete,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsDeploy,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsEvaluateProcessorVersion,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsEvaluationsGet,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsEvaluationsList,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsGet,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsList,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsProcess,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsTrain,
|
||||
kDocumentaiLocationsProcessorsProcessorVersionsUndeploy,
|
||||
kDocumentaiLocationsProcessorsSetDefaultProcessorVersion,
|
||||
kDocumentaiLocationsSchemasCreate,
|
||||
kDocumentaiLocationsSchemasDelete,
|
||||
kDocumentaiLocationsSchemasGet,
|
||||
kDocumentaiLocationsSchemasList,
|
||||
kDocumentaiLocationsSchemasPatch,
|
||||
kDocumentaiLocationsSchemasSchemaVersionsCreate,
|
||||
kDocumentaiLocationsSchemasSchemaVersionsDelete,
|
||||
kDocumentaiLocationsSchemasSchemaVersionsGenerate,
|
||||
kDocumentaiLocationsSchemasSchemaVersionsGet,
|
||||
kDocumentaiLocationsSchemasSchemaVersionsList,
|
||||
kDocumentaiLocationsSchemasSchemaVersionsPatch,
|
||||
kDocumentaiOperationsGet,
|
||||
kSpeechLocationsConfigGet,
|
||||
kSpeechLocationsConfigUpdate,
|
||||
kSpeechLocationsCustomClassesCreate,
|
||||
kSpeechLocationsCustomClassesDelete,
|
||||
kSpeechLocationsCustomClassesGet,
|
||||
kSpeechLocationsCustomClassesList,
|
||||
kSpeechLocationsCustomClassesPatch,
|
||||
kSpeechLocationsCustomClassesUndelete,
|
||||
kSpeechLocationsGet,
|
||||
kSpeechLocationsList,
|
||||
kSpeechLocationsOperationsGet,
|
||||
kSpeechLocationsOperationsList,
|
||||
kSpeechLocationsPhraseSetsCreate,
|
||||
kSpeechLocationsPhraseSetsDelete,
|
||||
kSpeechLocationsPhraseSetsGet,
|
||||
kSpeechLocationsPhraseSetsList,
|
||||
kSpeechLocationsPhraseSetsPatch,
|
||||
kSpeechLocationsPhraseSetsUndelete,
|
||||
kSpeechLocationsRecognizersBatchRecognize,
|
||||
kSpeechLocationsRecognizersCreate,
|
||||
kSpeechLocationsRecognizersDelete,
|
||||
kSpeechLocationsRecognizersGet,
|
||||
kSpeechLocationsRecognizersList,
|
||||
kSpeechLocationsRecognizersPatch,
|
||||
kSpeechLocationsRecognizersRecognize,
|
||||
kSpeechLocationsRecognizersUndelete,
|
||||
kTtsOperationsCancel,
|
||||
kTtsOperationsDelete,
|
||||
kTtsLocationsOperationsGet,
|
||||
kTtsLocationsOperationsList,
|
||||
kTtsLocationsSynthesizeLongAudio,
|
||||
kTtsTextSynthesize,
|
||||
kTtsVoicesList,
|
||||
@@ -0,0 +1,281 @@
|
||||
#include "google/cloudai/calls.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "clients/url.h"
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
static const CallSpec kCalls[] = {
|
||||
#include "google/cloudai/calls_table.inc"
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
// Regional hosts https://<api>.<location>.rep.googleapis.com (checked against
|
||||
// the Discovery `endpoints` list by tools/check_discovery.py).
|
||||
struct RegionalHosts {
|
||||
const char* api;
|
||||
const char* version;
|
||||
const char* locations;
|
||||
};
|
||||
// ENDPOINTS-BEGIN
|
||||
const RegionalHosts kRegional[] = {
|
||||
{"documentai", "v1", "us,eu,asia-south1,asia-southeast1,northamerica-northeast1,australia-southeast1,europe-west2,europe-west3"},
|
||||
{"speech", "v2", "us-central1,us-west1,me-west1,europe-west1,europe-west2,europe-west3,europe-west4"},
|
||||
};
|
||||
// ENDPOINTS-END
|
||||
|
||||
// Schema fields the typed classes put into request bodies; every one is
|
||||
// checked against Discovery by tools/check_discovery.py.
|
||||
struct SchemaFields {
|
||||
const char* api;
|
||||
const char* version;
|
||||
const char* schema;
|
||||
const char* fields;
|
||||
};
|
||||
// SCHEMAS-BEGIN
|
||||
const SchemaFields kSchemas[] = {
|
||||
{"translate", "v3", "TranslateTextRequest", "contents,mimeType,sourceLanguageCode,targetLanguageCode,model,glossaryConfig,labels"},
|
||||
{"translate", "v3", "DetectLanguageRequest", "content,mimeType,model,labels"},
|
||||
{"translate", "v3", "RomanizeTextRequest", "contents,sourceLanguageCode"},
|
||||
{"translate", "v3", "Glossary", "name,languagePair,languageCodesSet,inputConfig,displayName"},
|
||||
{"translate", "v3", "TranslateTextGlossaryConfig", "glossary,ignoreCase"},
|
||||
{"vision", "v1", "AnnotateImageRequest", "image,features,imageContext"},
|
||||
{"vision", "v1", "BatchAnnotateImagesRequest", "requests,parent"},
|
||||
{"vision", "v1", "Image", "content,source"},
|
||||
{"vision", "v1", "ImageSource", "imageUri,gcsImageUri"},
|
||||
{"vision", "v1", "Feature", "type,maxResults,model"},
|
||||
{"vision", "v1", "Product", "name,displayName,description,productCategory,productLabels"},
|
||||
{"language", "v2", "Document", "type,content,gcsContentUri,languageCode"},
|
||||
{"language", "v2", "AnalyzeSentimentRequest", "document,encodingType"},
|
||||
{"language", "v2", "AnalyzeEntitiesRequest", "document,encodingType"},
|
||||
{"language", "v2", "ClassifyTextRequest", "document"},
|
||||
{"language", "v2", "ModerateTextRequest", "document"},
|
||||
{"language", "v1", "AnalyzeSyntaxRequest", "document,encodingType"},
|
||||
{"language", "v1", "AnalyzeEntitySentimentRequest", "document,encodingType"},
|
||||
{"videointelligence", "v1", "GoogleCloudVideointelligenceV1_AnnotateVideoRequest", "inputUri,inputContent,features,locationId,outputUri"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1ProcessRequest", "rawDocument,inlineDocument,gcsDocument,skipHumanReview,fieldMask"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1RawDocument", "content,mimeType,displayName"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1Processor", "displayName,type"},
|
||||
{"speech", "v2", "RecognizeRequest", "config,configMask,content,uri"},
|
||||
{"speech", "v2", "RecognitionConfig", "autoDecodingConfig,explicitDecodingConfig,model,languageCodes,features"},
|
||||
{"texttospeech", "v1", "SynthesizeLongAudioRequest", "input,audioConfig,outputGcsUri,voice"},
|
||||
{"translate", "v3", "GcsSource", "inputUri"},
|
||||
{"translate", "v3", "LanguageCodesSet", "languageCodes"},
|
||||
{"translate", "v3", "LanguageCodePair", "sourceLanguageCode,targetLanguageCode"},
|
||||
{"vision", "v1", "GcsSource", "uri"},
|
||||
{"vision", "v1", "ProductSet", "displayName"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1GcsDocument", "gcsUri,mimeType"},
|
||||
{"speech", "v2", "Recognizer", "model,languageCodes"},
|
||||
{"texttospeech", "v1", "SynthesisInput", "text,ssml"},
|
||||
{"texttospeech", "v1", "VoiceSelectionParams", "languageCode,name,ssmlGender"},
|
||||
{"texttospeech", "v1", "AudioConfig", "audioEncoding,speakingRate,pitch,sampleRateHertz"},
|
||||
{"translate", "v3", "TranslateTextResponse", "translations,glossaryTranslations"},
|
||||
{"translate", "v3", "Translation", "translatedText,detectedLanguageCode,model"},
|
||||
{"translate", "v3", "DetectLanguageResponse", "languages"},
|
||||
{"translate", "v3", "SupportedLanguages", "languages"},
|
||||
{"translate", "v3", "ListGlossariesResponse", "glossaries,nextPageToken"},
|
||||
{"translate", "v3", "ListAdaptiveMtDatasetsResponse", "adaptiveMtDatasets,nextPageToken"},
|
||||
{"translate", "v3", "ListModelsResponse", "models,nextPageToken"},
|
||||
{"translate", "v3", "AdaptiveMtTranslateRequest", "dataset,content,mimeType"},
|
||||
{"vision", "v1", "BatchAnnotateImagesResponse", "responses"},
|
||||
{"vision", "v1", "ListProductSetsResponse", "productSets,nextPageToken"},
|
||||
{"vision", "v1", "ListProductsResponse", "products,nextPageToken"},
|
||||
{"vision", "v1", "AnnotateFileRequest", "inputConfig,features,pages"},
|
||||
{"vision", "v1", "InputConfig", "gcsSource,mimeType,content"},
|
||||
{"language", "v2", "AnnotateTextRequest", "document,features,encodingType"},
|
||||
{"language", "v2", "AnnotateTextRequestFeatures", "extractEntities,extractDocumentSentiment,classifyText,moderateText"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1ListProcessorsResponse", "processors,nextPageToken"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1ListProcessorTypesResponse", "processorTypes,nextPageToken"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1ProcessResponse", "document,humanReviewStatus"},
|
||||
{"documentai", "v1", "GoogleCloudDocumentaiV1ListProcessorVersionsResponse", "processorVersions,nextPageToken"},
|
||||
{"speech", "v2", "ListRecognizersResponse", "recognizers,nextPageToken"},
|
||||
{"speech", "v2", "ListPhraseSetsResponse", "phraseSets,nextPageToken"},
|
||||
{"speech", "v2", "ListCustomClassesResponse", "customClasses,nextPageToken"},
|
||||
{"speech", "v2", "RecognizeResponse", "results,metadata"},
|
||||
{"speech", "v2", "ExplicitDecodingConfig", "encoding,sampleRateHertz,audioChannelCount"},
|
||||
};
|
||||
// SCHEMAS-END
|
||||
|
||||
// Enum values the typed classes accept (UNSPECIFIED values left out); every
|
||||
// set must equal the Discovery enum, checked by tools/check_discovery.py.
|
||||
struct EnumSet {
|
||||
const char* api;
|
||||
const char* version;
|
||||
const char* schema_field;
|
||||
const char* values;
|
||||
};
|
||||
// ENUMS-BEGIN
|
||||
const EnumSet kEnums[] = {
|
||||
{"vision", "v1", "Feature.type", "FACE_DETECTION,LANDMARK_DETECTION,LOGO_DETECTION,LABEL_DETECTION,TEXT_DETECTION,DOCUMENT_TEXT_DETECTION,SAFE_SEARCH_DETECTION,IMAGE_PROPERTIES,CROP_HINTS,WEB_DETECTION,PRODUCT_SEARCH,OBJECT_LOCALIZATION"},
|
||||
{"videointelligence", "v1", "GoogleCloudVideointelligenceV1_AnnotateVideoRequest.features", "LABEL_DETECTION,SHOT_CHANGE_DETECTION,EXPLICIT_CONTENT_DETECTION,FACE_DETECTION,SPEECH_TRANSCRIPTION,TEXT_DETECTION,OBJECT_TRACKING,LOGO_RECOGNITION,PERSON_DETECTION"},
|
||||
{"language", "v2", "Document.type", "PLAIN_TEXT,HTML"},
|
||||
{"language", "v2", "AnnotateTextRequest.encodingType", "NONE,UTF8,UTF16,UTF32"},
|
||||
{"texttospeech", "v1", "AudioConfig.audioEncoding", "LINEAR16,MP3,OGG_OPUS,MULAW,ALAW,PCM,M4A"},
|
||||
{"texttospeech", "v1", "VoiceSelectionParams.ssmlGender", "MALE,FEMALE,NEUTRAL"},
|
||||
};
|
||||
// ENUMS-END
|
||||
|
||||
std::vector<std::string> split(const std::string& s, char sep) {
|
||||
std::vector<std::string> out;
|
||||
std::size_t start = 0;
|
||||
for (;;) {
|
||||
std::size_t at = s.find(sep, start);
|
||||
if (at == std::string::npos) {
|
||||
out.push_back(s.substr(start));
|
||||
return out;
|
||||
}
|
||||
out.push_back(s.substr(start, at - start));
|
||||
start = at + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Discovery patterns here are only literal segments, [^/]+ and a trailing .*.
|
||||
bool matches(const std::string& pattern_raw, const std::string& name) {
|
||||
std::string pattern = pattern_raw;
|
||||
if (!pattern.empty() && pattern.front() == '^') pattern.erase(0, 1);
|
||||
if (!pattern.empty() && pattern.back() == '$') pattern.pop_back();
|
||||
// "[^/]+" holds a slash: swap it for a one-character token before splitting.
|
||||
for (std::size_t at = pattern.find("[^/]+"); at != std::string::npos; at = pattern.find("[^/]+", at + 1))
|
||||
pattern.replace(at, 5, "*");
|
||||
std::vector<std::string> ps = split(pattern, '/');
|
||||
std::vector<std::string> ns = split(name, '/');
|
||||
for (std::size_t i = 0; i < ps.size(); ++i) {
|
||||
if (ps[i] == ".*") return i < ns.size() && i + 1 == ps.size();
|
||||
if (i >= ns.size()) return false;
|
||||
if (ps[i] == "*") {
|
||||
if (!valid_name_segment(ns[i])) return false;
|
||||
} else if (ps[i] != ns[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return ps.size() == ns.size();
|
||||
}
|
||||
|
||||
bool has_field(const char* list, const std::string& key) {
|
||||
std::string l = std::string(",") + list + ",";
|
||||
return l.find("," + key + ",") != std::string::npos;
|
||||
}
|
||||
|
||||
std::string location_of(const std::string& name) {
|
||||
std::vector<std::string> segs = split(name, '/');
|
||||
for (std::size_t i = 0; i + 1 < segs.size(); ++i)
|
||||
if (segs[i] == "locations") return segs[i + 1];
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::size_t call_count() { return sizeof(kCalls) / sizeof(kCalls[0]); }
|
||||
|
||||
bool valid_enum(const std::string& schema_field, const std::string& value) {
|
||||
for (const EnumSet& e : kEnums)
|
||||
if (schema_field == e.schema_field)
|
||||
return (std::string(",") + e.values + ",").find("," + value + ",") != std::string::npos;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t schema_count() { return sizeof(kSchemas) / sizeof(kSchemas[0]); }
|
||||
|
||||
const CallSpec& spec_at(std::size_t index) {
|
||||
if (index >= call_count()) throw GoogleError::invalid("no such call");
|
||||
return kCalls[index];
|
||||
}
|
||||
|
||||
const CallSpec& spec(Call call) { return spec_at(static_cast<std::size_t>(call)); }
|
||||
|
||||
const CallSpec* find_rpc(const std::string& rpc_id) {
|
||||
for (const CallSpec& s : kCalls)
|
||||
if (rpc_id == s.rpc_id) return &s;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
clients::Method method_of(Call call) {
|
||||
const char* m = spec(call).http_method;
|
||||
if (!std::strcmp(m, "GET")) return clients::Method::kGet;
|
||||
if (!std::strcmp(m, "POST")) return clients::Method::kPost;
|
||||
if (!std::strcmp(m, "PATCH")) return clients::Method::kPatch;
|
||||
if (!std::strcmp(m, "DELETE")) return clients::Method::kDelete;
|
||||
throw GoogleError::invalid("unsupported http method");
|
||||
}
|
||||
|
||||
bool valid_name_segment(const std::string& s) {
|
||||
if (s.empty() || s.size() > CloudAiCaps::kMaxSegmentChars) return false;
|
||||
if (s == "." || s == "..") return false;
|
||||
for (char c : s)
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') ||
|
||||
c == '-' || c == '_' || c == '.' || c == '~'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string render(Call call, const std::string& name) {
|
||||
const CallSpec& s = spec(call);
|
||||
std::string path = s.path;
|
||||
path.erase(0, path.find('/') + 1); // version prefix
|
||||
if (!*s.path_var) {
|
||||
if (!name.empty()) throw GoogleError::invalid("this call takes no resource name");
|
||||
return "/" + path;
|
||||
}
|
||||
if (name.empty() || name.size() > CloudAiCaps::kMaxNameChars)
|
||||
throw GoogleError::invalid("resource name is missing or too long");
|
||||
if (!matches(s.pattern, name))
|
||||
throw GoogleError::invalid(std::string("resource name does not match ") + s.pattern);
|
||||
std::size_t open = path.find('{');
|
||||
std::size_t close = path.find('}', open);
|
||||
path.replace(open, close - open + 1, name);
|
||||
return "/" + path;
|
||||
}
|
||||
|
||||
std::string query_of(Call call, const Query& query) {
|
||||
if (query.size() > CloudAiCaps::kMaxQueryParams) throw GoogleError::invalid("too many query parameters");
|
||||
const CallSpec& s = spec(call);
|
||||
std::string out;
|
||||
for (const auto& [k, v] : query) {
|
||||
if (!has_field(s.query_params, k)) throw GoogleError::invalid("unknown query parameter " + k);
|
||||
if (v.size() > CloudAiCaps::kMaxQueryValueChars) throw GoogleError::invalid("query value too long");
|
||||
out += (out.empty() ? "?" : "&") + clients::Url::encode_component(k) + "=" +
|
||||
clients::Url::encode_component(v);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
void check_body(Call call, const Json* body) {
|
||||
if (!body || body->is_null()) return;
|
||||
const CallSpec& s = spec(call);
|
||||
if (!std::strcmp(s.http_method, "GET") || !std::strcmp(s.http_method, "DELETE"))
|
||||
throw GoogleError::invalid("this call takes no request body");
|
||||
if (!body->is_object()) throw GoogleError::invalid("request body must be a JSON object");
|
||||
for (const auto& [k, v] : body->as_object()) {
|
||||
(void)v;
|
||||
if (!has_field(s.body_fields, k)) throw GoogleError::invalid("unknown request field " + k);
|
||||
}
|
||||
if (body->dump().size() > CloudAiCaps::kMaxBodyBytes) throw GoogleError::invalid("request body too large");
|
||||
}
|
||||
|
||||
ServiceEndpoint endpoint_of(Call call, const std::string& name) {
|
||||
const CallSpec& s = spec(call);
|
||||
std::string api = s.api;
|
||||
std::string root = "https://" + api + ".googleapis.com";
|
||||
std::string service = api;
|
||||
if (api == "translate") {
|
||||
root = "https://translation.googleapis.com";
|
||||
} else {
|
||||
std::string loc = location_of(name);
|
||||
for (const RegionalHosts& r : kRegional) {
|
||||
if (api != r.api || loc.empty()) continue;
|
||||
if ((std::string(",") + r.locations + ",").find("," + loc + ",") != std::string::npos)
|
||||
root = "https://" + api + "." + loc + ".rep.googleapis.com";
|
||||
else if (api == "speech" && (loc == "us" || loc == "eu"))
|
||||
root = "https://" + loc + "-speech.googleapis.com"; // multi-region, product docs
|
||||
}
|
||||
}
|
||||
return {service, root + "/" + s.version};
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
// The ONE table of REST calls this package makes. The rows (calls_table.inc)
|
||||
// and the enum (call_enum.inc) are generated from Google's Discovery documents
|
||||
// by tools/check_discovery.py --generate and verified by the same script.
|
||||
// Code builds every URL from this table, never from a literal. Package
|
||||
// coverage: Translation v3, Vision v1, Natural Language v2 (+ two v1 only
|
||||
// methods), Video Intelligence v1, Document AI v1, Speech v2, Text-to-Speech
|
||||
// v1 (long audio and voices). Media Translation has no Discovery document.
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "clients/body/json.h"
|
||||
#include "clients/request.h"
|
||||
#include "google/endpoints.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
enum class Call {
|
||||
#include "google/cloudai/call_enum.inc"
|
||||
};
|
||||
|
||||
struct CallSpec {
|
||||
Call call;
|
||||
const char* http_method;
|
||||
const char* path; // Discovery path, version prefix included
|
||||
const char* api; // Discovery name: translate, vision, language, ...
|
||||
const char* version; // v1, v2, v3
|
||||
const char* rpc_id; // Discovery method id
|
||||
const char* body_fields; // comma list: top-level request fields
|
||||
const char* query_params; // comma list
|
||||
const char* path_var; // the one path variable ("" if none)
|
||||
const char* pattern; // Discovery pattern of that variable
|
||||
};
|
||||
|
||||
std::size_t call_count();
|
||||
const CallSpec& spec_at(std::size_t index);
|
||||
const CallSpec& spec(Call call);
|
||||
const CallSpec* find_rpc(const std::string& rpc_id);
|
||||
// Number of schema field groups verified against Discovery (SCHEMAS table).
|
||||
std::size_t schema_count();
|
||||
|
||||
clients::Method method_of(Call call);
|
||||
|
||||
// Query parameters in send order; each key must be in the row.
|
||||
using Query = std::vector<std::pair<std::string, std::string>>;
|
||||
|
||||
// The path after the version prefix, with `name` validated against the
|
||||
// Discovery pattern of the row's path variable. Rows without a variable take
|
||||
// an empty name. Throws GoogleError::invalid.
|
||||
std::string render(Call call, const std::string& name);
|
||||
|
||||
// "?k=v&..." (encoded), "" when empty. Keys must be query parameters of the
|
||||
// row; count and value sizes are capped.
|
||||
std::string query_of(Call call, const Query& query);
|
||||
|
||||
// Throws GoogleError::invalid when a top-level field is not a request field
|
||||
// of the row, the body is not an object, it exceeds the size cap, or a GET /
|
||||
// DELETE row is given a body. A null pointer is always fine.
|
||||
void check_body(Call call, const clients::body::Json* body);
|
||||
|
||||
// Endpoint for a call. Document AI and Speech use the regional host named in
|
||||
// `name` (".../locations/{l}/...") when Discovery lists one.
|
||||
ServiceEndpoint endpoint_of(Call call, const std::string& name);
|
||||
|
||||
// True when `value` is a Discovery enum value of "Schema.field" for the
|
||||
// enum sets this package accepts ("Feature.type", "AudioConfig.audioEncoding").
|
||||
bool valid_enum(const std::string& schema_field, const std::string& value);
|
||||
|
||||
// True for [A-Za-z0-9._~-], 1..128, not "." or "..".
|
||||
bool valid_name_segment(const std::string& s);
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,179 @@
|
||||
// Generated by tools/check_discovery.py --generate. Do not edit.
|
||||
// CALLS-BEGIN (parsed by tools/check_discovery.py; one row per line)
|
||||
{Call::kTranslateDetectLanguage, "POST", "v3/{+parent}:detectLanguage", "translate", "v3", "translate.projects.detectLanguage", "content,documentInputConfig,labels,mimeType,model", "", "parent", "^projects/[^/]+$"},
|
||||
{Call::kTranslateGetSupportedLanguages, "GET", "v3/{+parent}/supportedLanguages", "translate", "v3", "translate.projects.getSupportedLanguages", "", "displayLanguageCode,model", "parent", "^projects/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesAdaptiveMtSentencesList, "GET", "v3/{+parent}/adaptiveMtSentences", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.adaptiveMtFiles.adaptiveMtSentences.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+/adaptiveMtFiles/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesDelete, "DELETE", "v3/{+name}", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.adaptiveMtFiles.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+/adaptiveMtFiles/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.adaptiveMtFiles.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+/adaptiveMtFiles/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtFilesList, "GET", "v3/{+parent}/adaptiveMtFiles", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.adaptiveMtFiles.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsAdaptiveMtSentencesList, "GET", "v3/{+parent}/adaptiveMtSentences", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.adaptiveMtSentences.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsCreate, "POST", "v3/{+parent}/adaptiveMtDatasets", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.create", "createTime,displayName,exampleCount,name,sourceLanguageCode,targetLanguageCode,updateTime", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsDelete, "DELETE", "v3/{+name}", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsImportAdaptiveMtFile, "POST", "v3/{+parent}:importAdaptiveMtFile", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.importAdaptiveMtFile", "fileInputSource,gcsInputSource", "", "parent", "^projects/[^/]+/locations/[^/]+/adaptiveMtDatasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtDatasetsList, "GET", "v3/{+parent}/adaptiveMtDatasets", "translate", "v3", "translate.projects.locations.adaptiveMtDatasets.list", "", "filter,pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsAdaptiveMtTranslate, "POST", "v3/{+parent}:adaptiveMtTranslate", "translate", "v3", "translate.projects.locations.adaptiveMtTranslate", "content,dataset,glossaryConfig,mimeType,referenceSentenceConfig", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsBatchTranslateDocument, "POST", "v3/{+parent}:batchTranslateDocument", "translate", "v3", "translate.projects.locations.batchTranslateDocument", "customizedAttribution,enableRotationCorrection,enableShadowRemovalNativePdf,formatConversions,glossaries,inputConfigs,models,outputConfig,pdfNativeOnly,sourceLanguageCode,targetLanguageCodes", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsBatchTranslateText, "POST", "v3/{+parent}:batchTranslateText", "translate", "v3", "translate.projects.locations.batchTranslateText", "glossaries,inputConfigs,labels,models,outputConfig,sourceLanguageCode,targetLanguageCodes", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsDatasetsCreate, "POST", "v3/{+parent}/datasets", "translate", "v3", "translate.projects.locations.datasets.create", "createTime,displayName,exampleCount,name,sourceLanguageCode,targetLanguageCode,testExampleCount,trainExampleCount,updateTime,validateExampleCount", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsDatasetsDelete, "DELETE", "v3/{+name}", "translate", "v3", "translate.projects.locations.datasets.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/datasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsDatasetsExamplesList, "GET", "v3/{+parent}/examples", "translate", "v3", "translate.projects.locations.datasets.examples.list", "", "filter,pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/datasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsDatasetsExportData, "POST", "v3/{+dataset}:exportData", "translate", "v3", "translate.projects.locations.datasets.exportData", "outputConfig", "", "dataset", "^projects/[^/]+/locations/[^/]+/datasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsDatasetsGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.datasets.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/datasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsDatasetsImportData, "POST", "v3/{+dataset}:importData", "translate", "v3", "translate.projects.locations.datasets.importData", "inputConfig", "", "dataset", "^projects/[^/]+/locations/[^/]+/datasets/[^/]+$"},
|
||||
{Call::kTranslateLocationsDatasetsList, "GET", "v3/{+parent}/datasets", "translate", "v3", "translate.projects.locations.datasets.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsDetectLanguage, "POST", "v3/{+parent}:detectLanguage", "translate", "v3", "translate.projects.locations.detectLanguage", "content,documentInputConfig,labels,mimeType,model", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsGetSupportedLanguages, "GET", "v3/{+parent}/supportedLanguages", "translate", "v3", "translate.projects.locations.getSupportedLanguages", "", "displayLanguageCode,model", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesCreate, "POST", "v3/{+parent}/glossaries", "translate", "v3", "translate.projects.locations.glossaries.create", "displayName,endTime,entryCount,inputConfig,languageCodesSet,languagePair,name,submitTime", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesDelete, "DELETE", "v3/{+name}", "translate", "v3", "translate.projects.locations.glossaries.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.glossaries.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesGlossaryEntriesCreate, "POST", "v3/{+parent}/glossaryEntries", "translate", "v3", "translate.projects.locations.glossaries.glossaryEntries.create", "description,name,termsPair,termsSet", "", "parent", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesGlossaryEntriesDelete, "DELETE", "v3/{+name}", "translate", "v3", "translate.projects.locations.glossaries.glossaryEntries.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+/glossaryEntries/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesGlossaryEntriesGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.glossaries.glossaryEntries.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+/glossaryEntries/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesGlossaryEntriesList, "GET", "v3/{+parent}/glossaryEntries", "translate", "v3", "translate.projects.locations.glossaries.glossaryEntries.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesGlossaryEntriesPatch, "PATCH", "v3/{+name}", "translate", "v3", "translate.projects.locations.glossaries.glossaryEntries.patch", "description,name,termsPair,termsSet", "", "name", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+/glossaryEntries/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesList, "GET", "v3/{+parent}/glossaries", "translate", "v3", "translate.projects.locations.glossaries.list", "", "filter,pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsGlossariesPatch, "PATCH", "v3/{+name}", "translate", "v3", "translate.projects.locations.glossaries.patch", "displayName,endTime,entryCount,inputConfig,languageCodesSet,languagePair,name,submitTime", "updateMask", "name", "^projects/[^/]+/locations/[^/]+/glossaries/[^/]+$"},
|
||||
{Call::kTranslateLocationsList, "GET", "v3/{+name}/locations", "translate", "v3", "translate.projects.locations.list", "", "extraLocationTypes,filter,pageSize,pageToken", "name", "^projects/[^/]+$"},
|
||||
{Call::kTranslateLocationsModelsCreate, "POST", "v3/{+parent}/models", "translate", "v3", "translate.projects.locations.models.create", "createTime,dataset,displayName,name,sourceLanguageCode,targetLanguageCode,testExampleCount,trainExampleCount,updateTime,validateExampleCount", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsModelsDelete, "DELETE", "v3/{+name}", "translate", "v3", "translate.projects.locations.models.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/models/[^/]+$"},
|
||||
{Call::kTranslateLocationsModelsGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.models.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/models/[^/]+$"},
|
||||
{Call::kTranslateLocationsModelsList, "GET", "v3/{+parent}/models", "translate", "v3", "translate.projects.locations.models.list", "", "filter,pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsOperationsCancel, "POST", "v3/{+name}:cancel", "translate", "v3", "translate.projects.locations.operations.cancel", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kTranslateLocationsOperationsDelete, "DELETE", "v3/{+name}", "translate", "v3", "translate.projects.locations.operations.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kTranslateLocationsOperationsGet, "GET", "v3/{+name}", "translate", "v3", "translate.projects.locations.operations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kTranslateLocationsOperationsList, "GET", "v3/{+name}/operations", "translate", "v3", "translate.projects.locations.operations.list", "", "filter,pageSize,pageToken,returnPartialSuccess", "name", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsOperationsWait, "POST", "v3/{+name}:wait", "translate", "v3", "translate.projects.locations.operations.wait", "timeout", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kTranslateLocationsRefineText, "POST", "v3/{+parent}:refineText", "translate", "v3", "translate.projects.locations.refineText", "refinementEntries,sourceLanguageCode,targetLanguageCode", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsRomanizeText, "POST", "v3/{+parent}:romanizeText", "translate", "v3", "translate.projects.locations.romanizeText", "contents,sourceLanguageCode", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsTranslateDocument, "POST", "v3/{+parent}:translateDocument", "translate", "v3", "translate.projects.locations.translateDocument", "customizedAttribution,documentInputConfig,documentOutputConfig,enableRotationCorrection,enableShadowRemovalNativePdf,glossaryConfig,isTranslateNativePdfOnly,labels,model,sourceLanguageCode,targetLanguageCode", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateLocationsTranslateText, "POST", "v3/{+parent}:translateText", "translate", "v3", "translate.projects.locations.translateText", "contents,glossaryConfig,labels,mimeType,model,sourceLanguageCode,targetLanguageCode,transliterationConfig", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTranslateRomanizeText, "POST", "v3/{+parent}:romanizeText", "translate", "v3", "translate.projects.romanizeText", "contents,sourceLanguageCode", "", "parent", "^projects/[^/]+$"},
|
||||
{Call::kTranslateTranslateText, "POST", "v3/{+parent}:translateText", "translate", "v3", "translate.projects.translateText", "contents,glossaryConfig,labels,mimeType,model,sourceLanguageCode,targetLanguageCode,transliterationConfig", "", "parent", "^projects/[^/]+$"},
|
||||
{Call::kVisionFilesAnnotate, "POST", "v1/files:annotate", "vision", "v1", "vision.files.annotate", "labels,parent,requests", "", "", ""},
|
||||
{Call::kVisionFilesAsyncBatchAnnotate, "POST", "v1/files:asyncBatchAnnotate", "vision", "v1", "vision.files.asyncBatchAnnotate", "labels,parent,requests", "", "", ""},
|
||||
{Call::kVisionImagesAnnotate, "POST", "v1/images:annotate", "vision", "v1", "vision.images.annotate", "labels,parent,requests", "", "", ""},
|
||||
{Call::kVisionImagesAsyncBatchAnnotate, "POST", "v1/images:asyncBatchAnnotate", "vision", "v1", "vision.images.asyncBatchAnnotate", "labels,outputConfig,parent,requests", "", "", ""},
|
||||
{Call::kVisionLocationsOperationsGet, "GET", "v1/{+name}", "vision", "v1", "vision.locations.operations.get", "", "", "name", "^locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kVisionOperationsCancel, "POST", "v1/{+name}:cancel", "vision", "v1", "vision.operations.cancel", "", "", "name", "^operations/.*$"},
|
||||
{Call::kVisionOperationsDelete, "DELETE", "v1/{+name}", "vision", "v1", "vision.operations.delete", "", "", "name", "^operations/.*$"},
|
||||
{Call::kVisionOperationsGet, "GET", "v1/{+name}", "vision", "v1", "vision.operations.get", "", "", "name", "^operations/[^/]+$"},
|
||||
{Call::kVisionOperationsList, "GET", "v1/{+name}", "vision", "v1", "vision.operations.list", "", "filter,pageSize,pageToken,returnPartialSuccess", "name", "^operations$"},
|
||||
{Call::kVisionProjectsFilesAnnotate, "POST", "v1/{+parent}/files:annotate", "vision", "v1", "vision.projects.files.annotate", "labels,parent,requests", "", "parent", "^projects/[^/]+$"},
|
||||
{Call::kVisionProjectsFilesAsyncBatchAnnotate, "POST", "v1/{+parent}/files:asyncBatchAnnotate", "vision", "v1", "vision.projects.files.asyncBatchAnnotate", "labels,parent,requests", "", "parent", "^projects/[^/]+$"},
|
||||
{Call::kVisionProjectsImagesAnnotate, "POST", "v1/{+parent}/images:annotate", "vision", "v1", "vision.projects.images.annotate", "labels,parent,requests", "", "parent", "^projects/[^/]+$"},
|
||||
{Call::kVisionProjectsImagesAsyncBatchAnnotate, "POST", "v1/{+parent}/images:asyncBatchAnnotate", "vision", "v1", "vision.projects.images.asyncBatchAnnotate", "labels,outputConfig,parent,requests", "", "parent", "^projects/[^/]+$"},
|
||||
{Call::kVisionLocationsFilesAnnotate, "POST", "v1/{+parent}/files:annotate", "vision", "v1", "vision.projects.locations.files.annotate", "labels,parent,requests", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsFilesAsyncBatchAnnotate, "POST", "v1/{+parent}/files:asyncBatchAnnotate", "vision", "v1", "vision.projects.locations.files.asyncBatchAnnotate", "labels,parent,requests", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsImagesAnnotate, "POST", "v1/{+parent}/images:annotate", "vision", "v1", "vision.projects.locations.images.annotate", "labels,parent,requests", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsImagesAsyncBatchAnnotate, "POST", "v1/{+parent}/images:asyncBatchAnnotate", "vision", "v1", "vision.projects.locations.images.asyncBatchAnnotate", "labels,outputConfig,parent,requests", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionProjectsLocationsOperationsGet, "GET", "v1/{+name}", "vision", "v1", "vision.projects.locations.operations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsAddProduct, "POST", "v1/{+name}:addProduct", "vision", "v1", "vision.projects.locations.productSets.addProduct", "product", "", "name", "^projects/[^/]+/locations/[^/]+/productSets/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsCreate, "POST", "v1/{+parent}/productSets", "vision", "v1", "vision.projects.locations.productSets.create", "displayName,indexError,indexTime,name", "productSetId", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsDelete, "DELETE", "v1/{+name}", "vision", "v1", "vision.projects.locations.productSets.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/productSets/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsGet, "GET", "v1/{+name}", "vision", "v1", "vision.projects.locations.productSets.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/productSets/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsImport, "POST", "v1/{+parent}/productSets:import", "vision", "v1", "vision.projects.locations.productSets.import", "inputConfig", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsList, "GET", "v1/{+parent}/productSets", "vision", "v1", "vision.projects.locations.productSets.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsPatch, "PATCH", "v1/{+name}", "vision", "v1", "vision.projects.locations.productSets.patch", "displayName,indexError,indexTime,name", "updateMask", "name", "^projects/[^/]+/locations/[^/]+/productSets/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsProductsList, "GET", "v1/{+name}/products", "vision", "v1", "vision.projects.locations.productSets.products.list", "", "pageSize,pageToken", "name", "^projects/[^/]+/locations/[^/]+/productSets/[^/]+$"},
|
||||
{Call::kVisionLocationsProductSetsRemoveProduct, "POST", "v1/{+name}:removeProduct", "vision", "v1", "vision.projects.locations.productSets.removeProduct", "product", "", "name", "^projects/[^/]+/locations/[^/]+/productSets/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsCreate, "POST", "v1/{+parent}/products", "vision", "v1", "vision.projects.locations.products.create", "description,displayName,name,productCategory,productLabels", "productId", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsDelete, "DELETE", "v1/{+name}", "vision", "v1", "vision.projects.locations.products.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/products/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsGet, "GET", "v1/{+name}", "vision", "v1", "vision.projects.locations.products.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/products/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsList, "GET", "v1/{+parent}/products", "vision", "v1", "vision.projects.locations.products.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsPatch, "PATCH", "v1/{+name}", "vision", "v1", "vision.projects.locations.products.patch", "description,displayName,name,productCategory,productLabels", "updateMask", "name", "^projects/[^/]+/locations/[^/]+/products/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsPurge, "POST", "v1/{+parent}/products:purge", "vision", "v1", "vision.projects.locations.products.purge", "deleteOrphanProducts,force,productSetPurgeConfig", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsReferenceImagesCreate, "POST", "v1/{+parent}/referenceImages", "vision", "v1", "vision.projects.locations.products.referenceImages.create", "boundingPolys,name,uri", "referenceImageId", "parent", "^projects/[^/]+/locations/[^/]+/products/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsReferenceImagesDelete, "DELETE", "v1/{+name}", "vision", "v1", "vision.projects.locations.products.referenceImages.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/products/[^/]+/referenceImages/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsReferenceImagesGet, "GET", "v1/{+name}", "vision", "v1", "vision.projects.locations.products.referenceImages.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/products/[^/]+/referenceImages/[^/]+$"},
|
||||
{Call::kVisionLocationsProductsReferenceImagesList, "GET", "v1/{+parent}/referenceImages", "vision", "v1", "vision.projects.locations.products.referenceImages.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/products/[^/]+$"},
|
||||
{Call::kVisionProjectsOperationsGet, "GET", "v1/{+name}", "vision", "v1", "vision.projects.operations.get", "", "", "name", "^projects/[^/]+/operations/[^/]+$"},
|
||||
{Call::kLanguageDocumentsAnalyzeEntities, "POST", "v2/documents:analyzeEntities", "language", "v2", "language.documents.analyzeEntities", "document,encodingType", "", "", ""},
|
||||
{Call::kLanguageDocumentsAnalyzeSentiment, "POST", "v2/documents:analyzeSentiment", "language", "v2", "language.documents.analyzeSentiment", "document,encodingType", "", "", ""},
|
||||
{Call::kLanguageDocumentsAnnotateText, "POST", "v2/documents:annotateText", "language", "v2", "language.documents.annotateText", "document,encodingType,features", "", "", ""},
|
||||
{Call::kLanguageDocumentsClassifyText, "POST", "v2/documents:classifyText", "language", "v2", "language.documents.classifyText", "document", "", "", ""},
|
||||
{Call::kLanguageDocumentsModerateText, "POST", "v2/documents:moderateText", "language", "v2", "language.documents.moderateText", "document,modelVersion", "", "", ""},
|
||||
{Call::kLanguageV1DocumentsAnalyzeEntitySentiment, "POST", "v1/documents:analyzeEntitySentiment", "language", "v1", "language.documents.analyzeEntitySentiment", "document,encodingType", "", "", ""},
|
||||
{Call::kLanguageV1DocumentsAnalyzeSyntax, "POST", "v1/documents:analyzeSyntax", "language", "v1", "language.documents.analyzeSyntax", "document,encodingType", "", "", ""},
|
||||
{Call::kVideoLocationsOperationsCancel, "POST", "v1/{+name}:cancel", "videointelligence", "v1", "videointelligence.projects.locations.operations.cancel", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kVideoLocationsOperationsDelete, "DELETE", "v1/{+name}", "videointelligence", "v1", "videointelligence.projects.locations.operations.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kVideoLocationsOperationsGet, "GET", "v1/{+name}", "videointelligence", "v1", "videointelligence.projects.locations.operations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kVideoLocationsOperationsList, "GET", "v1/{+name}/operations", "videointelligence", "v1", "videointelligence.projects.locations.operations.list", "", "filter,pageSize,pageToken,returnPartialSuccess", "name", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kVideoVideosAnnotate, "POST", "v1/videos:annotate", "videointelligence", "v1", "videointelligence.videos.annotate", "features,inputContent,inputUri,locationId,outputUri,videoContext", "", "", ""},
|
||||
{Call::kDocumentaiOperationsDelete, "DELETE", "v1/{+name}", "documentai", "v1", "documentai.operations.delete", "", "", "name", "^operations/.*$"},
|
||||
{Call::kDocumentaiLocationsFetchProcessorTypes, "GET", "v1/{+parent}:fetchProcessorTypes", "documentai", "v1", "documentai.projects.locations.fetchProcessorTypes", "", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsList, "GET", "v1/{+name}/locations", "documentai", "v1", "documentai.projects.locations.list", "", "extraLocationTypes,filter,pageSize,pageToken", "name", "^projects/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsOperationsCancel, "POST", "v1/{+name}:cancel", "documentai", "v1", "documentai.projects.locations.operations.cancel", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsOperationsGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.operations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsOperationsList, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.operations.list", "", "filter,pageSize,pageToken,returnPartialSuccess", "name", "^projects/[^/]+/locations/[^/]+/operations$"},
|
||||
{Call::kDocumentaiLocationsProcessorTypesGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.processorTypes.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/processorTypes/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorTypesList, "GET", "v1/{+parent}/processorTypes", "documentai", "v1", "documentai.projects.locations.processorTypes.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsBatchProcess, "POST", "v1/{+name}:batchProcess", "documentai", "v1", "documentai.projects.locations.processors.batchProcess", "documentOutputConfig,inputDocuments,labels,processOptions,skipHumanReview", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsCreate, "POST", "v1/{+parent}/processors", "documentai", "v1", "documentai.projects.locations.processors.create", "activeSchemaVersion,createTime,defaultProcessorVersion,displayName,kmsKeyName,name,processEndpoint,processorVersionAliases,satisfiesPzi,satisfiesPzs,state,type", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsDelete, "DELETE", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.processors.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsDisable, "POST", "v1/{+name}:disable", "documentai", "v1", "documentai.projects.locations.processors.disable", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsEnable, "POST", "v1/{+name}:enable", "documentai", "v1", "documentai.projects.locations.processors.enable", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.processors.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsHumanReviewConfigReviewDocument, "POST", "v1/{+humanReviewConfig}:reviewDocument", "documentai", "v1", "documentai.projects.locations.processors.humanReviewConfig.reviewDocument", "documentSchema,enableSchemaValidation,inlineDocument,priority", "", "humanReviewConfig", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/humanReviewConfig$"},
|
||||
{Call::kDocumentaiLocationsProcessorsList, "GET", "v1/{+parent}/processors", "documentai", "v1", "documentai.projects.locations.processors.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcess, "POST", "v1/{+name}:process", "documentai", "v1", "documentai.projects.locations.processors.process", "fieldMask,gcsDocument,imagelessMode,inlineDocument,labels,processOptions,rawDocument,skipHumanReview", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsBatchProcess, "POST", "v1/{+name}:batchProcess", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.batchProcess", "documentOutputConfig,inputDocuments,labels,processOptions,skipHumanReview", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsDelete, "DELETE", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsDeploy, "POST", "v1/{+name}:deploy", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.deploy", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsEvaluateProcessorVersion, "POST", "v1/{+processorVersion}:evaluateProcessorVersion", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.evaluateProcessorVersion", "evaluationDocuments", "", "processorVersion", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsEvaluationsGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.evaluations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+/evaluations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsEvaluationsList, "GET", "v1/{+parent}/evaluations", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.evaluations.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsList, "GET", "v1/{+parent}/processorVersions", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsProcess, "POST", "v1/{+name}:process", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.process", "fieldMask,gcsDocument,imagelessMode,inlineDocument,labels,processOptions,rawDocument,skipHumanReview", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsTrain, "POST", "v1/{+parent}/processorVersions:train", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.train", "baseProcessorVersion,customDocumentExtractionOptions,documentSchema,foundationModelTuningOptions,inputData,processorVersion", "", "parent", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsProcessorVersionsUndeploy, "POST", "v1/{+name}:undeploy", "documentai", "v1", "documentai.projects.locations.processors.processorVersions.undeploy", "", "", "name", "^projects/[^/]+/locations/[^/]+/processors/[^/]+/processorVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsProcessorsSetDefaultProcessorVersion, "POST", "v1/{+processor}:setDefaultProcessorVersion", "documentai", "v1", "documentai.projects.locations.processors.setDefaultProcessorVersion", "defaultProcessorVersion", "", "processor", "^projects/[^/]+/locations/[^/]+/processors/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasCreate, "POST", "v1/{+parent}/schemas", "documentai", "v1", "documentai.projects.locations.schemas.create", "createTime,displayName,labels,name,updateTime", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasDelete, "DELETE", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.schemas.delete", "", "force", "name", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.schemas.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasList, "GET", "v1/{+parent}/schemas", "documentai", "v1", "documentai.projects.locations.schemas.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasPatch, "PATCH", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.schemas.patch", "createTime,displayName,labels,name,updateTime", "updateMask", "name", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasSchemaVersionsCreate, "POST", "v1/{+parent}/schemaVersions", "documentai", "v1", "documentai.projects.locations.schemas.schemaVersions.create", "createTime,displayName,labels,name,schema", "", "parent", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasSchemaVersionsDelete, "DELETE", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.schemas.schemaVersions.delete", "", "", "name", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+/schemaVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasSchemaVersionsGenerate, "POST", "v1/{+parent}/schemaVersions:generate", "documentai", "v1", "documentai.projects.locations.schemas.schemaVersions.generate", "baseSchemaVersion,gcsDocuments,gcsPrefix,generateSchemaVersionParams,inlineDocuments,rawDocuments", "", "parent", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasSchemaVersionsGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.schemas.schemaVersions.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+/schemaVersions/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasSchemaVersionsList, "GET", "v1/{+parent}/schemaVersions", "documentai", "v1", "documentai.projects.locations.schemas.schemaVersions.list", "", "pageSize,pageToken", "parent", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+$"},
|
||||
{Call::kDocumentaiLocationsSchemasSchemaVersionsPatch, "PATCH", "v1/{+name}", "documentai", "v1", "documentai.projects.locations.schemas.schemaVersions.patch", "createTime,displayName,labels,name,schema", "updateMask", "name", "^projects/[^/]+/locations/[^/]+/schemas/[^/]+/schemaVersions/[^/]+$"},
|
||||
{Call::kDocumentaiOperationsGet, "GET", "v1/{+name}", "documentai", "v1", "documentai.projects.operations.get", "", "", "name", "^projects/[^/]+/operations/[^/]+$"},
|
||||
{Call::kSpeechLocationsConfigGet, "GET", "v2/{+name}", "speech", "v2", "speech.projects.locations.config.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/config$"},
|
||||
{Call::kSpeechLocationsConfigUpdate, "PATCH", "v2/{+name}", "speech", "v2", "speech.projects.locations.config.update", "kmsKeyName,name,updateTime", "updateMask", "name", "^projects/[^/]+/locations/[^/]+/config$"},
|
||||
{Call::kSpeechLocationsCustomClassesCreate, "POST", "v2/{+parent}/customClasses", "speech", "v2", "speech.projects.locations.customClasses.create", "annotations,createTime,deleteTime,displayName,etag,expireTime,items,kmsKeyName,kmsKeyVersionName,name,reconciling,state,uid,updateTime", "customClassId,validateOnly", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsCustomClassesDelete, "DELETE", "v2/{+name}", "speech", "v2", "speech.projects.locations.customClasses.delete", "", "allowMissing,etag,validateOnly", "name", "^projects/[^/]+/locations/[^/]+/customClasses/[^/]+$"},
|
||||
{Call::kSpeechLocationsCustomClassesGet, "GET", "v2/{+name}", "speech", "v2", "speech.projects.locations.customClasses.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/customClasses/[^/]+$"},
|
||||
{Call::kSpeechLocationsCustomClassesList, "GET", "v2/{+parent}/customClasses", "speech", "v2", "speech.projects.locations.customClasses.list", "", "pageSize,pageToken,showDeleted", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsCustomClassesPatch, "PATCH", "v2/{+name}", "speech", "v2", "speech.projects.locations.customClasses.patch", "annotations,createTime,deleteTime,displayName,etag,expireTime,items,kmsKeyName,kmsKeyVersionName,name,reconciling,state,uid,updateTime", "updateMask,validateOnly", "name", "^projects/[^/]+/locations/[^/]+/customClasses/[^/]+$"},
|
||||
{Call::kSpeechLocationsCustomClassesUndelete, "POST", "v2/{+name}:undelete", "speech", "v2", "speech.projects.locations.customClasses.undelete", "etag,name,validateOnly", "", "name", "^projects/[^/]+/locations/[^/]+/customClasses/[^/]+$"},
|
||||
{Call::kSpeechLocationsGet, "GET", "v2/{+name}", "speech", "v2", "speech.projects.locations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsList, "GET", "v2/{+name}/locations", "speech", "v2", "speech.projects.locations.list", "", "extraLocationTypes,filter,pageSize,pageToken", "name", "^projects/[^/]+$"},
|
||||
{Call::kSpeechLocationsOperationsGet, "GET", "v2/{+name}", "speech", "v2", "speech.projects.locations.operations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kSpeechLocationsOperationsList, "GET", "v2/{+name}/operations", "speech", "v2", "speech.projects.locations.operations.list", "", "filter,pageSize,pageToken,returnPartialSuccess", "name", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsPhraseSetsCreate, "POST", "v2/{+parent}/phraseSets", "speech", "v2", "speech.projects.locations.phraseSets.create", "annotations,boost,createTime,deleteTime,displayName,etag,expireTime,kmsKeyName,kmsKeyVersionName,name,phrases,reconciling,state,uid,updateTime", "phraseSetId,validateOnly", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsPhraseSetsDelete, "DELETE", "v2/{+name}", "speech", "v2", "speech.projects.locations.phraseSets.delete", "", "allowMissing,etag,validateOnly", "name", "^projects/[^/]+/locations/[^/]+/phraseSets/[^/]+$"},
|
||||
{Call::kSpeechLocationsPhraseSetsGet, "GET", "v2/{+name}", "speech", "v2", "speech.projects.locations.phraseSets.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/phraseSets/[^/]+$"},
|
||||
{Call::kSpeechLocationsPhraseSetsList, "GET", "v2/{+parent}/phraseSets", "speech", "v2", "speech.projects.locations.phraseSets.list", "", "pageSize,pageToken,showDeleted", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsPhraseSetsPatch, "PATCH", "v2/{+name}", "speech", "v2", "speech.projects.locations.phraseSets.patch", "annotations,boost,createTime,deleteTime,displayName,etag,expireTime,kmsKeyName,kmsKeyVersionName,name,phrases,reconciling,state,uid,updateTime", "updateMask,validateOnly", "name", "^projects/[^/]+/locations/[^/]+/phraseSets/[^/]+$"},
|
||||
{Call::kSpeechLocationsPhraseSetsUndelete, "POST", "v2/{+name}:undelete", "speech", "v2", "speech.projects.locations.phraseSets.undelete", "etag,name,validateOnly", "", "name", "^projects/[^/]+/locations/[^/]+/phraseSets/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersBatchRecognize, "POST", "v2/{+recognizer}:batchRecognize", "speech", "v2", "speech.projects.locations.recognizers.batchRecognize", "config,configMask,files,processingStrategy,recognitionOutputConfig,recognizer", "", "recognizer", "^projects/[^/]+/locations/[^/]+/recognizers/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersCreate, "POST", "v2/{+parent}/recognizers", "speech", "v2", "speech.projects.locations.recognizers.create", "annotations,createTime,defaultRecognitionConfig,deleteTime,displayName,etag,expireTime,kmsKeyName,kmsKeyVersionName,languageCodes,model,name,reconciling,state,uid,updateTime", "recognizerId,validateOnly", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersDelete, "DELETE", "v2/{+name}", "speech", "v2", "speech.projects.locations.recognizers.delete", "", "allowMissing,etag,validateOnly", "name", "^projects/[^/]+/locations/[^/]+/recognizers/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersGet, "GET", "v2/{+name}", "speech", "v2", "speech.projects.locations.recognizers.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/recognizers/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersList, "GET", "v2/{+parent}/recognizers", "speech", "v2", "speech.projects.locations.recognizers.list", "", "pageSize,pageToken,showDeleted", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersPatch, "PATCH", "v2/{+name}", "speech", "v2", "speech.projects.locations.recognizers.patch", "annotations,createTime,defaultRecognitionConfig,deleteTime,displayName,etag,expireTime,kmsKeyName,kmsKeyVersionName,languageCodes,model,name,reconciling,state,uid,updateTime", "updateMask,validateOnly", "name", "^projects/[^/]+/locations/[^/]+/recognizers/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersRecognize, "POST", "v2/{+recognizer}:recognize", "speech", "v2", "speech.projects.locations.recognizers.recognize", "config,configMask,content,uri", "", "recognizer", "^projects/[^/]+/locations/[^/]+/recognizers/[^/]+$"},
|
||||
{Call::kSpeechLocationsRecognizersUndelete, "POST", "v2/{+name}:undelete", "speech", "v2", "speech.projects.locations.recognizers.undelete", "etag,name,validateOnly", "", "name", "^projects/[^/]+/locations/[^/]+/recognizers/[^/]+$"},
|
||||
{Call::kTtsOperationsCancel, "POST", "v1/{+name}:cancel", "texttospeech", "v1", "texttospeech.operations.cancel", "", "", "name", "^operations/.*$"},
|
||||
{Call::kTtsOperationsDelete, "DELETE", "v1/{+name}", "texttospeech", "v1", "texttospeech.operations.delete", "", "", "name", "^operations/.*$"},
|
||||
{Call::kTtsLocationsOperationsGet, "GET", "v1/{+name}", "texttospeech", "v1", "texttospeech.projects.locations.operations.get", "", "", "name", "^projects/[^/]+/locations/[^/]+/operations/[^/]+$"},
|
||||
{Call::kTtsLocationsOperationsList, "GET", "v1/{+name}/operations", "texttospeech", "v1", "texttospeech.projects.locations.operations.list", "", "filter,pageSize,pageToken,returnPartialSuccess", "name", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTtsLocationsSynthesizeLongAudio, "POST", "v1/{+parent}:synthesizeLongAudio", "texttospeech", "v1", "texttospeech.projects.locations.synthesizeLongAudio", "audioConfig,input,outputGcsUri,voice", "", "parent", "^projects/[^/]+/locations/[^/]+$"},
|
||||
{Call::kTtsTextSynthesize, "POST", "v1/text:synthesize", "texttospeech", "v1", "texttospeech.text.synthesize", "advancedVoiceOptions,audioConfig,input,voice", "", "", ""},
|
||||
{Call::kTtsVoicesList, "GET", "v1/voices", "texttospeech", "v1", "texttospeech.voices.list", "", "languageCode", "", ""},
|
||||
// CALLS-END
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
// Static ceilings for the cloudai package. Never autotuned.
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct CloudAiCaps {
|
||||
static constexpr std::size_t kMaxNameChars = 512; // a resource name
|
||||
static constexpr std::size_t kMaxSegmentChars = 128; // one path segment
|
||||
static constexpr std::size_t kMaxBodyBytes = 16 * 1024 * 1024; // serialized request
|
||||
static constexpr std::size_t kMaxQueryParams = 20;
|
||||
static constexpr std::size_t kMaxQueryValueChars = 2048;
|
||||
static constexpr std::size_t kMaxListPages = 20;
|
||||
static constexpr std::size_t kPageSize = 50;
|
||||
static constexpr std::size_t kMaxTexts = 1024; // contents per translate call
|
||||
static constexpr std::size_t kMaxTextChars = 30000; // Translation v3: 30k code points per request
|
||||
static constexpr std::size_t kMaxNlTextChars = 1000000; // Natural Language document content
|
||||
static constexpr std::size_t kMaxImages = 16; // images per annotate batch (Vision limit)
|
||||
static constexpr std::size_t kMaxFeatures = 16;
|
||||
static constexpr int kMaxResults = 100; // maxResults per feature
|
||||
static constexpr std::size_t kMaxUriChars = 1024;
|
||||
static constexpr std::size_t kMaxIdChars = 63; // resource ids (glossary, processor, recognizer)
|
||||
static constexpr std::size_t kMaxDisplayChars = 128;
|
||||
static constexpr std::size_t kMaxLanguageCodeChars = 35;
|
||||
static constexpr std::size_t kMaxLongAudioChars = 1000000; // long audio input text, bytes
|
||||
static constexpr std::size_t kMaxAudioBytes = 10 * 1024 * 1024; // inline audio / document bytes
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,87 @@
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
CloudAiService::CloudAiService(std::shared_ptr<GoogleClient> client, CloudContext context,
|
||||
Sleeper sleeper)
|
||||
: Service(std::move(client), ServiceEndpoint{"cloudai", ""}),
|
||||
context_(std::move(context)),
|
||||
sleeper_(std::move(sleeper)) {}
|
||||
|
||||
Json CloudAiService::invoke(Call call, const std::string& name, const Json* body,
|
||||
const Query& query) const {
|
||||
std::string path = render(call, name) + query_of(call, query);
|
||||
check_body(call, body);
|
||||
return client_->request(method_of(call), endpoint_of(call, name), path, body);
|
||||
}
|
||||
|
||||
Json CloudAiService::list(Call call, const std::string& name, const std::string& items_key,
|
||||
Query query) const {
|
||||
query.emplace_back("pageSize", std::to_string(CloudAiCaps::kPageSize));
|
||||
std::string path = render(call, name) + query_of(call, query);
|
||||
return list_all(*client_, endpoint_of(call, name), path, items_key, CloudAiCaps::kMaxListPages);
|
||||
}
|
||||
|
||||
Operation CloudAiService::start(Call call, const std::string& name, const Json* body,
|
||||
const Query& query) const {
|
||||
Json reply = invoke(call, name, body, query);
|
||||
Operation op = Operation::from_json(reply);
|
||||
if (op.name.empty() && !op.done) throw GoogleError(502, "BAD_RESPONSE", "no operation in reply", "cloudai");
|
||||
return op;
|
||||
}
|
||||
|
||||
Operation CloudAiService::operation(Call get_call, const std::string& operation_name) const {
|
||||
return Operation::from_json(invoke(get_call, operation_name));
|
||||
}
|
||||
|
||||
Operation CloudAiService::wait(Call get_call, const std::string& operation_name) const {
|
||||
std::string path = render(get_call, operation_name); // validates the name
|
||||
(void)path;
|
||||
return wait_operation(*client_, endpoint_of(get_call, operation_name), operation_name, sleeper_);
|
||||
}
|
||||
|
||||
std::string CloudAiService::project() const {
|
||||
std::string p = context_.parent(); // validates the project
|
||||
return p.substr(0, p.find("/locations/"));
|
||||
}
|
||||
|
||||
std::string checked_language_code(const std::string& code, const char* what) {
|
||||
if (code.empty() || code.size() > CloudAiCaps::kMaxLanguageCodeChars)
|
||||
throw GoogleError::invalid(std::string(what) + " must be a language code (1..35 chars)");
|
||||
for (char c : code)
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '-'))
|
||||
throw GoogleError::invalid(std::string(what) + " has characters outside A-Z a-z 0-9 -");
|
||||
return code;
|
||||
}
|
||||
|
||||
std::string checked_id(const std::string& id, const char* what) {
|
||||
if (id.empty() || id.size() > CloudAiCaps::kMaxIdChars || !valid_name_segment(id))
|
||||
throw GoogleError::invalid(std::string(what) + " must be 1..63 chars of A-Z a-z 0-9 . _ - ~");
|
||||
return id;
|
||||
}
|
||||
|
||||
std::string checked_gcs_uri(const std::string& uri, const char* what) {
|
||||
if (uri.rfind("gs://", 0) != 0 || uri.size() <= 5 || uri.size() > CloudAiCaps::kMaxUriChars)
|
||||
throw GoogleError::invalid(std::string(what) + " must be a gs:// URI");
|
||||
for (char c : uri)
|
||||
if (static_cast<unsigned char>(c) <= 0x20 || c == '"' || c == '\\')
|
||||
throw GoogleError::invalid(std::string(what) + " has illegal characters");
|
||||
return uri;
|
||||
}
|
||||
|
||||
std::string checked_https_or_gcs_uri(const std::string& uri, const char* what) {
|
||||
if (uri.rfind("gs://", 0) == 0) return checked_gcs_uri(uri, what);
|
||||
if (uri.rfind("https://", 0) != 0 || uri.size() <= 8 || uri.size() > CloudAiCaps::kMaxUriChars)
|
||||
throw GoogleError::invalid(std::string(what) + " must be a gs:// or https:// URI");
|
||||
for (char c : uri)
|
||||
if (static_cast<unsigned char>(c) <= 0x20 || c == '"' || c == '\\')
|
||||
throw GoogleError::invalid(std::string(what) + " has illegal characters");
|
||||
return uri;
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
// Base of every cloudai API class: runs one row of the call table through the
|
||||
// shared GoogleClient. Validation (resource name against the Discovery
|
||||
// pattern, request fields, query parameters, sizes) happens before any
|
||||
// network traffic and before the credential check.
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "google/cloudai/calls.h"
|
||||
#include "google/operation.h"
|
||||
#include "google/resource.h"
|
||||
#include "google/service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
class CloudAiService : public Service {
|
||||
public:
|
||||
CloudAiService(std::shared_ptr<GoogleClient> client, CloudContext context,
|
||||
Sleeper sleeper = nullptr);
|
||||
|
||||
const CloudContext& context() const { return context_; }
|
||||
|
||||
// One call of the table. `name` fills the row's path variable. Throws
|
||||
// GoogleError::invalid for bad input, NotConfiguredError without a credential.
|
||||
clients::body::Json invoke(Call call, const std::string& name = "",
|
||||
const clients::body::Json* body = nullptr,
|
||||
const Query& query = {}) const;
|
||||
|
||||
// Follows nextPageToken (capped) on a list row and collects `items_key`.
|
||||
clients::body::Json list(Call call, const std::string& name, const std::string& items_key,
|
||||
Query query = {}) const;
|
||||
|
||||
// A row that starts a long-running operation: answers it, never waits.
|
||||
Operation start(Call call, const std::string& name, const clients::body::Json* body = nullptr,
|
||||
const Query& query = {}) const;
|
||||
|
||||
// GET the operation by its full name through `get_call` (the family's
|
||||
// operations.get row).
|
||||
Operation operation(Call get_call, const std::string& operation_name) const;
|
||||
|
||||
// Polls until done (hard caps in OperationCaps). Throws on failure.
|
||||
Operation wait(Call get_call, const std::string& operation_name) const;
|
||||
|
||||
// "projects/{project}/locations/{location}" of the context.
|
||||
std::string parent() const { return context_.parent(); }
|
||||
// "projects/{project}" only.
|
||||
std::string project() const;
|
||||
|
||||
protected:
|
||||
CloudContext context_;
|
||||
Sleeper sleeper_;
|
||||
};
|
||||
|
||||
// Shared input checks for the typed classes. All throw GoogleError::invalid.
|
||||
std::string checked_language_code(const std::string& code, const char* what);
|
||||
std::string checked_id(const std::string& id, const char* what); // resource id, 1..63 [A-Za-z0-9._-]
|
||||
std::string checked_gcs_uri(const std::string& uri, const char* what);
|
||||
std::string checked_https_or_gcs_uri(const std::string& uri, const char* what);
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,125 @@
|
||||
#include "google/cloudai/document_ai.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
namespace {
|
||||
bool mime_ok(const std::string& m) {
|
||||
for (const char* ok : {"application/pdf", "image/png", "image/jpeg", "image/tiff", "image/gif",
|
||||
"image/bmp", "image/webp", "text/html"})
|
||||
if (m == ok) return true;
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string DocumentAi::processor_name(const std::string& id) const {
|
||||
return context_.child("processors", checked_id(id, "processor id"));
|
||||
}
|
||||
|
||||
std::string DocumentAi::process_target(const ProcessRequest& r) const {
|
||||
std::string name = processor_name(r.processor_id);
|
||||
if (!r.version_id.empty()) name += "/processorVersions/" + checked_id(r.version_id, "version id");
|
||||
return name;
|
||||
}
|
||||
|
||||
Json DocumentAi::process_body(const ProcessRequest& r) const {
|
||||
if (!mime_ok(r.mime_type))
|
||||
throw GoogleError::invalid("mimeType must be application/pdf, image/png, image/jpeg, image/tiff, image/gif, image/bmp, image/webp or text/html");
|
||||
Json b = Json::object();
|
||||
if (!r.gcs_uri.empty()) {
|
||||
if (!r.content_base64.empty()) throw GoogleError::invalid("give content or gcsUri, not both");
|
||||
Json g = Json::object();
|
||||
g.set("gcsUri", Json(checked_gcs_uri(r.gcs_uri, "gcsUri")));
|
||||
g.set("mimeType", Json(r.mime_type));
|
||||
b.set("gcsDocument", g);
|
||||
} else {
|
||||
if (r.content_base64.empty()) throw GoogleError::invalid("content or gcsUri is required");
|
||||
if (r.content_base64.size() / 4 * 3 > CloudAiCaps::kMaxAudioBytes)
|
||||
throw GoogleError::invalid("document over 10 MiB");
|
||||
for (char c : r.content_base64)
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '+' ||
|
||||
c == '/' || c == '=' || c == '-' || c == '_'))
|
||||
throw GoogleError::invalid("content is not base64");
|
||||
Json raw = Json::object();
|
||||
raw.set("content", Json(r.content_base64));
|
||||
raw.set("mimeType", Json(r.mime_type));
|
||||
b.set("rawDocument", raw);
|
||||
}
|
||||
b.set("skipHumanReview", Json(r.skip_human_review));
|
||||
if (!r.field_mask.empty()) {
|
||||
if (r.field_mask.size() > 512) throw GoogleError::invalid("fieldMask too long");
|
||||
b.set("fieldMask", Json(r.field_mask));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
Json DocumentAi::process(const ProcessRequest& r) const {
|
||||
Json b = process_body(r);
|
||||
return invoke(r.version_id.empty() ? Call::kDocumentaiLocationsProcessorsProcess
|
||||
: Call::kDocumentaiLocationsProcessorsProcessorVersionsProcess,
|
||||
process_target(r), &b);
|
||||
}
|
||||
|
||||
Json DocumentAi::list_processor_types() const {
|
||||
return list(Call::kDocumentaiLocationsProcessorTypesList, parent(), "processorTypes");
|
||||
}
|
||||
Json DocumentAi::fetch_processor_types() const {
|
||||
return invoke(Call::kDocumentaiLocationsFetchProcessorTypes, parent());
|
||||
}
|
||||
Json DocumentAi::list_processors() const {
|
||||
return list(Call::kDocumentaiLocationsProcessorsList, parent(), "processors");
|
||||
}
|
||||
Json DocumentAi::get_processor(const std::string& id) const {
|
||||
return invoke(Call::kDocumentaiLocationsProcessorsGet, processor_name(id));
|
||||
}
|
||||
Json DocumentAi::list_versions(const std::string& processor_id) const {
|
||||
return list(Call::kDocumentaiLocationsProcessorsProcessorVersionsList, processor_name(processor_id),
|
||||
"processorVersions");
|
||||
}
|
||||
Json DocumentAi::list_schemas() const {
|
||||
return list(Call::kDocumentaiLocationsSchemasList, parent(), "schemas");
|
||||
}
|
||||
Json DocumentAi::list_locations() const {
|
||||
return list(Call::kDocumentaiLocationsList, project(), "locations");
|
||||
}
|
||||
Operation DocumentAi::get_operation(const std::string& name) const {
|
||||
return operation(Call::kDocumentaiLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
Json DocumentAi::create_processor(const std::string& display_name, const std::string& type) const {
|
||||
if (display_name.empty() || display_name.size() > CloudAiCaps::kMaxDisplayChars)
|
||||
throw GoogleError::invalid("displayName: 1..128 chars");
|
||||
if (type.empty() || type.size() > 64) throw GoogleError::invalid("type: 1..64 chars");
|
||||
for (char c : type)
|
||||
if (!((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'))
|
||||
throw GoogleError::invalid("type looks like FORM_PARSER_PROCESSOR");
|
||||
Json b = Json::object();
|
||||
b.set("displayName", Json(display_name));
|
||||
b.set("type", Json(type));
|
||||
return invoke(Call::kDocumentaiLocationsProcessorsCreate, parent(), &b);
|
||||
}
|
||||
Operation DocumentAi::delete_processor_start(const std::string& id) const {
|
||||
return start(Call::kDocumentaiLocationsProcessorsDelete, processor_name(id));
|
||||
}
|
||||
Operation DocumentAi::enable_processor_start(const std::string& id) const {
|
||||
return start(Call::kDocumentaiLocationsProcessorsEnable, processor_name(id));
|
||||
}
|
||||
Operation DocumentAi::disable_processor_start(const std::string& id) const {
|
||||
return start(Call::kDocumentaiLocationsProcessorsDisable, processor_name(id));
|
||||
}
|
||||
Operation DocumentAi::batch_process_start(const std::string& processor_id, const Json& body) const {
|
||||
return start(Call::kDocumentaiLocationsProcessorsBatchProcess, processor_name(processor_id), &body);
|
||||
}
|
||||
|
||||
Json DocumentAi::call(Call c, const std::string& name, const Json* body, const Query& query) const {
|
||||
if (std::strcmp(spec(c).api, "documentai") != 0) throw GoogleError::invalid("not a Document AI call");
|
||||
return invoke(c, name, body, query);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
// Document AI v1: processor types, processors, versions, schemas, online
|
||||
// process, batch process start. Locations "us" and "eu" use their regional
|
||||
// hosts. Process is paid per page.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct ProcessRequest {
|
||||
std::string processor_id; // processor id (hex) under the context location
|
||||
std::string version_id; // optional processor version id
|
||||
std::string content_base64; // raw document bytes, base64 (at most 10 MiB decoded)
|
||||
std::string gcs_uri; // alternative: gs:// document
|
||||
std::string mime_type; // application/pdf, image/png, ...
|
||||
bool skip_human_review = true;
|
||||
std::string field_mask; // optional, e.g. "text,entities"
|
||||
};
|
||||
|
||||
class DocumentAi : public CloudAiService {
|
||||
public:
|
||||
using CloudAiService::CloudAiService;
|
||||
|
||||
std::string processor_name(const std::string& id) const;
|
||||
std::string process_target(const ProcessRequest& r) const;
|
||||
clients::body::Json process_body(const ProcessRequest& r) const;
|
||||
// Paid. Online (sync) process.
|
||||
clients::body::Json process(const ProcessRequest& r) const;
|
||||
|
||||
// Reads.
|
||||
clients::body::Json list_processor_types() const;
|
||||
clients::body::Json fetch_processor_types() const;
|
||||
clients::body::Json list_processors() const;
|
||||
clients::body::Json get_processor(const std::string& id) const;
|
||||
clients::body::Json list_versions(const std::string& processor_id) const;
|
||||
clients::body::Json list_schemas() const;
|
||||
clients::body::Json list_locations() const;
|
||||
Operation get_operation(const std::string& name) const;
|
||||
|
||||
// Writes: explicit, no defaults.
|
||||
clients::body::Json create_processor(const std::string& display_name, const std::string& type) const;
|
||||
Operation delete_processor_start(const std::string& id) const;
|
||||
Operation enable_processor_start(const std::string& id) const;
|
||||
Operation disable_processor_start(const std::string& id) const;
|
||||
// Batch process from a prepared body (inputDocuments, documentOutputConfig); paid.
|
||||
Operation batch_process_start(const std::string& processor_id, const clients::body::Json& body) const;
|
||||
|
||||
clients::body::Json call(Call c, const std::string& name, const clients::body::Json* body = nullptr,
|
||||
const Query& query = {}) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,56 @@
|
||||
#include "google/cloudai/long_audio.h"
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
Json LongAudio::request_body(const LongAudioRequest& r) const {
|
||||
if (r.text.empty()) throw GoogleError::invalid("text is empty");
|
||||
if (r.text.size() > CloudAiCaps::kMaxLongAudioChars) throw GoogleError::invalid("text over 1,000,000 bytes");
|
||||
if (!valid_enum("AudioConfig.audioEncoding", r.encoding)) throw GoogleError::invalid("unknown audioEncoding");
|
||||
Json in = Json::object();
|
||||
in.set(r.ssml ? "ssml" : "text", Json(r.text));
|
||||
Json voice = Json::object();
|
||||
voice.set("languageCode", Json(checked_language_code(r.language, "language")));
|
||||
if (!r.voice_name.empty()) {
|
||||
if (r.voice_name.size() > 128 || !valid_name_segment(r.voice_name))
|
||||
throw GoogleError::invalid("voice name has illegal characters");
|
||||
voice.set("name", Json(r.voice_name));
|
||||
}
|
||||
Json audio = Json::object();
|
||||
audio.set("audioEncoding", Json(r.encoding));
|
||||
Json b = Json::object();
|
||||
b.set("input", in);
|
||||
b.set("voice", voice);
|
||||
b.set("audioConfig", audio);
|
||||
b.set("outputGcsUri", Json(checked_gcs_uri(r.output_uri, "outputUri")));
|
||||
return b;
|
||||
}
|
||||
|
||||
Operation LongAudio::synthesize_start(const LongAudioRequest& r) const {
|
||||
Json b = request_body(r);
|
||||
return start(Call::kTtsLocationsSynthesizeLongAudio, parent(), &b);
|
||||
}
|
||||
|
||||
Operation LongAudio::get_operation(const std::string& name) const {
|
||||
return operation(Call::kTtsLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
Json LongAudio::list_operations() const {
|
||||
return list(Call::kTtsLocationsOperationsList, parent(), "operations");
|
||||
}
|
||||
|
||||
Json LongAudio::voices(const std::string& language) const {
|
||||
Query q;
|
||||
if (!language.empty()) q.emplace_back("languageCode", checked_language_code(language, "language"));
|
||||
return invoke(Call::kTtsVoicesList, "", nullptr, q);
|
||||
}
|
||||
|
||||
void LongAudio::cancel_operation(const std::string& name) const {
|
||||
invoke(Call::kTtsOperationsCancel, name);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
// Text-to-Speech long audio synthesis (v1 projects.locations.synthesizeLongAudio):
|
||||
// a long-running operation that writes LINEAR16 audio to a gs:// object, plus
|
||||
// the voice list. Paid per character. Short synthesis stays in
|
||||
// google/text_to_speech.h.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct LongAudioRequest {
|
||||
std::string text; // plain text (or SSML when ssml is true), at most 1,000,000 bytes
|
||||
bool ssml = false;
|
||||
std::string language; // voice languageCode, e.g. en-US
|
||||
std::string voice_name; // optional, e.g. en-US-Standard-A
|
||||
std::string encoding = "LINEAR16"; // AudioConfig.audioEncoding (long audio supports LINEAR16)
|
||||
std::string output_uri; // gs://bucket/object.wav
|
||||
};
|
||||
|
||||
class LongAudio : public CloudAiService {
|
||||
public:
|
||||
using CloudAiService::CloudAiService;
|
||||
|
||||
clients::body::Json request_body(const LongAudioRequest& r) const;
|
||||
Operation synthesize_start(const LongAudioRequest& r) const; // never waits
|
||||
Operation get_operation(const std::string& name) const;
|
||||
clients::body::Json list_operations() const;
|
||||
// Free of charge.
|
||||
clients::body::Json voices(const std::string& language = "") const;
|
||||
// Explicit.
|
||||
void cancel_operation(const std::string& name) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,77 @@
|
||||
#include "google/cloudai/natural_language.h"
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
Json NaturalLanguage::document_json(const NlDocument& d) const {
|
||||
if (!valid_enum("Document.type", d.type)) throw GoogleError::invalid("document type must be PLAIN_TEXT or HTML");
|
||||
Json o = Json::object();
|
||||
o.set("type", Json(d.type));
|
||||
if (!d.gcs_uri.empty()) {
|
||||
if (!d.content.empty()) throw GoogleError::invalid("give content or gcsUri, not both");
|
||||
o.set("gcsContentUri", Json(checked_gcs_uri(d.gcs_uri, "gcsUri")));
|
||||
} else {
|
||||
if (d.content.empty()) throw GoogleError::invalid("document content is empty");
|
||||
if (d.content.size() > CloudAiCaps::kMaxNlTextChars)
|
||||
throw GoogleError::invalid("document content over 1,000,000 bytes");
|
||||
o.set("content", Json(d.content));
|
||||
}
|
||||
if (!d.language.empty()) o.set("languageCode", Json(checked_language_code(d.language, "language")));
|
||||
return o;
|
||||
}
|
||||
|
||||
Json NaturalLanguage::with_document(Call c, const NlDocument& d, const std::string& encoding,
|
||||
bool has_encoding) const {
|
||||
Json b = Json::object();
|
||||
b.set("document", document_json(d));
|
||||
if (!encoding.empty()) {
|
||||
if (!has_encoding || !valid_enum("AnnotateTextRequest.encodingType", encoding))
|
||||
throw GoogleError::invalid("encodingType must be NONE, UTF8, UTF16 or UTF32");
|
||||
b.set("encodingType", Json(encoding));
|
||||
}
|
||||
return invoke(c, "", &b);
|
||||
}
|
||||
|
||||
Json NaturalLanguage::analyze_sentiment(const NlDocument& d, const std::string& e) const {
|
||||
return with_document(Call::kLanguageDocumentsAnalyzeSentiment, d, e, true);
|
||||
}
|
||||
Json NaturalLanguage::analyze_entities(const NlDocument& d, const std::string& e) const {
|
||||
return with_document(Call::kLanguageDocumentsAnalyzeEntities, d, e, true);
|
||||
}
|
||||
Json NaturalLanguage::classify_text(const NlDocument& d) const {
|
||||
return with_document(Call::kLanguageDocumentsClassifyText, d, "", false);
|
||||
}
|
||||
Json NaturalLanguage::moderate_text(const NlDocument& d) const {
|
||||
return with_document(Call::kLanguageDocumentsModerateText, d, "", false);
|
||||
}
|
||||
Json NaturalLanguage::analyze_entity_sentiment(const NlDocument& d, const std::string& e) const {
|
||||
return with_document(Call::kLanguageV1DocumentsAnalyzeEntitySentiment, d, e, true);
|
||||
}
|
||||
Json NaturalLanguage::analyze_syntax(const NlDocument& d, const std::string& e) const {
|
||||
return with_document(Call::kLanguageV1DocumentsAnalyzeSyntax, d, e, true);
|
||||
}
|
||||
|
||||
Json NaturalLanguage::annotate_text(const NlDocument& d, const NlFeatures& f, const std::string& encoding) const {
|
||||
if (!f.entities && !f.sentiment && !f.classify && !f.moderate)
|
||||
throw GoogleError::invalid("annotateText needs at least one feature");
|
||||
Json feats = Json::object();
|
||||
if (f.entities) feats.set("extractEntities", Json(true));
|
||||
if (f.sentiment) feats.set("extractDocumentSentiment", Json(true));
|
||||
if (f.classify) feats.set("classifyText", Json(true));
|
||||
if (f.moderate) feats.set("moderateText", Json(true));
|
||||
Json b = Json::object();
|
||||
b.set("document", document_json(d));
|
||||
b.set("features", feats);
|
||||
if (!encoding.empty()) {
|
||||
if (!valid_enum("AnnotateTextRequest.encodingType", encoding))
|
||||
throw GoogleError::invalid("encodingType must be NONE, UTF8, UTF16 or UTF32");
|
||||
b.set("encodingType", Json(encoding));
|
||||
}
|
||||
return invoke(Call::kLanguageDocumentsAnnotateText, "", &b);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
// Cloud Natural Language: v2 (entities, sentiment, classify, moderate,
|
||||
// annotateText) and the two v1-only methods (entity sentiment, syntax).
|
||||
// Document content is paid per 1000 characters (first 5000 a month free).
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct NlDocument {
|
||||
std::string content; // text or HTML, at most 1,000,000 bytes
|
||||
std::string gcs_uri; // alternative to content
|
||||
std::string type = "PLAIN_TEXT"; // PLAIN_TEXT or HTML
|
||||
std::string language; // optional BCP-47, empty: detect
|
||||
};
|
||||
|
||||
struct NlFeatures {
|
||||
bool entities = false;
|
||||
bool sentiment = false;
|
||||
bool classify = false;
|
||||
bool moderate = false;
|
||||
};
|
||||
|
||||
class NaturalLanguage : public CloudAiService {
|
||||
public:
|
||||
using CloudAiService::CloudAiService;
|
||||
|
||||
clients::body::Json document_json(const NlDocument& d) const;
|
||||
|
||||
clients::body::Json analyze_sentiment(const NlDocument& d, const std::string& encoding = "") const;
|
||||
clients::body::Json analyze_entities(const NlDocument& d, const std::string& encoding = "") const;
|
||||
clients::body::Json classify_text(const NlDocument& d) const;
|
||||
clients::body::Json moderate_text(const NlDocument& d) const;
|
||||
clients::body::Json annotate_text(const NlDocument& d, const NlFeatures& f,
|
||||
const std::string& encoding = "") const;
|
||||
// v1 only.
|
||||
clients::body::Json analyze_entity_sentiment(const NlDocument& d, const std::string& encoding = "") const;
|
||||
clients::body::Json analyze_syntax(const NlDocument& d, const std::string& encoding = "") const;
|
||||
|
||||
private:
|
||||
clients::body::Json with_document(Call c, const NlDocument& d, const std::string& encoding,
|
||||
bool has_encoding) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "google/cloudai/speech_v2.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string checked_model(const std::string& m) {
|
||||
if (m.empty() || m.size() > 64) throw GoogleError::invalid("model: 1..64 chars");
|
||||
for (char c : m)
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_'))
|
||||
throw GoogleError::invalid("model has characters outside a-z 0-9 _");
|
||||
return m;
|
||||
}
|
||||
|
||||
Json languages_json(const std::vector<std::string>& langs) {
|
||||
if (langs.empty() || langs.size() > 3) throw GoogleError::invalid("languages: 1..3 codes");
|
||||
Json a = Json::array();
|
||||
for (const auto& l : langs) a.push(Json(l == "auto" ? l : checked_language_code(l, "language")));
|
||||
return a;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string SpeechV2::recognizer_name(const std::string& id) const {
|
||||
return context_.child("recognizers", id == "_" ? id : checked_id(id, "recognizer id"));
|
||||
}
|
||||
|
||||
Json SpeechV2::recognize_body(const SpeechRequest& r) const {
|
||||
Json cfg = Json::object();
|
||||
cfg.set("model", Json(checked_model(r.model)));
|
||||
cfg.set("languageCodes", languages_json(r.languages));
|
||||
cfg.set("autoDecodingConfig", Json::object());
|
||||
Json b = Json::object();
|
||||
b.set("config", cfg);
|
||||
if (!r.uri.empty()) {
|
||||
if (!r.content_base64.empty()) throw GoogleError::invalid("give content or uri, not both");
|
||||
b.set("uri", Json(checked_gcs_uri(r.uri, "uri")));
|
||||
} else {
|
||||
if (r.content_base64.empty()) throw GoogleError::invalid("audio content or uri is required");
|
||||
if (r.content_base64.size() / 4 * 3 > CloudAiCaps::kMaxAudioBytes)
|
||||
throw GoogleError::invalid("audio over 10 MiB");
|
||||
for (char c : r.content_base64)
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '+' ||
|
||||
c == '/' || c == '=' || c == '-' || c == '_'))
|
||||
throw GoogleError::invalid("content is not base64");
|
||||
b.set("content", Json(r.content_base64));
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
Json SpeechV2::recognize(const SpeechRequest& r) const {
|
||||
Json b = recognize_body(r);
|
||||
return invoke(Call::kSpeechLocationsRecognizersRecognize, recognizer_name(r.recognizer), &b);
|
||||
}
|
||||
|
||||
Json SpeechV2::list_recognizers() const {
|
||||
return list(Call::kSpeechLocationsRecognizersList, parent(), "recognizers");
|
||||
}
|
||||
Json SpeechV2::get_recognizer(const std::string& id) const {
|
||||
return invoke(Call::kSpeechLocationsRecognizersGet, recognizer_name(id));
|
||||
}
|
||||
Json SpeechV2::list_phrase_sets() const {
|
||||
return list(Call::kSpeechLocationsPhraseSetsList, parent(), "phraseSets");
|
||||
}
|
||||
Json SpeechV2::list_custom_classes() const {
|
||||
return list(Call::kSpeechLocationsCustomClassesList, parent(), "customClasses");
|
||||
}
|
||||
Json SpeechV2::get_config() const {
|
||||
return invoke(Call::kSpeechLocationsConfigGet, parent() + "/config");
|
||||
}
|
||||
Json SpeechV2::list_locations() const {
|
||||
return list(Call::kSpeechLocationsList, project(), "locations");
|
||||
}
|
||||
Operation SpeechV2::get_operation(const std::string& name) const {
|
||||
return operation(Call::kSpeechLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
Operation SpeechV2::create_recognizer_start(const std::string& id, const std::string& model,
|
||||
const std::vector<std::string>& languages) const {
|
||||
Json rec = Json::object();
|
||||
rec.set("model", Json(checked_model(model)));
|
||||
rec.set("languageCodes", languages_json(languages));
|
||||
return start(Call::kSpeechLocationsRecognizersCreate, parent(), &rec,
|
||||
{{"recognizerId", checked_id(id, "recognizer id")}});
|
||||
}
|
||||
Operation SpeechV2::delete_recognizer_start(const std::string& id) const {
|
||||
return start(Call::kSpeechLocationsRecognizersDelete, recognizer_name(id));
|
||||
}
|
||||
|
||||
Json SpeechV2::call(Call c, const std::string& name, const Json* body, const Query& query) const {
|
||||
if (std::strcmp(spec(c).api, "speech") != 0) throw GoogleError::invalid("not a Speech call");
|
||||
return invoke(c, name, body, query);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
// Speech-to-Text v2 (Chirp models): recognize against a recognizer (the
|
||||
// recognizer id "_" is the implicit default recognizer), recognizers, phrase
|
||||
// sets, custom classes, config. Models such as chirp_2 / chirp_3 need their
|
||||
// supported regions (us-central1, europe-west4, us, eu ...).
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct SpeechRequest {
|
||||
std::string recognizer = "_"; // id under the context location
|
||||
std::string content_base64; // audio bytes, base64 (at most 10 MiB decoded)
|
||||
std::string uri; // alternative: gs:// audio
|
||||
std::string model = "chirp_2"; // 1..64 chars [a-z0-9_]
|
||||
std::vector<std::string> languages; // 1..3 BCP-47 codes, or "auto"
|
||||
};
|
||||
|
||||
class SpeechV2 : public CloudAiService {
|
||||
public:
|
||||
using CloudAiService::CloudAiService;
|
||||
|
||||
std::string recognizer_name(const std::string& id) const;
|
||||
clients::body::Json recognize_body(const SpeechRequest& r) const;
|
||||
// Paid (per second of audio).
|
||||
clients::body::Json recognize(const SpeechRequest& r) const;
|
||||
|
||||
clients::body::Json list_recognizers() const;
|
||||
clients::body::Json get_recognizer(const std::string& id) const;
|
||||
clients::body::Json list_phrase_sets() const;
|
||||
clients::body::Json list_custom_classes() const;
|
||||
clients::body::Json get_config() const;
|
||||
clients::body::Json list_locations() const;
|
||||
Operation get_operation(const std::string& name) const;
|
||||
|
||||
// Writes: explicit, no defaults.
|
||||
Operation create_recognizer_start(const std::string& id, const std::string& model,
|
||||
const std::vector<std::string>& languages) const;
|
||||
Operation delete_recognizer_start(const std::string& id) const;
|
||||
|
||||
clients::body::Json call(Call c, const std::string& name, const clients::body::Json* body = nullptr,
|
||||
const Query& query = {}) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,220 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check (and generate) the cloudai call table against Google's Discovery documents.
|
||||
|
||||
python3 -I src/google/cloudai/tools/check_discovery.py # check
|
||||
python3 src/google/cloudai/tools/check_discovery.py --generate # rewrite the .inc files
|
||||
|
||||
The call table (calls_table.inc) and the enum (call_enum.inc) are generated
|
||||
from Discovery by --generate, so every path, HTTP method, request field and
|
||||
query parameter is read, never typed. The check fails (exit 1) when:
|
||||
row a row is absent from Discovery, or its HTTP method, path, request
|
||||
fields, query parameters, path variable or pattern differ;
|
||||
coverage a Discovery method of a covered API is neither a row nor listed in
|
||||
EXCLUDED with a reason (a new Discovery method fails until wrapped);
|
||||
schema a schema field the typed classes use (SCHEMAS-BEGIN block in
|
||||
calls.cpp) is absent;
|
||||
enum an accepted enum set differs from Discovery's;
|
||||
endpoint a regional host used by calls.cpp (Document AI, Speech) is not in
|
||||
the Discovery `endpoints` list.
|
||||
Python 3 stdlib only, no credentials needed.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
PKG = os.path.join(HERE, "..")
|
||||
URL = "https://%s.googleapis.com/$discovery/rest?version=%s"
|
||||
|
||||
# (discovery name, version, enum prefix, only these rpc ids or None for all)
|
||||
APIS = [
|
||||
("translate", "v3", "Translate", None),
|
||||
("vision", "v1", "Vision", None),
|
||||
("language", "v2", "Language", None),
|
||||
("language", "v1", "LanguageV1",
|
||||
{"language.documents.analyzeEntitySentiment", "language.documents.analyzeSyntax"}),
|
||||
("videointelligence", "v1", "Video", None),
|
||||
("documentai", "v1", "Documentai", None),
|
||||
("speech", "v2", "Speech", None),
|
||||
("texttospeech", "v1", "Tts", None),
|
||||
]
|
||||
# Discovery methods deliberately not wrapped (id -> reason).
|
||||
EXCLUDED = {
|
||||
"videointelligence.operations.projects.locations.operations.get": "alias of projects.locations.operations.get",
|
||||
"videointelligence.operations.projects.locations.operations.cancel": "alias of projects.locations.operations.cancel",
|
||||
"videointelligence.operations.projects.locations.operations.delete": "alias of projects.locations.operations.delete",
|
||||
}
|
||||
# Not in the Discovery directory: no public REST surface to derive calls from.
|
||||
NOT_IN_DISCOVERY = ["mediatranslation"]
|
||||
|
||||
|
||||
def fetch(name, version):
|
||||
last = None
|
||||
for _ in range(4):
|
||||
try:
|
||||
with urllib.request.urlopen(URL % (name, version), timeout=60) as r:
|
||||
return json.load(r)
|
||||
except Exception as e: # transient 502s happen
|
||||
last = e
|
||||
time.sleep(2)
|
||||
raise last
|
||||
|
||||
|
||||
def methods(node, out):
|
||||
for m in node.get("methods", {}).values():
|
||||
out[m["id"]] = m
|
||||
for child in node.get("resources", {}).values():
|
||||
methods(child, out)
|
||||
|
||||
|
||||
def camel(parts):
|
||||
return "".join(p[:1].upper() + p[1:] for p in parts)
|
||||
|
||||
|
||||
def row_fields(doc, m):
|
||||
ref = m.get("request", {}).get("$ref")
|
||||
body = sorted(doc["schemas"][ref]["properties"]) if ref else []
|
||||
query = sorted(k for k, v in m.get("parameters", {}).items() if v.get("location") == "query")
|
||||
names = re.findall(r"\{\+?(\w+)\}", m["path"])
|
||||
var = names[0] if names else ""
|
||||
pat = m.get("parameters", {}).get(var, {}).get("pattern", "") if var else ""
|
||||
return body, query, var, pat
|
||||
|
||||
|
||||
def build():
|
||||
docs, rows, used = {}, [], set()
|
||||
for name, version, prefix, only in APIS:
|
||||
doc = fetch(name, version)
|
||||
docs[(name, version)] = doc
|
||||
idx = {}
|
||||
methods(doc, idx)
|
||||
for rpc in sorted(idx):
|
||||
m = idx[rpc]
|
||||
if only is not None and rpc not in only:
|
||||
continue
|
||||
if rpc in EXCLUDED:
|
||||
continue
|
||||
parts = rpc.split(".")[1:]
|
||||
short = parts[1:] if parts[0] == "projects" else parts
|
||||
ident = "k" + prefix + camel(short)
|
||||
if ident in used:
|
||||
ident = "k" + prefix + camel(parts)
|
||||
assert ident not in used, ident
|
||||
used.add(ident)
|
||||
body, query, var, pat = row_fields(doc, m)
|
||||
rows.append((ident, m["httpMethod"], m["path"], name, version, rpc,
|
||||
",".join(body), ",".join(query), var, pat))
|
||||
return docs, rows
|
||||
|
||||
|
||||
def generate():
|
||||
_, rows = build()
|
||||
with open(os.path.join(PKG, "call_enum.inc"), "w") as f:
|
||||
f.write("// Generated by tools/check_discovery.py --generate. Do not edit.\n")
|
||||
for r in rows:
|
||||
f.write(" %s,\n" % r[0])
|
||||
with open(os.path.join(PKG, "calls_table.inc"), "w") as f:
|
||||
f.write("// Generated by tools/check_discovery.py --generate. Do not edit.\n")
|
||||
f.write("// CALLS-BEGIN (parsed by tools/check_discovery.py; one row per line)\n")
|
||||
for r in rows:
|
||||
f.write(" {Call::%s, %s},\n" % (r[0], ", ".join('"%s"' % x for x in r[1:])))
|
||||
f.write("// CALLS-END\n")
|
||||
print("generated %d rows" % len(rows))
|
||||
|
||||
|
||||
ROW = re.compile(r'^\s*\{Call::(\w+),\s*(.*)\},?\s*$')
|
||||
STR = re.compile(r'"([^"]*)"')
|
||||
|
||||
|
||||
def table_rows():
|
||||
rows = []
|
||||
text = open(os.path.join(PKG, "calls_table.inc")).read()
|
||||
a, b = text.index("// CALLS-BEGIN"), text.index("// CALLS-END")
|
||||
for line in text[a:b].splitlines()[1:]:
|
||||
m = ROW.match(line)
|
||||
if m:
|
||||
rows.append(STR.findall(m.group(2)))
|
||||
return rows
|
||||
|
||||
|
||||
def block(text, begin, end):
|
||||
a, b = text.index(begin), text.index(end)
|
||||
out = []
|
||||
for line in text[a:b].splitlines()[1:]:
|
||||
s = STR.findall(line)
|
||||
if s:
|
||||
out.append(s)
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
if "--generate" in sys.argv:
|
||||
generate()
|
||||
return 0
|
||||
rows = table_rows()
|
||||
docs, expected = build()
|
||||
bad = []
|
||||
# (rpc, api, version) triples
|
||||
have = {(r[4], r[2], r[3]) for r in rows}
|
||||
want = {(e[5], e[3], e[4]) for e in expected}
|
||||
for t in sorted(want - have):
|
||||
bad.append("coverage: discovery method %s (%s %s) is not a row" % t)
|
||||
for t in sorted(have - want):
|
||||
bad.append("row %s (%s %s) is not in discovery" % t)
|
||||
by = {}
|
||||
for r in rows:
|
||||
by[(r[4], r[2], r[3])] = r
|
||||
for e in expected:
|
||||
r = by.get((e[5], e[3], e[4]))
|
||||
if not r:
|
||||
continue
|
||||
if r[0] != e[1]:
|
||||
bad.append("%s: http %s != %s" % (e[5], r[0], e[1]))
|
||||
if r[1] != e[2]:
|
||||
bad.append("%s: path %s != %s" % (e[5], r[1], e[2]))
|
||||
for i, label in ((5, "body fields"), (6, "query"), (7, "path variable"), (8, "pattern")):
|
||||
if r[i] != e[i + 1]:
|
||||
bad.append("%s: %s %r != %r" % (e[5], label, r[i], e[i + 1]))
|
||||
calls_cpp = open(os.path.join(PKG, "calls.cpp")).read()
|
||||
for api, version, schema, fields in block(calls_cpp, "// SCHEMAS-BEGIN", "// SCHEMAS-END"):
|
||||
doc = docs.get((api, version))
|
||||
props = doc["schemas"].get(schema, {}).get("properties") if doc else None
|
||||
if props is None:
|
||||
bad.append("missing schema %s %s %s" % (api, version, schema))
|
||||
continue
|
||||
for f in fields.split(","):
|
||||
if f not in props:
|
||||
bad.append("schema %s.%s absent" % (schema, f))
|
||||
for api, version, sf, values in block(calls_cpp, "// ENUMS-BEGIN", "// ENUMS-END"):
|
||||
doc = docs.get((api, version))
|
||||
schema, field = sf.split(".")
|
||||
prop = doc["schemas"].get(schema, {}).get("properties", {}).get(field) if doc else None
|
||||
enum = (prop.get("enum") or prop.get("items", {}).get("enum")) if prop else None
|
||||
if not enum:
|
||||
bad.append("enum %s %s has no discovery enum" % (api, sf))
|
||||
continue
|
||||
real = {v for v in enum if not v.endswith("UNSPECIFIED")}
|
||||
if real != set(values.split(",")):
|
||||
bad.append("enum %s differs: missing %s extra %s" % (
|
||||
sf, sorted(real - set(values.split(","))), sorted(set(values.split(",")) - real)))
|
||||
for api, version, hosts in block(calls_cpp, "// ENDPOINTS-BEGIN", "// ENDPOINTS-END"):
|
||||
doc = docs.get((api, version))
|
||||
listed = {e["location"] for e in doc.get("endpoints", [])} if doc else set()
|
||||
for loc in hosts.split(","):
|
||||
if loc not in listed:
|
||||
bad.append("endpoint %s %s not in discovery endpoints" % (api, loc))
|
||||
revs = {"%s-%s" % k: d.get("revision") for k, d in docs.items()}
|
||||
if bad:
|
||||
print("DISCOVERY CHECK FAILED (revisions %s)" % revs)
|
||||
for b in bad:
|
||||
print(" " + b)
|
||||
return 1
|
||||
print("discovery ok: %d rows, %d apis, revisions %s" % (len(rows), len(docs), revs))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,191 @@
|
||||
#include "google/cloudai/translation.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
namespace {
|
||||
|
||||
std::size_t code_points(const std::string& s) {
|
||||
std::size_t n = 0;
|
||||
for (unsigned char c : s)
|
||||
if ((c & 0xC0) != 0x80) ++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
void check_texts(const std::vector<std::string>& texts) {
|
||||
if (texts.empty()) throw GoogleError::invalid("texts must not be empty");
|
||||
if (texts.size() > CloudAiCaps::kMaxTexts) throw GoogleError::invalid("too many texts (max 1024)");
|
||||
std::size_t total = 0;
|
||||
for (const auto& t : texts) {
|
||||
if (t.empty()) throw GoogleError::invalid("a text is empty");
|
||||
total += code_points(t);
|
||||
}
|
||||
if (total > CloudAiCaps::kMaxTextChars)
|
||||
throw GoogleError::invalid("texts exceed 30000 characters in total");
|
||||
}
|
||||
|
||||
Json strings(const std::vector<std::string>& v) {
|
||||
Json a = Json::array();
|
||||
for (const auto& s : v) a.push(Json(s));
|
||||
return a;
|
||||
}
|
||||
|
||||
std::string s_at(const Json& j, const char* k) {
|
||||
const Json* v = j.is_object() ? j.find(k) : nullptr;
|
||||
return v && v->is_string() ? v->as_string() : std::string();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
std::string Translation::glossary_name(const std::string& id) const {
|
||||
return context_.child("glossaries", checked_id(id, "glossary id"));
|
||||
}
|
||||
|
||||
void Translation::validate(const TranslateRequest& r) const {
|
||||
check_texts(r.texts);
|
||||
checked_language_code(r.target, "target");
|
||||
if (!r.source.empty()) checked_language_code(r.source, "source");
|
||||
if (!r.mime_type.empty() && r.mime_type != "text/plain" && r.mime_type != "text/html")
|
||||
throw GoogleError::invalid("mimeType must be text/plain or text/html");
|
||||
if (r.model.size() > CloudAiCaps::kMaxNameChars) throw GoogleError::invalid("model too long");
|
||||
if (!r.model.empty() && r.model.rfind("projects/", 0) != 0)
|
||||
throw GoogleError::invalid("model must be a full projects/... name");
|
||||
if (!r.glossary.empty() && (r.glossary.rfind("projects/", 0) != 0 ||
|
||||
r.glossary.size() > CloudAiCaps::kMaxNameChars ||
|
||||
r.glossary.find("..") != std::string::npos))
|
||||
throw GoogleError::invalid("glossary must be a full projects/... name");
|
||||
}
|
||||
|
||||
Json Translation::translate_body(const TranslateRequest& r) const {
|
||||
validate(r);
|
||||
Json b = Json::object();
|
||||
b.set("contents", strings(r.texts));
|
||||
b.set("targetLanguageCode", Json(r.target));
|
||||
if (!r.source.empty()) b.set("sourceLanguageCode", Json(r.source));
|
||||
if (!r.mime_type.empty()) b.set("mimeType", Json(r.mime_type));
|
||||
if (!r.model.empty()) b.set("model", Json(r.model));
|
||||
if (!r.glossary.empty()) {
|
||||
Json g = Json::object();
|
||||
g.set("glossary", Json(r.glossary));
|
||||
if (r.glossary_ignore_case) g.set("ignoreCase", Json(true));
|
||||
b.set("glossaryConfig", g);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
std::vector<Translated> Translation::translate(const TranslateRequest& r) const {
|
||||
Json b = translate_body(r);
|
||||
Json reply = invoke(Call::kTranslateLocationsTranslateText, parent(), &b);
|
||||
std::vector<Translated> out;
|
||||
const Json* arr = reply.find("translations");
|
||||
if (arr && arr->is_array())
|
||||
for (const Json& t : arr->as_array())
|
||||
out.push_back({s_at(t, "translatedText"), s_at(t, "detectedLanguageCode"), s_at(t, "model")});
|
||||
return out;
|
||||
}
|
||||
|
||||
Json Translation::detect_language(const std::string& text) const {
|
||||
check_texts({text});
|
||||
Json b = Json::object();
|
||||
b.set("content", Json(text));
|
||||
b.set("mimeType", Json("text/plain"));
|
||||
return invoke(Call::kTranslateLocationsDetectLanguage, parent(), &b);
|
||||
}
|
||||
|
||||
Json Translation::supported_languages(const std::string& display_language, const std::string& model) const {
|
||||
Query q;
|
||||
if (!display_language.empty()) q.emplace_back("displayLanguageCode", checked_language_code(display_language, "displayLanguageCode"));
|
||||
if (!model.empty()) q.emplace_back("model", model);
|
||||
return invoke(Call::kTranslateLocationsGetSupportedLanguages, parent(), nullptr, q);
|
||||
}
|
||||
|
||||
Json Translation::romanize(const std::vector<std::string>& texts, const std::string& source) const {
|
||||
check_texts(texts);
|
||||
Json b = Json::object();
|
||||
b.set("contents", strings(texts));
|
||||
if (!source.empty()) b.set("sourceLanguageCode", Json(checked_language_code(source, "source")));
|
||||
return invoke(Call::kTranslateLocationsRomanizeText, parent(), &b);
|
||||
}
|
||||
|
||||
Json Translation::list_glossaries() const {
|
||||
return list(Call::kTranslateLocationsGlossariesList, parent(), "glossaries");
|
||||
}
|
||||
Json Translation::get_glossary(const std::string& id) const {
|
||||
return invoke(Call::kTranslateLocationsGlossariesGet, glossary_name(id));
|
||||
}
|
||||
Json Translation::list_adaptive_datasets() const {
|
||||
return list(Call::kTranslateLocationsAdaptiveMtDatasetsList, parent(), "adaptiveMtDatasets");
|
||||
}
|
||||
Json Translation::get_adaptive_dataset(const std::string& id) const {
|
||||
return invoke(Call::kTranslateLocationsAdaptiveMtDatasetsGet,
|
||||
context_.child("adaptiveMtDatasets", checked_id(id, "dataset id")));
|
||||
}
|
||||
Json Translation::list_models() const {
|
||||
return list(Call::kTranslateLocationsModelsList, parent(), "models");
|
||||
}
|
||||
Json Translation::list_datasets() const {
|
||||
return list(Call::kTranslateLocationsDatasetsList, parent(), "datasets");
|
||||
}
|
||||
Json Translation::list_locations() const {
|
||||
return list(Call::kTranslateLocationsList, project(), "locations");
|
||||
}
|
||||
Operation Translation::get_operation(const std::string& name) const {
|
||||
return operation(Call::kTranslateLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
Json Translation::adaptive_translate(const std::string& dataset_id, const std::vector<std::string>& texts) const {
|
||||
check_texts(texts);
|
||||
Json b = Json::object();
|
||||
b.set("dataset", Json(context_.child("adaptiveMtDatasets", checked_id(dataset_id, "dataset id"))));
|
||||
b.set("content", strings(texts));
|
||||
return invoke(Call::kTranslateLocationsAdaptiveMtTranslate, parent(), &b);
|
||||
}
|
||||
|
||||
Json Translation::glossary_body(const GlossaryDraft& d) const {
|
||||
Json b = Json::object();
|
||||
b.set("name", Json(glossary_name(d.id)));
|
||||
Json in = Json::object();
|
||||
Json gcs = Json::object();
|
||||
gcs.set("inputUri", Json(checked_gcs_uri(d.input_uri, "inputUri")));
|
||||
in.set("gcsSource", gcs);
|
||||
b.set("inputConfig", in);
|
||||
if (!d.language_codes.empty()) {
|
||||
if (!d.source_language.empty() || !d.target_language.empty())
|
||||
throw GoogleError::invalid("use a language pair or a language set, not both");
|
||||
if (d.language_codes.size() < 2 || d.language_codes.size() > 64)
|
||||
throw GoogleError::invalid("a language set needs 2..64 codes");
|
||||
Json set = Json::object();
|
||||
Json codes = Json::array();
|
||||
for (const auto& c : d.language_codes) codes.push(Json(checked_language_code(c, "language code")));
|
||||
set.set("languageCodes", codes);
|
||||
b.set("languageCodesSet", set);
|
||||
} else {
|
||||
Json pair = Json::object();
|
||||
pair.set("sourceLanguageCode", Json(checked_language_code(d.source_language, "source")));
|
||||
pair.set("targetLanguageCode", Json(checked_language_code(d.target_language, "target")));
|
||||
b.set("languagePair", pair);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
Operation Translation::create_glossary_start(const GlossaryDraft& d) const {
|
||||
Json b = glossary_body(d);
|
||||
return start(Call::kTranslateLocationsGlossariesCreate, parent(), &b);
|
||||
}
|
||||
|
||||
Operation Translation::delete_glossary_start(const std::string& id) const {
|
||||
return start(Call::kTranslateLocationsGlossariesDelete, glossary_name(id));
|
||||
}
|
||||
|
||||
Json Translation::call(Call c, const std::string& name, const Json* body, const Query& query) const {
|
||||
if (std::strcmp(spec(c).api, "translate") != 0) throw GoogleError::invalid("not a Translation call");
|
||||
return invoke(c, name, body, query);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
|
||||
// Cloud Translation v3: text, language detection, supported languages,
|
||||
// romanization, glossaries, adaptive MT, batch and document translation,
|
||||
// models and datasets. Location defaults to "global" in the demo; glossaries
|
||||
// and models are regional resources.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct TranslateRequest {
|
||||
std::vector<std::string> texts; // 1..1024, total at most 30000 characters
|
||||
std::string target; // required language code
|
||||
std::string source; // optional, empty: detect
|
||||
std::string mime_type; // text/plain (default) or text/html
|
||||
std::string model; // optional full model name
|
||||
std::string glossary; // optional full glossary name
|
||||
bool glossary_ignore_case = false;
|
||||
};
|
||||
|
||||
struct Translated {
|
||||
std::string text;
|
||||
std::string detected_language;
|
||||
std::string model;
|
||||
};
|
||||
|
||||
struct GlossaryDraft {
|
||||
std::string id; // glossary id
|
||||
std::string input_uri; // gs:// csv / tsv / tmx
|
||||
std::string source_language; // with target_language: unidirectional pair
|
||||
std::string target_language;
|
||||
std::vector<std::string> language_codes; // set: equivalent term sets (alternative to the pair)
|
||||
};
|
||||
|
||||
class Translation : public CloudAiService {
|
||||
public:
|
||||
using CloudAiService::CloudAiService;
|
||||
|
||||
void validate(const TranslateRequest& r) const;
|
||||
clients::body::Json translate_body(const TranslateRequest& r) const;
|
||||
// Paid (per character). Uses projects/{p}/locations/{l}.
|
||||
std::vector<Translated> translate(const TranslateRequest& r) const;
|
||||
|
||||
clients::body::Json detect_language(const std::string& text) const;
|
||||
clients::body::Json supported_languages(const std::string& display_language = "",
|
||||
const std::string& model = "") const;
|
||||
clients::body::Json romanize(const std::vector<std::string>& texts,
|
||||
const std::string& source = "") const;
|
||||
|
||||
// Reads.
|
||||
clients::body::Json list_glossaries() const;
|
||||
clients::body::Json get_glossary(const std::string& id) const;
|
||||
clients::body::Json list_adaptive_datasets() const;
|
||||
clients::body::Json get_adaptive_dataset(const std::string& id) const;
|
||||
clients::body::Json list_models() const;
|
||||
clients::body::Json list_datasets() const;
|
||||
clients::body::Json list_locations() const;
|
||||
Operation get_operation(const std::string& name) const;
|
||||
|
||||
// Adaptive MT translate: texts against a dataset (paid).
|
||||
clients::body::Json adaptive_translate(const std::string& dataset_id,
|
||||
const std::vector<std::string>& texts) const;
|
||||
|
||||
// Long-running starts. They answer the operation and never wait.
|
||||
clients::body::Json glossary_body(const GlossaryDraft& d) const;
|
||||
Operation create_glossary_start(const GlossaryDraft& d) const;
|
||||
// Destructive: explicit, no default.
|
||||
Operation delete_glossary_start(const std::string& id) const;
|
||||
|
||||
// Any other row of the Translation family by call (validated against it).
|
||||
clients::body::Json call(Call c, const std::string& name, const clients::body::Json* body = nullptr,
|
||||
const Query& query = {}) const;
|
||||
|
||||
std::string glossary_name(const std::string& id) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "google/cloudai/video_intelligence.h"
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
Json VideoIntelligence::annotate_body(const VideoRequest& r) const {
|
||||
if (r.features.empty() || r.features.size() > 9) throw GoogleError::invalid("features: 1..9 required");
|
||||
Json feats = Json::array();
|
||||
for (const auto& f : r.features) {
|
||||
if (!valid_enum("GoogleCloudVideointelligenceV1_AnnotateVideoRequest.features", f))
|
||||
throw GoogleError::invalid("unknown video feature " + f);
|
||||
feats.push(Json(f));
|
||||
}
|
||||
Json b = Json::object();
|
||||
if (!r.input_uri.empty()) {
|
||||
if (!r.input_content_base64.empty()) throw GoogleError::invalid("give inputUri or content, not both");
|
||||
b.set("inputUri", Json(checked_gcs_uri(r.input_uri, "inputUri")));
|
||||
} else {
|
||||
if (r.input_content_base64.empty()) throw GoogleError::invalid("inputUri or content is required");
|
||||
if (r.input_content_base64.size() / 4 * 3 > CloudAiCaps::kMaxAudioBytes)
|
||||
throw GoogleError::invalid("inline video over 10 MiB");
|
||||
b.set("inputContent", Json(r.input_content_base64));
|
||||
}
|
||||
b.set("features", feats);
|
||||
if (!r.output_uri.empty()) b.set("outputUri", Json(checked_gcs_uri(r.output_uri, "outputUri")));
|
||||
if (!r.location_id.empty()) {
|
||||
for (const char* ok : {"us-east1", "us-west1", "europe-west1", "asia-east1"})
|
||||
if (r.location_id == ok) {
|
||||
b.set("locationId", Json(r.location_id));
|
||||
break;
|
||||
}
|
||||
if (!b.find("locationId")) throw GoogleError::invalid("locationId must be us-east1, us-west1, europe-west1 or asia-east1");
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
Operation VideoIntelligence::annotate_start(const VideoRequest& r) const {
|
||||
Json b = annotate_body(r);
|
||||
return start(Call::kVideoVideosAnnotate, "", &b);
|
||||
}
|
||||
|
||||
Operation VideoIntelligence::get_operation(const std::string& name) const {
|
||||
return operation(Call::kVideoLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
Json VideoIntelligence::list_operations(const std::string& filter) const {
|
||||
Query q;
|
||||
if (!filter.empty()) q.emplace_back("filter", filter);
|
||||
return list(Call::kVideoLocationsOperationsList, parent(), "operations", q);
|
||||
}
|
||||
|
||||
void VideoIntelligence::cancel_operation(const std::string& name) const {
|
||||
invoke(Call::kVideoLocationsOperationsCancel, name);
|
||||
}
|
||||
void VideoIntelligence::delete_operation(const std::string& name) const {
|
||||
invoke(Call::kVideoLocationsOperationsDelete, name);
|
||||
}
|
||||
Operation VideoIntelligence::wait_operation_done(const std::string& name) const {
|
||||
return wait(Call::kVideoLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
// Cloud Video Intelligence v1: videos.annotate starts a long-running
|
||||
// operation (paid per minute of video and feature); operations are read,
|
||||
// listed, cancelled or deleted through the project location.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct VideoRequest {
|
||||
std::string input_uri; // gs:// video
|
||||
std::string input_content_base64; // alternative, at most 10 MiB
|
||||
std::vector<std::string> features; // 1..9, AnnotateVideoRequest.features enum
|
||||
std::string output_uri; // optional gs:// for the JSON result
|
||||
std::string location_id; // optional: us-east1, us-west1, europe-west1, asia-east1
|
||||
};
|
||||
|
||||
class VideoIntelligence : public CloudAiService {
|
||||
public:
|
||||
using CloudAiService::CloudAiService;
|
||||
|
||||
clients::body::Json annotate_body(const VideoRequest& r) const;
|
||||
// Starts the operation and answers it; never waits (videos take minutes).
|
||||
Operation annotate_start(const VideoRequest& r) const;
|
||||
|
||||
Operation get_operation(const std::string& name) const;
|
||||
clients::body::Json list_operations(const std::string& filter = "") const;
|
||||
// Cancel and delete are explicit.
|
||||
void cancel_operation(const std::string& name) const;
|
||||
void delete_operation(const std::string& name) const;
|
||||
Operation wait_operation_done(const std::string& name) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,188 @@
|
||||
#include "google/cloudai/vision.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "google/cloudai/caps.h"
|
||||
#include "google/errors.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
using clients::body::Json;
|
||||
|
||||
namespace {
|
||||
|
||||
bool base64_ok(const std::string& s) {
|
||||
if (s.empty()) return false;
|
||||
for (char c : s)
|
||||
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '+' ||
|
||||
c == '/' || c == '=' || c == '-' || c == '_'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void check_inline(const std::string& b64, const char* what) {
|
||||
if (!base64_ok(b64)) throw GoogleError::invalid(std::string(what) + " is not base64");
|
||||
if (b64.size() / 4 * 3 > CloudAiCaps::kMaxAudioBytes)
|
||||
throw GoogleError::invalid(std::string(what) + " exceeds 10 MiB");
|
||||
}
|
||||
|
||||
Json features_json(const std::vector<VisionFeature>& features) {
|
||||
if (features.empty() || features.size() > CloudAiCaps::kMaxFeatures)
|
||||
throw GoogleError::invalid("features: 1..16 required");
|
||||
Json arr = Json::array();
|
||||
for (const auto& f : features) {
|
||||
if (!Vision::valid_feature(f.type)) throw GoogleError::invalid("unknown feature type " + f.type);
|
||||
if (f.max_results < 0 || f.max_results > CloudAiCaps::kMaxResults)
|
||||
throw GoogleError::invalid("maxResults must be 0..100");
|
||||
Json o = Json::object();
|
||||
o.set("type", Json(f.type));
|
||||
if (f.max_results > 0) o.set("maxResults", Json(f.max_results));
|
||||
arr.push(o);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
Json image_json(const VisionImage& im) {
|
||||
Json o = Json::object();
|
||||
if (!im.content_base64.empty()) {
|
||||
if (!im.uri.empty()) throw GoogleError::invalid("image: give content or uri, not both");
|
||||
check_inline(im.content_base64, "image content");
|
||||
o.set("content", Json(im.content_base64));
|
||||
} else if (!im.uri.empty()) {
|
||||
Json src = Json::object();
|
||||
if (im.uri.rfind("gs://", 0) == 0)
|
||||
src.set("gcsImageUri", Json(checked_gcs_uri(im.uri, "image uri")));
|
||||
else
|
||||
src.set("imageUri", Json(checked_https_or_gcs_uri(im.uri, "image uri")));
|
||||
o.set("source", src);
|
||||
} else {
|
||||
throw GoogleError::invalid("image needs content or uri");
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool Vision::valid_feature(const std::string& type) { return valid_enum("Feature.type", type); }
|
||||
|
||||
std::string Vision::product_set_name(const std::string& id) const {
|
||||
return context_.child("productSets", checked_id(id, "product set id"));
|
||||
}
|
||||
std::string Vision::product_name(const std::string& id) const {
|
||||
return context_.child("products", checked_id(id, "product id"));
|
||||
}
|
||||
|
||||
Json Vision::annotate_body(const std::vector<VisionImage>& images,
|
||||
const std::vector<VisionFeature>& features) const {
|
||||
if (images.empty() || images.size() > CloudAiCaps::kMaxImages)
|
||||
throw GoogleError::invalid("images: 1..16 required");
|
||||
Json feats = features_json(features);
|
||||
Json reqs = Json::array();
|
||||
for (const auto& im : images) {
|
||||
Json r = Json::object();
|
||||
r.set("image", image_json(im));
|
||||
r.set("features", feats);
|
||||
reqs.push(r);
|
||||
}
|
||||
Json b = Json::object();
|
||||
b.set("requests", reqs);
|
||||
return b;
|
||||
}
|
||||
|
||||
Json Vision::annotate(const std::vector<VisionImage>& images, const std::vector<VisionFeature>& features) const {
|
||||
Json b = annotate_body(images, features);
|
||||
return invoke(Call::kVisionImagesAnnotate, "", &b);
|
||||
}
|
||||
|
||||
Json Vision::annotate_file_body(const FileAnnotation& file, const std::vector<VisionFeature>& features) const {
|
||||
Json input = Json::object();
|
||||
if (!file.gcs_uri.empty()) {
|
||||
if (!file.content_base64.empty()) throw GoogleError::invalid("file: give gcsUri or content, not both");
|
||||
Json gcs = Json::object();
|
||||
gcs.set("uri", Json(checked_gcs_uri(file.gcs_uri, "file uri")));
|
||||
input.set("gcsSource", gcs);
|
||||
} else {
|
||||
check_inline(file.content_base64, "file content");
|
||||
input.set("content", Json(file.content_base64));
|
||||
}
|
||||
if (file.mime_type != "application/pdf" && file.mime_type != "image/tiff" && file.mime_type != "image/gif")
|
||||
throw GoogleError::invalid("mimeType must be application/pdf, image/tiff or image/gif");
|
||||
input.set("mimeType", Json(file.mime_type));
|
||||
Json req = Json::object();
|
||||
req.set("inputConfig", input);
|
||||
req.set("features", features_json(features));
|
||||
if (!file.pages.empty()) {
|
||||
if (file.pages.size() > 5) throw GoogleError::invalid("at most 5 pages");
|
||||
Json pages = Json::array();
|
||||
for (int p : file.pages) {
|
||||
if (p < 1 || p > 10000) throw GoogleError::invalid("page numbers are 1..10000");
|
||||
pages.push(Json(p));
|
||||
}
|
||||
req.set("pages", pages);
|
||||
}
|
||||
Json reqs = Json::array();
|
||||
reqs.push(req);
|
||||
Json b = Json::object();
|
||||
b.set("requests", reqs);
|
||||
return b;
|
||||
}
|
||||
|
||||
Json Vision::annotate_file(const FileAnnotation& file, const std::vector<VisionFeature>& features) const {
|
||||
Json b = annotate_file_body(file, features);
|
||||
return invoke(Call::kVisionFilesAnnotate, "", &b);
|
||||
}
|
||||
|
||||
Json Vision::list_product_sets() const {
|
||||
return list(Call::kVisionLocationsProductSetsList, parent(), "productSets");
|
||||
}
|
||||
Json Vision::get_product_set(const std::string& id) const {
|
||||
return invoke(Call::kVisionLocationsProductSetsGet, product_set_name(id));
|
||||
}
|
||||
Json Vision::list_products() const {
|
||||
return list(Call::kVisionLocationsProductsList, parent(), "products");
|
||||
}
|
||||
Json Vision::get_product(const std::string& id) const {
|
||||
return invoke(Call::kVisionLocationsProductsGet, product_name(id));
|
||||
}
|
||||
Json Vision::list_reference_images(const std::string& product_id) const {
|
||||
return list(Call::kVisionLocationsProductsReferenceImagesList, product_name(product_id), "referenceImages");
|
||||
}
|
||||
|
||||
Json Vision::create_product_set(const std::string& id, const std::string& display_name) const {
|
||||
if (display_name.empty() || display_name.size() > CloudAiCaps::kMaxDisplayChars)
|
||||
throw GoogleError::invalid("displayName: 1..128 chars");
|
||||
Json b = Json::object();
|
||||
b.set("displayName", Json(display_name));
|
||||
return invoke(Call::kVisionLocationsProductSetsCreate, parent(), &b,
|
||||
{{"productSetId", checked_id(id, "product set id")}});
|
||||
}
|
||||
Json Vision::delete_product_set(const std::string& id) const {
|
||||
return invoke(Call::kVisionLocationsProductSetsDelete, product_set_name(id));
|
||||
}
|
||||
Json Vision::create_product(const std::string& id, const std::string& display_name,
|
||||
const std::string& category) const {
|
||||
if (display_name.empty() || display_name.size() > CloudAiCaps::kMaxDisplayChars)
|
||||
throw GoogleError::invalid("displayName: 1..128 chars");
|
||||
if (category != "homegoods-v2" && category != "apparel-v2" && category != "toys-v2" &&
|
||||
category != "packagedgoods-v1" && category != "general-v1")
|
||||
throw GoogleError::invalid("category must be homegoods-v2, apparel-v2, toys-v2, packagedgoods-v1 or general-v1");
|
||||
Json b = Json::object();
|
||||
b.set("displayName", Json(display_name));
|
||||
b.set("productCategory", Json(category));
|
||||
return invoke(Call::kVisionLocationsProductsCreate, parent(), &b,
|
||||
{{"productId", checked_id(id, "product id")}});
|
||||
}
|
||||
Json Vision::delete_product(const std::string& id) const {
|
||||
return invoke(Call::kVisionLocationsProductsDelete, product_name(id));
|
||||
}
|
||||
|
||||
Operation Vision::get_operation(const std::string& name) const {
|
||||
return operation(Call::kVisionProjectsLocationsOperationsGet, name);
|
||||
}
|
||||
|
||||
Json Vision::call(Call c, const std::string& name, const Json* body, const Query& query) const {
|
||||
if (std::strcmp(spec(c).api, "vision") != 0) throw GoogleError::invalid("not a Vision call");
|
||||
return invoke(c, name, body, query);
|
||||
}
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
// Cloud Vision v1: image and file annotation (sync and async start),
|
||||
// product search resources (product sets, products, reference images).
|
||||
// Annotation is paid per image and feature.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "google/cloudai/cloudai_service.h"
|
||||
|
||||
namespace molo::google::cloudai {
|
||||
|
||||
struct VisionImage {
|
||||
std::string content_base64; // inline bytes, base64 (at most 10 MiB decoded)
|
||||
std::string uri; // gs:// or https:// instead of content
|
||||
};
|
||||
|
||||
struct VisionFeature {
|
||||
std::string type; // Feature.type enum, e.g. LABEL_DETECTION
|
||||
int max_results = 0; // 0: Google default; at most 100
|
||||
};
|
||||
|
||||
struct FileAnnotation {
|
||||
std::string gcs_uri; // gs:// PDF / TIFF / GIF
|
||||
std::string content_base64; // alternative to gcs_uri
|
||||
std::string mime_type; // application/pdf, image/tiff, image/gif
|
||||
std::vector<int> pages; // at most 5, 1-based
|
||||
};
|
||||
|
||||
class Vision : public CloudAiService {
|
||||
public:
|
||||
using CloudAiService::CloudAiService;
|
||||
|
||||
static bool valid_feature(const std::string& type);
|
||||
|
||||
clients::body::Json annotate_body(const std::vector<VisionImage>& images,
|
||||
const std::vector<VisionFeature>& features) const;
|
||||
// images:annotate (global endpoint). Returns the raw "responses" reply.
|
||||
clients::body::Json annotate(const std::vector<VisionImage>& images,
|
||||
const std::vector<VisionFeature>& features) const;
|
||||
|
||||
clients::body::Json annotate_file_body(const FileAnnotation& file,
|
||||
const std::vector<VisionFeature>& features) const;
|
||||
clients::body::Json annotate_file(const FileAnnotation& file,
|
||||
const std::vector<VisionFeature>& features) const;
|
||||
|
||||
// Product search reads.
|
||||
clients::body::Json list_product_sets() const;
|
||||
clients::body::Json get_product_set(const std::string& id) const;
|
||||
clients::body::Json list_products() const;
|
||||
clients::body::Json get_product(const std::string& id) const;
|
||||
clients::body::Json list_reference_images(const std::string& product_id) const;
|
||||
|
||||
// Product search writes: explicit, no defaults.
|
||||
clients::body::Json create_product_set(const std::string& id, const std::string& display_name) const;
|
||||
clients::body::Json delete_product_set(const std::string& id) const;
|
||||
clients::body::Json create_product(const std::string& id, const std::string& display_name,
|
||||
const std::string& category) const;
|
||||
clients::body::Json delete_product(const std::string& id) const;
|
||||
|
||||
Operation get_operation(const std::string& name) const;
|
||||
|
||||
clients::body::Json call(Call c, const std::string& name, const clients::body::Json* body = nullptr,
|
||||
const Query& query = {}) const;
|
||||
|
||||
std::string product_set_name(const std::string& id) const;
|
||||
std::string product_name(const std::string& id) const;
|
||||
};
|
||||
|
||||
} // namespace molo::google::cloudai
|
||||
Reference in New Issue
Block a user