mirror of https://github.com/FlowiseAI/Flowise.git
Fix for Whisper Error: 'File is not defined' when using Speech to Text (#2526)
* tested ok * update localai stt file * update toFile method for OpenAI Assistant uploads --------- Co-authored-by: Henry Heng <henryheng@flowiseai.com> Co-authored-by: Henry <hzj94@hotmail.com>pull/2531/head
parent
059eae4268
commit
eb738a1552
|
|
@ -1,6 +1,6 @@
|
|||
import { ICommonObject, IFileUpload } from './Interface'
|
||||
import { getCredentialData } from './utils'
|
||||
import { type ClientOptions, OpenAIClient } from '@langchain/openai'
|
||||
import { type ClientOptions, OpenAIClient, toFile } from '@langchain/openai'
|
||||
import { AssemblyAI } from 'assemblyai'
|
||||
import { getFileFromStorage } from './storageUtils'
|
||||
|
||||
|
|
@ -22,8 +22,9 @@ export const convertSpeechToText = async (upload: IFileUpload, speechToTextConfi
|
|||
apiKey: credentialData.openAIApiKey
|
||||
}
|
||||
const openAIClient = new OpenAIClient(openAIClientOptions)
|
||||
const file = await toFile(audio_file, upload.name)
|
||||
const openAITranscription = await openAIClient.audio.transcriptions.create({
|
||||
file: new File([new Blob([audio_file])], upload.name),
|
||||
file: file,
|
||||
model: 'whisper-1',
|
||||
language: speechToTextConfig?.language,
|
||||
temperature: speechToTextConfig?.temperature ? parseFloat(speechToTextConfig.temperature) : undefined,
|
||||
|
|
@ -56,8 +57,9 @@ export const convertSpeechToText = async (upload: IFileUpload, speechToTextConfi
|
|||
baseURL: speechToTextConfig?.baseUrl
|
||||
}
|
||||
const localAIClient = new OpenAIClient(LocalAIClientOptions)
|
||||
const file = await toFile(audio_file, upload.name)
|
||||
const localAITranscription = await localAIClient.audio.transcriptions.create({
|
||||
file: new File([new Blob([audio_file])], upload.name),
|
||||
file: file,
|
||||
model: speechToTextConfig?.model || 'whisper-1',
|
||||
language: speechToTextConfig?.language,
|
||||
temperature: speechToTextConfig?.temperature ? parseFloat(speechToTextConfig.temperature) : undefined,
|
||||
|
|
|
|||
|
|
@ -178,8 +178,9 @@ const uploadFilesToAssistantVectorStore = async (
|
|||
const openai = new OpenAI({ apiKey: openAIApiKey })
|
||||
const uploadedFiles = []
|
||||
for (const file of files) {
|
||||
const toFile = await OpenAI.toFile(fs.readFileSync(file.filePath), file.fileName)
|
||||
const createdFile = await openai.files.create({
|
||||
file: new File([new Blob([fs.readFileSync(file.filePath)])], file.fileName),
|
||||
file: toFile,
|
||||
purpose: 'assistants'
|
||||
})
|
||||
uploadedFiles.push(createdFile)
|
||||
|
|
|
|||
|
|
@ -101,8 +101,9 @@ const uploadFilesToAssistant = async (credentialId: string, files: { filePath: s
|
|||
const uploadedFiles = []
|
||||
|
||||
for (const file of files) {
|
||||
const toFile = await OpenAI.toFile(fs.readFileSync(file.filePath), file.fileName)
|
||||
const createdFile = await openai.files.create({
|
||||
file: new File([new Blob([fs.readFileSync(file.filePath)])], file.fileName),
|
||||
file: toFile,
|
||||
purpose: 'assistants'
|
||||
})
|
||||
uploadedFiles.push(createdFile)
|
||||
|
|
|
|||
Loading…
Reference in New Issue