Support deepgram onprem (#398)

* Support deepgram onprem

* wip

* wip
This commit is contained in:
Hoan Luu Huu
2024-02-12 20:52:54 +07:00
committed by GitHub
parent 3a87f5f1c2
commit 9d2fee64e6
3 changed files with 96 additions and 3 deletions

View File

@@ -420,6 +420,8 @@ export interface SpeechCredential {
model: null | string; model: null | string;
options: null | string; options: null | string;
use_streaming: number; use_streaming: number;
deepgram_stt_uri: null | string;
deepgram_stt_use_tls: number;
} }
export interface Alert { export interface Alert {

View File

@@ -11,6 +11,7 @@ type CheckzoneProps = {
hidden?: boolean; hidden?: boolean;
children: React.ReactNode; children: React.ReactNode;
initialCheck: boolean; initialCheck: boolean;
disabled?: boolean;
handleChecked?: (e: React.ChangeEvent<HTMLInputElement>) => void; handleChecked?: (e: React.ChangeEvent<HTMLInputElement>) => void;
}; };
@@ -28,6 +29,7 @@ export const Checkzone = forwardRef<CheckzoneRef, CheckzoneProps>(
children, children,
initialCheck, initialCheck,
handleChecked, handleChecked,
disabled = false,
}: CheckzoneProps, }: CheckzoneProps,
ref ref
) => { ) => {
@@ -51,6 +53,7 @@ export const Checkzone = forwardRef<CheckzoneRef, CheckzoneProps>(
<label> <label>
<div className="label-container"> <div className="label-container">
<input <input
disabled={disabled}
ref={ref} ref={ref}
type="checkbox" type="checkbox"
name={name} name={name}

View File

@@ -48,6 +48,7 @@ import {
isUserAccountScope, isUserAccountScope,
isNotBlank, isNotBlank,
hasLength, hasLength,
hasValue,
} from "src/utils"; } from "src/utils";
import { getObscuredGoogleServiceKey } from "./utils"; import { getObscuredGoogleServiceKey } from "./utils";
import { CredentialStatus } from "./status"; import { CredentialStatus } from "./status";
@@ -145,6 +146,13 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
const [options, setOptions] = useState(""); const [options, setOptions] = useState("");
const [tmpOptions, setTmpOptions] = useState(""); const [tmpOptions, setTmpOptions] = useState("");
const [useStreaming, setUseStreaming] = useState(false); const [useStreaming, setUseStreaming] = useState(false);
const [deepgramSttUri, setDeepgramSttUri] = useState("");
const [tmpDeepgramSttUri, setTmpDeepgramSttUri] = useState("");
const [deepgramSttUseTls, setDeepgramSttUseTls] = useState(false);
const [tmpDeepgramSttUseTls, setTmpDeepgramSttUseTls] = useState(false);
const [initialDeepgramOnpremCheck, setInitialDeepgramOnpremCheck] =
useState(false);
const [isDeepgramOnpremEnabled, setIsDeepgramOnpremEnabled] = useState(false);
const handleFile = (file: File) => { const handleFile = (file: File) => {
const handleError = () => { const handleError = () => {
@@ -293,8 +301,12 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
...(vendor === VENDOR_ELEVENLABS && { ...(vendor === VENDOR_ELEVENLABS && {
options: options || null, options: options || null,
}), }),
...((vendor === VENDOR_ELEVENLABS || vendor === VENDOR_WHISPER) && { ...((vendor === VENDOR_ELEVENLABS /* || vendor === VENDOR_WHISPER */) && {
use_streaming: useStreaming ? 1 : 0, use_streaming: useStreaming ? 1 : 0
}),
...(vendor === VENDOR_DEEPGRAM && {
deepgram_stt_uri: deepgramSttUri || null,
deepgram_stt_use_tls: deepgramSttUseTls ? 1 : 0,
}), }),
}; };
@@ -551,6 +563,16 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
setUseCustomVoicesCheck(json.length > 0); setUseCustomVoicesCheck(json.length > 0);
}); });
} }
if (credential?.data?.deepgram_stt_uri) {
setDeepgramSttUri(credential.data.deepgram_stt_uri);
}
if (credential?.data?.deepgram_stt_use_tls) {
setDeepgramSttUseTls(
credential?.data?.deepgram_stt_use_tls > 0 ? true : false
);
}
setInitialDeepgramOnpremCheck(hasValue(credential?.data?.deepgram_stt_uri));
setIsDeepgramOnpremEnabled(hasValue(credential?.data?.deepgram_stt_uri));
}, [credential]); }, [credential]);
const updateCustomVoices = ( const updateCustomVoices = (
@@ -1133,7 +1155,6 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
</fieldset> </fieldset>
)} )}
{(vendor === VENDOR_WELLSAID || {(vendor === VENDOR_WELLSAID ||
vendor === VENDOR_DEEPGRAM ||
vendor === VENDOR_ASSEMBLYAI || vendor === VENDOR_ASSEMBLYAI ||
vendor == VENDOR_ELEVENLABS || vendor == VENDOR_ELEVENLABS ||
vendor === VENDOR_WHISPER || vendor === VENDOR_WHISPER ||
@@ -1153,6 +1174,22 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
/> />
</fieldset> </fieldset>
)} )}
{vendor === VENDOR_DEEPGRAM && (
<fieldset>
<label htmlFor={`${vendor}_apikey`}>
API key{!isDeepgramOnpremEnabled && <span>*</span>}
</label>
<Passwd
id={`${vendor}_apikey`}
required={!isDeepgramOnpremEnabled}
name={`${vendor}_apikey`}
placeholder="API key"
value={apiKey ? getObscuredSecret(apiKey) : apiKey}
onChange={(e) => setApiKey(e.target.value)}
disabled={credential ? true : false}
/>
</fieldset>
)}
{(vendor == VENDOR_ELEVENLABS || vendor == VENDOR_WHISPER) && {(vendor == VENDOR_ELEVENLABS || vendor == VENDOR_WHISPER) &&
ttsModels.length > 0 && ( ttsModels.length > 0 && (
<fieldset> <fieldset>
@@ -1345,6 +1382,57 @@ export const SpeechServiceForm = ({ credential }: SpeechServiceFormProps) => {
/> />
</fieldset> </fieldset>
)} )}
{vendor === VENDOR_DEEPGRAM && (
<fieldset>
<Checkzone
disabled={hasValue(credential)}
hidden
name="use_hosted_deepgram_service"
label="Use on-prem Deepgram container"
initialCheck={initialDeepgramOnpremCheck}
handleChecked={(e) => {
// setInitialDeepgramOnpremCheck(!e.target.checked);
setIsDeepgramOnpremEnabled(e.target.checked);
if (e.target.checked) {
if (tmpDeepgramSttUri) {
setDeepgramSttUri(tmpDeepgramSttUri);
}
if (tmpDeepgramSttUseTls) {
setDeepgramSttUseTls(tmpDeepgramSttUseTls);
}
} else {
setTmpDeepgramSttUri(deepgramSttUri);
setDeepgramSttUri("");
setTmpDeepgramSttUseTls(deepgramSttUseTls);
setDeepgramSttUseTls(false);
}
}}
>
<label htmlFor="deepgram_uri_for_tts">
Container URI<span>*</span>
</label>
<input
id="deepgram_uri_for_tts"
required
type="text"
name="deepgram_uri_for_tts"
placeholder="Container URI for TTS"
value={deepgramSttUri}
onChange={(e) => setDeepgramSttUri(e.target.value)}
/>
<label htmlFor="deepgram_tts_use_tls" className="chk">
<input
id="deepgram_tts_use_tls"
name="deepgram_tts_use_tls"
type="checkbox"
onChange={(e) => setDeepgramSttUseTls(e.target.checked)}
defaultChecked={deepgramSttUseTls}
/>
<div>Use TLS</div>
</label>
</Checkzone>
</fieldset>
)}
{vendor === VENDOR_MICROSOFT && ( {vendor === VENDOR_MICROSOFT && (
<React.Fragment> <React.Fragment>
<fieldset> <fieldset>