From 4b98b0a22b72e50c422d576b4144394d68707b29 Mon Sep 17 00:00:00 2001
From: Kirill Bykov <140751079+kirillatrev@users.noreply.github.com>
Date: Thu, 4 Jan 2024 10:50:54 -0600
Subject: [PATCH] REVAI-3919:Split NlpModel to have separate enums for
Translation and Summarization (#63)
https://revinc.atlassian.net/browse/REVAI-3919
---
README.md | 2 +-
examples/AsyncSummarizeMediaUrl.java | 2 +-
examples/AsyncTranslateMediaUrl.java | 2 +-
pom.xml | 2 +-
.../java/ai/rev/speechtotext/ApiClient.java | 7 +----
.../models/asynchronous/Summarization.java | 9 +++---
.../asynchronous/SummarizationModel.java | 30 +++++++++++++++++++
.../asynchronous/SummarizationOptions.java | 11 ++++---
.../asynchronous/TranslationLanguage.java | 7 ++---
.../TranslationLanguageOptions.java | 11 ++++---
.../TranslationModel.java} | 8 ++---
.../integration/SubmitJobTest.java | 17 +++++------
12 files changed, 63 insertions(+), 45 deletions(-)
create mode 100644 src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationModel.java
rename src/main/java/ai/rev/speechtotext/models/{NlpModel.java => asynchronous/TranslationModel.java} (76%)
diff --git a/README.md b/README.md
index b53a38d..139d672 100755
--- a/README.md
+++ b/README.md
@@ -207,7 +207,7 @@ int channelId = 1;
InputStream inputStream = apiClient.getCaptions(revAiJob.getJobId(), RevAiCaptionType.VTT, channelId);
// or if you requested transcript translation(s)
-InputStream inputStream = apiClient.getTranslatedCaptions(revAiJob.getJobId(), "es", RevAiCaptionType.VTT, channelId);
+InputStream inputStream = apiClient.getTranslatedCaptions(revAiJob.getJobId(), "es", RevAiCaptionType.VTT);
```
### Getting transcript summary
diff --git a/examples/AsyncSummarizeMediaUrl.java b/examples/AsyncSummarizeMediaUrl.java
index 188ab1f..81108dc 100644
--- a/examples/AsyncSummarizeMediaUrl.java
+++ b/examples/AsyncSummarizeMediaUrl.java
@@ -28,7 +28,7 @@ public static void main(String[] args) {
revAiJobOptions.setSourceConfig(mediaUrl, null);
revAiJobOptions.setDeleteAfterSeconds(2592000); // 30 days in seconds
revAiJobOptions.setLanguage("en");
- revAiJobOptions.setSummarizationOptions(new SummarizationOptions().setModel(NlpModel.STANDARD));
+ revAiJobOptions.setSummarizationOptions(new SummarizationOptions().setModel(SummarizationModel.STANDARD));
RevAiJob submittedJob;
diff --git a/examples/AsyncTranslateMediaUrl.java b/examples/AsyncTranslateMediaUrl.java
index 91844b1..919912a 100644
--- a/examples/AsyncTranslateMediaUrl.java
+++ b/examples/AsyncTranslateMediaUrl.java
@@ -30,7 +30,7 @@ public static void main(String[] args) {
revAiJobOptions.setLanguage("en");
revAiJobOptions.setTranslationOptions(new TranslationOptions(Arrays.asList(
new TranslationLanguageOptions("es")
- .setModel(NlpModel.PREMIUM),
+ .setModel(TranslationModel.PREMIUM),
new TranslationLanguageOptions("de"))
));
diff --git a/pom.xml b/pom.xml
index c890d13..07a711c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
ai.rev
revai-java-sdk
- 2.4.0
+ 2.4.1
Rev AI SDK for Java
Java SDK for Rev AI API
https://docs.rev.ai/
diff --git a/src/main/java/ai/rev/speechtotext/ApiClient.java b/src/main/java/ai/rev/speechtotext/ApiClient.java
index d6312bb..619dec4 100755
--- a/src/main/java/ai/rev/speechtotext/ApiClient.java
+++ b/src/main/java/ai/rev/speechtotext/ApiClient.java
@@ -438,23 +438,18 @@ public InputStream getCaptions(String id, RevAiCaptionType captionType, Integer
* @param id The ID of the job to return captions for.
* @param language requested translation language.
* @param captionType An enumeration of the desired caption type. Default is SRT.
- * @param channelId Identifies the audio channel of the file to output captions for. Default is
- * null.
* @return InputStream A stream of bytes that represents the caption output.
* @throws IOException If the response has a status code > 399.
* @throws IllegalArgumentException If the job ID provided is null.
* @see https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions
*/
- public InputStream getTranslatedCaptions(String id, String language, RevAiCaptionType captionType, Integer channelId)
+ public InputStream getTranslatedCaptions(String id, String language, RevAiCaptionType captionType)
throws IOException {
if (id == null) {
throw new IllegalArgumentException("Job ID must be provided");
}
Map query = new HashMap<>();
- if (channelId != null) {
- query.put("speaker_channel", channelId.toString());
- }
if (captionType == null) {
captionType = RevAiCaptionType.SRT;
}
diff --git a/src/main/java/ai/rev/speechtotext/models/asynchronous/Summarization.java b/src/main/java/ai/rev/speechtotext/models/asynchronous/Summarization.java
index add8483..dddeb6c 100644
--- a/src/main/java/ai/rev/speechtotext/models/asynchronous/Summarization.java
+++ b/src/main/java/ai/rev/speechtotext/models/asynchronous/Summarization.java
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;
-import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;
/**
@@ -15,10 +14,10 @@ public class Summarization {
/**
* Summarization model.
*
- * @see NlpModel
+ * @see TranslationModel
*/
@SerializedName("model")
- private NlpModel model;
+ private TranslationModel model;
/** Formatting options. Default is Paragraph. */
@SerializedName("type")
@@ -56,9 +55,9 @@ public String getPrompt() {
* Returns backend model used for the summarization job.
*
* @return Backend model used for the summarization job.
- * @see NlpModel
+ * @see TranslationModel
*/
- public NlpModel getModel() {
+ public TranslationModel getModel() {
return model;
}
diff --git a/src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationModel.java b/src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationModel.java
new file mode 100644
index 0000000..9cdd8d2
--- /dev/null
+++ b/src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationModel.java
@@ -0,0 +1,30 @@
+package ai.rev.speechtotext.models.asynchronous;
+
+import com.google.gson.annotations.SerializedName;
+
+/** Supported model types for summarization. */
+public enum SummarizationModel {
+
+ @SerializedName("standard")
+ STANDARD("standard"),
+ @SerializedName("premium")
+ PREMIUM("premium");
+
+ private final String model;
+
+ SummarizationModel(String model) {
+ this.model = model;
+ }
+
+ /**
+ * Returns the String value of the enumeration.
+ *
+ * @return The String value of the enumeration.
+ */
+ public String getModel() { return model; }
+
+ @Override
+ public String toString() {
+ return "{" + "model='" + model + '\'' + '}';
+ }
+}
diff --git a/src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationOptions.java b/src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationOptions.java
index d9688d2..c645a8e 100644
--- a/src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationOptions.java
+++ b/src/main/java/ai/rev/speechtotext/models/asynchronous/SummarizationOptions.java
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;
-import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;
/**
@@ -18,7 +17,7 @@ public class SummarizationOptions {
/** Standard or Premium AI backend. */
@SerializedName("model")
- private NlpModel model;
+ private SummarizationModel model;
/** Formatting options. Default is Paragraph. */
@SerializedName("type")
@@ -47,9 +46,9 @@ public SummarizationOptions setPrompt(String prompt) {
* Returns backend model used for the summarization job.
*
* @return Backend model used for the summarization job.
- * @see NlpModel
+ * @see TranslationModel
*/
- public NlpModel getModel() {
+ public SummarizationModel getModel() {
return model;
}
@@ -57,9 +56,9 @@ public NlpModel getModel() {
* Sets backend model used for the summarization job.
*
* @param model Backend model used for the summarization job.
- * @see NlpModel
+ * @see SummarizationModel
*/
- public SummarizationOptions setModel(NlpModel model) {
+ public SummarizationOptions setModel(SummarizationModel model) {
this.model = model;
return this;
}
diff --git a/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguage.java b/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguage.java
index b034ae3..d353cf4 100644
--- a/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguage.java
+++ b/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguage.java
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;
-import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;
/**
@@ -11,7 +10,7 @@
public class TranslationLanguage {
/** Standard or Premium AI backend. */
@SerializedName("model")
- private NlpModel model;
+ private TranslationModel model;
@SerializedName("language")
private String language;
@@ -26,9 +25,9 @@ public class TranslationLanguage {
* Returns backend model used for the summarization job.
*
* @return Backend model used for the summarization job.
- * @see NlpModel
+ * @see TranslationModel
*/
- public NlpModel getModel() {
+ public TranslationModel getModel() {
return model;
}
diff --git a/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguageOptions.java b/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguageOptions.java
index 146fa70..4d86675 100644
--- a/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguageOptions.java
+++ b/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationLanguageOptions.java
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;
-import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;
/**
@@ -13,7 +12,7 @@
public class TranslationLanguageOptions {
/** Standard or Premium AI backend. */
@SerializedName("model")
- private NlpModel model;
+ private TranslationModel model;
@SerializedName("language")
private final String language;
@@ -22,9 +21,9 @@ public class TranslationLanguageOptions {
* Returns backend model used for the summarization job.
*
* @return Backend model used for the summarization job.
- * @see NlpModel
+ * @see TranslationModel
*/
- public NlpModel getModel() {
+ public TranslationModel getModel() {
return model;
}
@@ -32,9 +31,9 @@ public NlpModel getModel() {
* Sets backend model to use for the summarization job.
*
* @param model Backend model to use for the summarization job
- * @see NlpModel
+ * @see TranslationModel
*/
- public TranslationLanguageOptions setModel(NlpModel model) {
+ public TranslationLanguageOptions setModel(TranslationModel model) {
this.model = model;
return this;
}
diff --git a/src/main/java/ai/rev/speechtotext/models/NlpModel.java b/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationModel.java
similarity index 76%
rename from src/main/java/ai/rev/speechtotext/models/NlpModel.java
rename to src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationModel.java
index 36f6ad8..8f18058 100644
--- a/src/main/java/ai/rev/speechtotext/models/NlpModel.java
+++ b/src/main/java/ai/rev/speechtotext/models/asynchronous/TranslationModel.java
@@ -1,9 +1,9 @@
-package ai.rev.speechtotext.models;
+package ai.rev.speechtotext.models.asynchronous;
import com.google.gson.annotations.SerializedName;
-/** Supported model types for NLP tasks like summarization. */
-public enum NlpModel {
+/** Supported model types for translation. */
+public enum TranslationModel {
@SerializedName("standard")
STANDARD("standard"),
@@ -12,7 +12,7 @@ public enum NlpModel {
private final String model;
- NlpModel(String model) {
+ TranslationModel(String model) {
this.model = model;
}
diff --git a/src/test/java/ai/rev/speechtotext/integration/SubmitJobTest.java b/src/test/java/ai/rev/speechtotext/integration/SubmitJobTest.java
index b1e48b3..2f4856a 100644
--- a/src/test/java/ai/rev/speechtotext/integration/SubmitJobTest.java
+++ b/src/test/java/ai/rev/speechtotext/integration/SubmitJobTest.java
@@ -1,7 +1,7 @@
package ai.rev.speechtotext.integration;
import ai.rev.speechtotext.ApiClient;
-import ai.rev.speechtotext.models.NlpModel;
+import ai.rev.speechtotext.models.asynchronous.TranslationModel;
import ai.rev.speechtotext.models.asynchronous.*;
import ai.rev.testutils.EnvHelper;
import org.junit.Before;
@@ -10,10 +10,7 @@
import org.junit.rules.TestName;
import java.io.*;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
-import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
@@ -169,13 +166,13 @@ public void SubmitJobLocalFile_SummarizationOptionsSpecified_ReturnsRevAiJobInPr
revAiJobOptions.setSummarizationOptions(new SummarizationOptions()
.setType(SummarizationFormattingOptions.BULLETS)
- .setModel(NlpModel.PREMIUM)
+ .setModel(SummarizationModel.PREMIUM)
.setPrompt("Try to summarize this transcript as good as you possibly can")
);
revAiJobOptions.setTranslationOptions(new TranslationOptions(Arrays.asList(
new TranslationLanguageOptions("es")
- .setModel(NlpModel.PREMIUM),
+ .setModel(TranslationModel.PREMIUM),
new TranslationLanguageOptions("ru")
)));
@@ -184,7 +181,7 @@ public void SubmitJobLocalFile_SummarizationOptionsSpecified_ReturnsRevAiJobInPr
assertThat(revAiJob.toString()).isNotNull();
assertRevAiJob(revAiJob);
assertThat(revAiJob.getSummarization()).isNotNull();
- assertThat(revAiJob.getSummarization().getModel()).isEqualTo(NlpModel.PREMIUM);
+ assertThat(revAiJob.getSummarization().getModel()).isEqualTo(TranslationModel.PREMIUM);
assertThat(revAiJob.getSummarization().getType()).isEqualTo(SummarizationFormattingOptions.BULLETS);
assertThat(revAiJob.getSummarization().getPrompt()).isEqualTo("Try to summarize this transcript as good as you possibly can");
@@ -208,7 +205,7 @@ public void SubmitJobLocalFile_SummarizationOptionsSpecified_ReturnsRevAiJobInPr
assertThat(revAiJob.getTranslation().getCompletedOn()).isNotNull();
assertThat(revAiJob.getTranslation().getTargetLanguages().get(0).getJobStatus()).isEqualTo(TranslationJobStatus.COMPLETED);
assertThat(revAiJob.getTranslation().getTargetLanguages().get(0).getLanguage()).isEqualTo("es");
- assertThat(revAiJob.getTranslation().getTargetLanguages().get(0).getModel()).isEqualTo(NlpModel.PREMIUM);
+ assertThat(revAiJob.getTranslation().getTargetLanguages().get(0).getModel()).isEqualTo(TranslationModel.PREMIUM);
assertThat(revAiJob.getTranslation().getTargetLanguages().get(1).getJobStatus()).isEqualTo(TranslationJobStatus.COMPLETED);
@@ -231,9 +228,9 @@ public void SubmitJobLocalFile_SummarizationOptionsSpecified_ReturnsRevAiJobInPr
RevAiTranscript translationObject2 = apiClient.getTranslatedTranscriptObject(revAiJob.getJobId(),"ru");
assertThat(translationObject2).isNotNull();
- InputStream translatedCaptionsStream1 = apiClient.getTranslatedCaptions(revAiJob.getJobId(),"es",RevAiCaptionType.SRT,0);
+ InputStream translatedCaptionsStream1 = apiClient.getTranslatedCaptions(revAiJob.getJobId(),"es",RevAiCaptionType.SRT);
assertThat(translatedCaptionsStream1).isNotNull();
- InputStream translatedCaptionsStream2 = apiClient.getTranslatedCaptions(revAiJob.getJobId(),"ru",RevAiCaptionType.SRT,0);
+ InputStream translatedCaptionsStream2 = apiClient.getTranslatedCaptions(revAiJob.getJobId(),"ru",RevAiCaptionType.SRT);
assertThat(translatedCaptionsStream2).isNotNull();
}
public void assertRevAiJob(RevAiJob revAiJob) {