Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${okhttp-version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
10 changes: 5 additions & 5 deletions common/src/main/java/com/skyflow/BaseSkyflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.skyflow.config.Credentials;
import com.skyflow.enums.LogLevel;
import com.skyflow.errors.ErrorCode;
import com.skyflow.errors.ErrorMessage;
import com.skyflow.errors.BaseErrorMessage;
import com.skyflow.errors.SkyflowException;
import com.skyflow.logs.ErrorLogs;
import com.skyflow.logs.InfoLogs;
Expand Down Expand Up @@ -66,7 +66,7 @@ public LogLevel getLogLevel() {
}

protected static <T> T resolveOrThrow(Map<String, T> map, String key,
ErrorLogs errorLog, ErrorMessage errorMessage) throws SkyflowException {
ErrorLogs errorLog, BaseErrorMessage errorMessage) throws SkyflowException {
T value = key != null ? map.get(key) : map.values().stream().findFirst().orElse(null);
if (value == null) {
// The log line carries a %s1 placeholder for the id. Callers that resolve the single
Expand Down Expand Up @@ -125,7 +125,7 @@ protected final void addVaultConfigTemplate(V vaultConfig) throws SkyflowExcepti
ErrorLogs.VAULT_CONFIG_EXISTS.getLog(), vaultId
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(),
ErrorMessage.VaultIdAlreadyInConfigList.getMessage());
BaseErrorMessage.VaultIdAlreadyInConfigList.getMessage());
}
onVaultConfigAdded(vaultConfigCopy);
this.vaultConfigMap.put(vaultId, vaultConfigCopy);
Expand All @@ -139,7 +139,7 @@ protected final void updateVaultConfigTemplate(V vaultConfig) throws SkyflowExce
LogUtil.printErrorLog(BaseUtils.parameterizedString(
ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST.getLog(), vaultId
));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), BaseErrorMessage.VaultIdNotInConfigList.getMessage());
}
V previousConfig = this.vaultConfigMap.get(vaultId);
V merged = mergeVaultConfig(vaultConfig, cloneVaultConfig(previousConfig));
Expand All @@ -150,7 +150,7 @@ protected final void updateVaultConfigTemplate(V vaultConfig) throws SkyflowExce
protected final void removeVaultConfigTemplate(String vaultId) throws SkyflowException {
if (!hasVaultClient(vaultId)) {
LogUtil.printErrorLog(BaseUtils.parameterizedString(ErrorLogs.VAULT_CONFIG_DOES_NOT_EXIST.getLog(), vaultId));
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.VaultIdNotInConfigList.getMessage());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), BaseErrorMessage.VaultIdNotInConfigList.getMessage());
}
onVaultConfigRemoved(vaultId);
this.vaultConfigMap.remove(vaultId);
Expand Down
8 changes: 4 additions & 4 deletions common/src/main/java/com/skyflow/BaseVaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.skyflow.config.BaseCredentials;
import com.skyflow.config.BaseVaultConfig;
import com.skyflow.errors.ErrorCode;
import com.skyflow.errors.ErrorMessage;
import com.skyflow.errors.BaseErrorMessage;
import com.skyflow.errors.SkyflowException;
import com.skyflow.logs.ErrorLogs;
import com.skyflow.logs.InfoLogs;
Expand All @@ -25,7 +25,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

