mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-21 21:50:49 +02:00
🔧 fix: Upload Audio as Text missing Param (#9356)
This commit is contained in:
parent
b75b799e34
commit
7742b18c9c
4 changed files with 23 additions and 8 deletions
|
@ -616,7 +616,7 @@ const processAgentFileUpload = async ({ req, res, metadata }) => {
|
|||
|
||||
if (shouldUseSTT) {
|
||||
const sttService = await STTService.getInstance();
|
||||
const { text, bytes } = await processAudioFile({ file, sttService });
|
||||
const { text, bytes } = await processAudioFile({ req, file, sttService });
|
||||
return await createTextFile({ text, bytes });
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,23 @@
|
|||
import fs from 'fs';
|
||||
import { logger } from '@librechat/data-schemas';
|
||||
import type { STTService, AudioFileInfo, FileObject, AudioProcessingResult } from '~/types';
|
||||
import type {
|
||||
AudioProcessingResult,
|
||||
ServerRequest,
|
||||
AudioFileInfo,
|
||||
STTService,
|
||||
FileObject,
|
||||
} from '~/types';
|
||||
|
||||
/**
|
||||
* Processes audio files using Speech-to-Text (STT) service.
|
||||
* @param {Object} params - The parameters object.
|
||||
* @param {FileObject} params.file - The audio file object.
|
||||
* @param {STTService} params.sttService - The STT service instance.
|
||||
* @returns {Promise<AudioProcessingResult>} A promise that resolves to an object containing text and bytes.
|
||||
* @returns A promise that resolves to an object containing text and bytes.
|
||||
*/
|
||||
export async function processAudioFile({
|
||||
req,
|
||||
file,
|
||||
sttService,
|
||||
}: {
|
||||
req: ServerRequest;
|
||||
file: FileObject;
|
||||
sttService: STTService;
|
||||
}): Promise<AudioProcessingResult> {
|
||||
|
@ -24,7 +29,7 @@ export async function processAudioFile({
|
|||
size: file.size,
|
||||
};
|
||||
|
||||
const [provider, sttSchema] = await sttService.getProviderSchema();
|
||||
const [provider, sttSchema] = await sttService.getProviderSchema(req);
|
||||
const text = await sttService.sttRequest(provider, sttSchema, { audioBuffer, audioFile });
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import type { ServerRequest } from './http';
|
||||
export interface STTService {
|
||||
getInstance(): Promise<STTService>;
|
||||
getProviderSchema(): Promise<[string, object]>;
|
||||
getProviderSchema(req: ServerRequest): Promise<[string, object]>;
|
||||
sttRequest(
|
||||
provider: string,
|
||||
schema: object,
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
import type { Request } from 'express';
|
||||
import type { IUser } from '@librechat/data-schemas';
|
||||
import type { AppConfig } from './config';
|
||||
|
||||
/**
|
||||
* LibreChat-specific request body type that extends Express Request body
|
||||
* (have to use type alias because you can't extend indexed access types like Request['body'])
|
||||
|
@ -7,3 +11,8 @@ export type RequestBody = {
|
|||
conversationId?: string;
|
||||
parentMessageId?: string;
|
||||
};
|
||||
|
||||
export type ServerRequest = Request & {
|
||||
user?: IUser;
|
||||
config?: AppConfig;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue