| import getStream from 'get-stream'; |
| import { Providers } from '@librechat/agents'; |
| import { FileSources, mergeFileConfig, getEndpointFileConfig } from 'librechat-data-provider'; |
| import type { IMongoFile } from '@librechat/data-schemas'; |
| import type { ServerRequest, StrategyFunctions, ProcessedFile } from '~/types'; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export const getConfiguredFileSizeLimit = ( |
| req: ServerRequest, |
| params: { |
| provider: Providers; |
| endpoint?: string; |
| }, |
| ): number | undefined => { |
| if (!req.config?.fileConfig) { |
| return undefined; |
| } |
| const { provider, endpoint } = params; |
| const fileConfig = mergeFileConfig(req.config.fileConfig); |
| const endpointConfig = getEndpointFileConfig({ |
| fileConfig, |
| endpoint: endpoint ?? provider, |
| }); |
| return endpointConfig?.fileSizeLimit; |
| }; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export async function getFileStream( |
| req: ServerRequest, |
| file: IMongoFile, |
| encodingMethods: Record<string, StrategyFunctions>, |
| getStrategyFunctions: (source: string) => StrategyFunctions, |
| ): Promise<ProcessedFile | null> { |
| if (!file?.filepath) { |
| return null; |
| } |
|
|
| const source = file.source ?? FileSources.local; |
| if (!encodingMethods[source]) { |
| encodingMethods[source] = getStrategyFunctions(source); |
| } |
|
|
| const { getDownloadStream } = encodingMethods[source]; |
| const stream = await getDownloadStream(req, file.filepath); |
| const buffer = await getStream.buffer(stream); |
|
|
| return { |
| file, |
| content: buffer.toString('base64'), |
| metadata: { |
| file_id: file.file_id, |
| temp_file_id: file.temp_file_id, |
| filepath: file.filepath, |
| source: file.source, |
| filename: file.filename, |
| type: file.type, |
| }, |
| }; |
| } |
|
|