class BaseVaultClient<V extends BaseVaultConfig> {
public class BaseVaultClient<V extends BaseVaultConfig> {
protected V vaultConfig;
protected OkHttpClient sharedHttpClient;
protected String currentVaultURL;
Expand Down Expand Up @@ -69,7 +69,7 @@ protected synchronized void prioritiseCredentials(BaseCredentials vaultSpecificC
sysCredentials = dotenv.get(BaseConstants.ENV_CREDENTIALS_KEY_NAME);
}
if (sysCredentials == null) {
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyCredentials.getMessage());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), BaseErrorMessage.EmptyCredentials.getMessage());
} else {
this.finalCredentials = new BaseCredentials();
this.finalCredentials.setCredentialsString(sysCredentials);
Expand All @@ -80,7 +80,7 @@ protected synchronized void prioritiseCredentials(BaseCredentials vaultSpecificC
apiKey = null;
}
} catch (DotenvException e) {
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), ErrorMessage.EmptyCredentials.getMessage());
throw new SkyflowException(ErrorCode.INVALID_INPUT.getCode(), BaseErrorMessage.EmptyCredentials.getMessage());
} catch (SkyflowException e) {
throw e;
} catch (Exception e) {
Expand Down
93 changes: 93 additions & 0 deletions common/src/main/java/com/skyflow/detect/Audio.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.skyflow.detect;

/**
* Audio processing options.
*/
public final class Audio {
private final Boolean outputProcessedAudio;
private final OutputTranscriptionType outputTranscription;
private final Bleep bleep;

private Audio(AudioBuilder builder) {
this.outputProcessedAudio = builder.outputProcessedAudio;
this.outputTranscription = builder.outputTranscription;
this.bleep = builder.bleep;
}

/**
* @return a new builder
*/
public static AudioBuilder builder() {
return new AudioBuilder();
}

/**
* @return Whether to return the processed audio file.
*/
public Boolean getOutputProcessedAudio() {
return outputProcessedAudio;
}

/**
* @return Transcription output to produce.
*/
public OutputTranscriptionType getOutputTranscription() {
return outputTranscription;
}

/**
* @return Bleep configuration.
*/
public Bleep getBleep() {
return bleep;
}

@Override
public String toString() {
return "Audio{" +
"outputProcessedAudio=" + outputProcessedAudio +
", outputTranscription=" + outputTranscription +
", bleep=" + bleep +
'}';
}

public static final class AudioBuilder {
private Boolean outputProcessedAudio;
private OutputTranscriptionType outputTranscription;
private Bleep bleep;

private AudioBuilder() {
}

/**
* @param outputProcessedAudio Whether to return the processed audio file.
* @return this builder
*/
public AudioBuilder outputProcessedAudio(Boolean outputProcessedAudio) {
this.outputProcessedAudio = outputProcessedAudio;
return this;
}

/**
* @param outputTranscription Transcription output to produce.
* @return this builder
*/
public AudioBuilder outputTranscription(OutputTranscriptionType outputTranscription) {
this.outputTranscription = outputTranscription;
return this;
}

/**
* @param bleep Bleep configuration.
* @return this builder
*/
public AudioBuilder bleep(Bleep bleep) {
this.bleep = bleep;
return this;
}

public Audio build() {
return new Audio(this);
}
}
}
113 changes: 113 additions & 0 deletions common/src/main/java/com/skyflow/detect/Bleep.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.skyflow.detect;

/**
* Bleep tone applied over detected speech in audio.
*/
public final class Bleep {
private final Float startPadding;
private final Float stopPadding;
private final Integer frequency;
private final Integer gain;

private Bleep(BleepBuilder builder) {
this.startPadding = builder.startPadding;
this.stopPadding = builder.stopPadding;
this.frequency = builder.frequency;
this.gain = builder.gain;
}

/**
* @return a new builder
*/
public static BleepBuilder builder() {
return new BleepBuilder();
}

/**
* @return Seconds of bleep added before the detected span.
*/
public Float getStartPadding() {
return startPadding;
}

/**
* @return Seconds of bleep added after the detected span.
*/
public Float getStopPadding() {
return stopPadding;
}

/**
* @return Bleep frequency in Hz.
*/
public Integer getFrequency() {
return frequency;
}

/**
* @return Bleep gain.
*/
public Integer getGain() {
return gain;
}

@Override
public String toString() {
return "Bleep{" +
"startPadding=" + startPadding +
", stopPadding=" + stopPadding +
", frequency=" + frequency +
", gain=" + gain +
'}';
}

public static final class BleepBuilder {
private Float startPadding;
private Float stopPadding;
private Integer frequency;
private Integer gain;

private BleepBuilder() {
}

/**
* @param startPadding Seconds of bleep added before the detected span.
* @return this builder
*/
public BleepBuilder startPadding(Float startPadding) {
this.startPadding = startPadding;
return this;
}

/**
* @param stopPadding Seconds of bleep added after the detected span.
* @return this builder
*/
public BleepBuilder stopPadding(Float stopPadding) {
this.stopPadding = stopPadding;
return this;
}

/**
* @param frequency Bleep frequency in Hz.
* @return this builder
*/
public BleepBuilder frequency(Integer frequency) {
this.frequency = frequency;
return this;
}

/**
* @param gain Bleep gain.
* @return this builder
*/
public BleepBuilder gain(Integer gain) {
this.gain = gain;
return this;
}

public Bleep build() {
return new Bleep(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.skyflow.detect;

import java.util.List;

/**
* Request for {@code checkGuardrails}: screens text for toxicity and denied topics.
*/
public final class CheckGuardrailsRequest {
private final String text;
private final Boolean checkToxicity;
private final List<String> denyTopics;

private CheckGuardrailsRequest(CheckGuardrailsRequestBuilder builder) {
this.text = builder.text;
this.checkToxicity = builder.checkToxicity;
this.denyTopics = builder.denyTopics;
}

/**
* @return a new builder
*/
public static CheckGuardrailsRequestBuilder builder() {
return new CheckGuardrailsRequestBuilder();
}

/**
* @return Text to screen. Required.
*/
public String getText() {
return text;
}

/**
* @return Whether to check the text for toxicity.
*/
public Boolean getCheckToxicity() {
return checkToxicity;
}

/**
* @return Topics the text must not discuss.
*/
public List<String> getDenyTopics() {
return denyTopics;
}

@Override
public String toString() {
return "CheckGuardrailsRequest{" +
"text=" + text +
", checkToxicity=" + checkToxicity +
", denyTopics=" + denyTopics +
'}';
}

public static final class CheckGuardrailsRequestBuilder {
private String text;
private Boolean checkToxicity;
private List<String> denyTopics;

private CheckGuardrailsRequestBuilder() {
}

/**
* @param text Text to screen. Required.
* @return this builder
*/
public CheckGuardrailsRequestBuilder text(String text) {
this.text = text;
return this;
}

/**
* @param checkToxicity Whether to check the text for toxicity.
* @return this builder
*/
public CheckGuardrailsRequestBuilder checkToxicity(Boolean checkToxicity) {
this.checkToxicity = checkToxicity;
return this;
}

/**
* @param denyTopics Topics the text must not discuss.
* @return this builder
*/
public CheckGuardrailsRequestBuilder denyTopics(List<String> denyTopics) {
this.denyTopics = denyTopics;
return this;
}

public CheckGuardrailsRequest build() {
return new CheckGuardrailsRequest(this);
}
}
}
Loading
Loading