Fix local state sync issue, STT auth issue, and add none option for speech to text

This commit is contained in:
Ilango
2024-02-20 23:29:14 +05:30
parent 8bad360796
commit 97a376d6e2
3 changed files with 116 additions and 92 deletions
+2
View File
@@ -1530,6 +1530,7 @@ export class App {
if (chatflow.speechToText) { if (chatflow.speechToText) {
const speechToTextProviders = JSON.parse(chatflow.speechToText) const speechToTextProviders = JSON.parse(chatflow.speechToText)
for (const provider in speechToTextProviders) { for (const provider in speechToTextProviders) {
if (provider !== 'none') {
const providerObj = speechToTextProviders[provider] const providerObj = speechToTextProviders[provider]
if (providerObj.status) { if (providerObj.status) {
isSpeechToTextEnabled = true isSpeechToTextEnabled = true
@@ -1537,6 +1538,7 @@ export class App {
} }
} }
} }
}
let isImageUploadAllowed = false let isImageUploadAllowed = false
const nodes: IReactFlowNode[] = flowObj.nodes const nodes: IReactFlowNode[] = flowObj.nodes
@@ -175,7 +175,16 @@ const SpeechToTextDialog = ({ show, dialogProps, onCancel }) => {
useEffect(() => { useEffect(() => {
if (dialogProps.chatflow && dialogProps.chatflow.speechToText) { if (dialogProps.chatflow && dialogProps.chatflow.speechToText) {
try { try {
setSpeechToText(JSON.parse(dialogProps.chatflow.speechToText)) const speechToText = JSON.parse(dialogProps.chatflow.speechToText)
let selectedProvider = 'none'
Object.keys(speechToTextProviders).forEach((key) => {
const providerConfig = speechToText[key]
if (providerConfig.status) {
selectedProvider = key
}
})
setSelectedProvider(selectedProvider)
setSpeechToText(speechToText)
} catch (e) { } catch (e) {
setSpeechToText({}) setSpeechToText({})
console.error(e) console.error(e)
@@ -193,7 +202,7 @@ const SpeechToTextDialog = ({ show, dialogProps, onCancel }) => {
return () => dispatch({ type: HIDE_CANVAS_DIALOG }) return () => dispatch({ type: HIDE_CANVAS_DIALOG })
}, [show, dispatch]) }, [show, dispatch])
const component = show ? ( const component = (
<Dialog <Dialog
onClose={onCancel} onClose={onCancel}
open={show} open={show}
@@ -210,11 +219,13 @@ const SpeechToTextDialog = ({ show, dialogProps, onCancel }) => {
<Typography>Speech To Text Providers</Typography> <Typography>Speech To Text Providers</Typography>
<FormControl fullWidth> <FormControl fullWidth>
<Select value={selectedProvider} onChange={handleProviderChange}> <Select value={selectedProvider} onChange={handleProviderChange}>
<MenuItem value='none'>None</MenuItem>
<MenuItem value='openAIWhisper'>OpenAI Whisper</MenuItem> <MenuItem value='openAIWhisper'>OpenAI Whisper</MenuItem>
<MenuItem value='assemblyAiTranscribe'>Assembly AI</MenuItem> <MenuItem value='assemblyAiTranscribe'>Assembly AI</MenuItem>
</Select> </Select>
</FormControl> </FormControl>
</Box> </Box>
{selectedProvider !== 'none' && (
<> <>
<ListItem style={{ padding: 0, margin: 0 }} alignItems='center'> <ListItem style={{ padding: 0, margin: 0 }} alignItems='center'>
<ListItemAvatar> <ListItemAvatar>
@@ -261,7 +272,11 @@ const SpeechToTextDialog = ({ show, dialogProps, onCancel }) => {
</div> </div>
{inputParam.type === 'credential' && ( {inputParam.type === 'credential' && (
<CredentialInputHandler <CredentialInputHandler
data={speechToText[selectedProvider] ? { credential: speechToText[selectedProvider].credentialId } : {}} data={
speechToText[selectedProvider]
? { credential: speechToText[selectedProvider].credentialId }
: {}
}
inputParam={inputParam} inputParam={inputParam}
onSelect={(newValue) => setValue(newValue, selectedProvider, 'credentialId')} onSelect={(newValue) => setValue(newValue, selectedProvider, 'credentialId')}
/> />
@@ -303,6 +318,7 @@ const SpeechToTextDialog = ({ show, dialogProps, onCancel }) => {
</Box> </Box>
))} ))}
</> </>
)}
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<StyledButton variant='contained' onClick={onSave}> <StyledButton variant='contained' onClick={onSave}>
@@ -310,7 +326,7 @@ const SpeechToTextDialog = ({ show, dialogProps, onCancel }) => {
</StyledButton> </StyledButton>
</DialogActions> </DialogActions>
</Dialog> </Dialog>
) : null )
return createPortal(component, portalElement) return createPortal(component, portalElement)
} }
@@ -48,6 +48,12 @@ export const Input = ({ inputParam, value, nodes, edges, nodeId, onChange, disab
} }
}, [myValue]) }, [myValue])
useEffect(() => {
if (value) {
setMyValue(value)
}
}, [value])
return ( return (
<> <>
{inputParam.name === 'note' ? ( {inputParam.name === 'note' ? (