Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

feat: use setModel as rest api already support it #330

Merged
merged 1 commit into from Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -98,8 +98,6 @@ public List<LanguagesResource> listSupportedLanguages(Map<Option, ?> optionMap)
@Override
public List<TranslationsResource> translate(List<String> texts, Map<Option, ?> optionMap) {
try {
// TODO use POST as soon as usage of "model" correctly reports an error in non-whitelisted
// projects
String targetLanguage =
firstNonNull(Option.TARGET_LANGUAGE.getString(optionMap), options.getTargetLanguage());
final String sourceLanguage = Option.SOURCE_LANGUAGE.getString(optionMap);
Expand All @@ -109,7 +107,7 @@ public List<TranslationsResource> translate(List<String> texts, Map<Option, ?> o
.list(texts, targetLanguage)
.setSource(sourceLanguage)
.setKey(options.getApiKey())
.set("model", Option.MODEL.getString(optionMap))
.setModel(Option.MODEL.getString(optionMap))
.setFormat(Option.FORMAT.getString(optionMap))
.execute()
.getTranslations();
Expand Down
Expand Up @@ -368,6 +368,19 @@ public void testTranslateListWithOptions() {
verify();
}

@Test
public void testTranslateTextListWithModel() {
String text = "Hallo Welt!";
List<String> texts = ImmutableList.of(text);
EasyMock.expect(
translateRpcMock.translate(texts, ImmutableMap.of(TranslateRpc.Option.MODEL, "nmt")))
.andReturn(ImmutableList.of(TRANSLATION2_PB));
EasyMock.replay(translateRpcMock);
initializeService();
assertEquals(ImmutableList.of(TRANSLATION2), translate.translate(texts, MODEL_OPTION));
verify();
}

@Test
public void testRetryableException() {
EasyMock.expect(translateRpcMock.listSupportedLanguages(EMPTY_RPC_OPTIONS))
Expand Down