Skip to content

Commit

Permalink
REVAI-3919:Split NlpModel to have separate enums for Translation and …
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillatrev authored Jan 4, 2024
1 parent a8ca699 commit 4b98b0a
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/AsyncSummarizeMediaUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion examples/AsyncTranslateMediaUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
));

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- groupId, artifactId, these namespaces should not be changed -->
<groupId>ai.rev</groupId>
<artifactId>revai-java-sdk</artifactId>
<version>2.4.0</version>
<version>2.4.1</version>
<name>Rev AI SDK for Java</name>
<description>Java SDK for Rev AI API</description>
<url>https://docs.rev.ai/</url>
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/ai/rev/speechtotext/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a
* href="https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions">https://docs.rev.ai/api/asynchronous/reference/#operation/GetCaptions</a>
*/
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<String, String> query = new HashMap<>();
if (channelId != null) {
query.put("speaker_channel", channelId.toString());
}
if (captionType == null) {
captionType = RevAiCaptionType.SRT;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;

import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -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")
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 + '\'' + '}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;

import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -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")
Expand Down Expand Up @@ -47,19 +46,19 @@ 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;
}

/**
* 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;

import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ai.rev.speechtotext.models.asynchronous;

import ai.rev.speechtotext.models.NlpModel;
import com.google.gson.annotations.SerializedName;

/**
Expand All @@ -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;
Expand All @@ -22,19 +21,19 @@ 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;
}

/**
* 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -12,7 +12,7 @@ public enum NlpModel {

private final String model;

NlpModel(String model) {
TranslationModel(String model) {
this.model = model;
}

Expand Down
17 changes: 7 additions & 10 deletions src/test/java/ai/rev/speechtotext/integration/SubmitJobTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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")
)));

Expand All @@ -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");

Expand All @@ -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);

Expand All @@ -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) {
Expand Down

0 comments on commit 4b98b0a

Please sign in to comment.