Here’s my code:
private static void adaptiveMtTranslate(
TranslationServiceClient translationServiceClient,
String projectId,
String location,
String datasetId,
List<String> content) {
String adaptiveMtDatasetName = String.format("projects/%s/locations/%s/adaptiveMtDatasets/%s",
projectId, location, datasetId);
AdaptiveMtTranslateRequest request = AdaptiveMtTranslateRequest.newBuilder()
.setParent(LocationName.of(projectId, location).toString())
.setDataset(adaptiveMtDatasetName)
.addAllContent(content)
.build();
AdaptiveMtTranslateResponse response = translationServiceClient.adaptiveMtTranslate(request);
for (AdaptiveMtTranslation translation : response.getTranslationsList()) {
System.out.println(translation.getTranslatedText());
}
}
When I pass a List<String> with multiple entries as the content parameter, I get the following error:
{
"error": {
"code": 400,
"message": "Request should not have more than 1 entries",
"status": "INVALID_ARGUMENT"
}
}
I’ve referred to the official API documentation and the Java client library documentation, and both seem to indicate that passing a list of strings is supported.
Am I missing something, or is this a limitation in the current implementation of the API's AdaptiveMtTranslateRequest? If passing multiple strings isn't supported, is there a recommended way to batch translations without sending one request per sentence?
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |