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

Commit

Permalink
fix: use setModel as rest api already support it (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
athakor committed Oct 30, 2020
1 parent ef7d7c8 commit de5b5a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit de5b5a8

Please sign in to comment.