mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-13 14:08:51 +01:00
WIP: app.locals refactoring
WIP: appConfig fix: update memory configuration retrieval to use getAppConfig based on user role fix: update comment for AppConfig interface to clarify purpose
This commit is contained in:
parent
5a14ee9c6a
commit
b992fed16c
66 changed files with 706 additions and 366 deletions
|
|
@ -46,7 +46,12 @@ import * as fs from 'fs';
|
|||
import axios from 'axios';
|
||||
import type { Request as ExpressRequest } from 'express';
|
||||
import type { Readable } from 'stream';
|
||||
import type { MistralFileUploadResponse, MistralSignedUrlResponse, OCRResult } from '~/types';
|
||||
import type {
|
||||
MistralFileUploadResponse,
|
||||
MistralSignedUrlResponse,
|
||||
OCRResult,
|
||||
AppConfig,
|
||||
} from '~/types';
|
||||
import { logger as mockLogger } from '@librechat/data-schemas';
|
||||
import {
|
||||
uploadDocumentToMistral,
|
||||
|
|
@ -497,18 +502,17 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
// Use environment variable syntax to ensure loadAuthValues is called
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-medium',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
// Use environment variable syntax to ensure loadAuthValues is called
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-medium',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -517,6 +521,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const result = await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -599,17 +604,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user456' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-medium',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-medium',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/image.png',
|
||||
originalname: 'image.png',
|
||||
|
|
@ -618,6 +622,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const result = await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -698,17 +703,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${CUSTOM_API_KEY}',
|
||||
baseURL: '${CUSTOM_BASEURL}',
|
||||
mistralModel: '${CUSTOM_MODEL}',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${CUSTOM_API_KEY}',
|
||||
baseURL: '${CUSTOM_BASEURL}',
|
||||
mistralModel: '${CUSTOM_MODEL}',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
// Set environment variable for model
|
||||
process.env.CUSTOM_MODEL = 'mistral-large';
|
||||
|
||||
|
|
@ -720,6 +724,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const result = await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -790,18 +795,17 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
// Use environment variable syntax to ensure loadAuthValues is called
|
||||
apiKey: '${INVALID_FORMAT}', // Using valid env var format but with an invalid name
|
||||
baseURL: '${OCR_BASEURL}', // Using valid env var format
|
||||
mistralModel: 'mistral-ocr-latest', // Plain string value
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
// Use environment variable syntax to ensure loadAuthValues is called
|
||||
apiKey: '${INVALID_FORMAT}', // Using valid env var format but with an invalid name
|
||||
baseURL: '${OCR_BASEURL}', // Using valid env var format
|
||||
mistralModel: 'mistral-ocr-latest', // Plain string value
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -810,6 +814,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -845,16 +850,15 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: 'OCR_API_KEY',
|
||||
baseURL: 'OCR_BASEURL',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: 'OCR_API_KEY',
|
||||
baseURL: 'OCR_BASEURL',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -864,6 +868,7 @@ describe('MistralOCR Service', () => {
|
|||
await expect(
|
||||
uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
}),
|
||||
|
|
@ -931,17 +936,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: 'OCR_API_KEY',
|
||||
baseURL: 'OCR_BASEURL',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: 'OCR_API_KEY',
|
||||
baseURL: 'OCR_BASEURL',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'single-page.pdf',
|
||||
|
|
@ -950,6 +954,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const result = await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1019,18 +1024,17 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
// Direct values that should be used as-is, without variable substitution
|
||||
apiKey: 'actual-api-key-value',
|
||||
baseURL: 'https://direct-api-url.mistral.ai/v1',
|
||||
mistralModel: 'mistral-direct-model',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
// Direct values that should be used as-is, without variable substitution
|
||||
apiKey: 'actual-api-key-value',
|
||||
baseURL: 'https://direct-api-url.mistral.ai/v1',
|
||||
mistralModel: 'mistral-direct-model',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'direct-values.pdf',
|
||||
|
|
@ -1039,6 +1043,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const result = await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1133,18 +1138,17 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
// Empty string values - should fall back to defaults
|
||||
apiKey: '',
|
||||
baseURL: '',
|
||||
mistralModel: '',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
// Empty string values - should fall back to defaults
|
||||
apiKey: '',
|
||||
baseURL: '',
|
||||
mistralModel: '',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'empty-config.pdf',
|
||||
|
|
@ -1153,6 +1157,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const result = await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1276,17 +1281,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${AZURE_MISTRAL_OCR_API_KEY}',
|
||||
baseURL: 'https://endpoint.models.ai.azure.com/v1',
|
||||
mistralModel: 'mistral-ocr-2503',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${AZURE_MISTRAL_OCR_API_KEY}',
|
||||
baseURL: 'https://endpoint.models.ai.azure.com/v1',
|
||||
mistralModel: 'mistral-ocr-2503',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1295,6 +1299,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1360,17 +1365,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user456' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: 'hardcoded-api-key-12345',
|
||||
baseURL: '${CUSTOM_OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: 'hardcoded-api-key-12345',
|
||||
baseURL: '${CUSTOM_OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1379,6 +1383,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1484,17 +1489,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1503,6 +1507,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1553,17 +1558,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1573,6 +1577,7 @@ describe('MistralOCR Service', () => {
|
|||
await expect(
|
||||
uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
}),
|
||||
|
|
@ -1641,17 +1646,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1661,6 +1665,7 @@ describe('MistralOCR Service', () => {
|
|||
// Should not throw even if delete fails
|
||||
const result = await uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1701,17 +1706,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1721,6 +1725,7 @@ describe('MistralOCR Service', () => {
|
|||
await expect(
|
||||
uploadMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
}),
|
||||
|
|
@ -1775,17 +1780,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${OCR_API_KEY}',
|
||||
baseURL: '${OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/azure-file.pdf',
|
||||
originalname: 'azure-document.pdf',
|
||||
|
|
@ -1794,6 +1798,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const result = await uploadAzureMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1851,17 +1856,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user123' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: '${AZURE_MISTRAL_OCR_API_KEY}',
|
||||
baseURL: 'https://endpoint.models.ai.azure.com/v1',
|
||||
mistralModel: 'mistral-ocr-2503',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: '${AZURE_MISTRAL_OCR_API_KEY}',
|
||||
baseURL: 'https://endpoint.models.ai.azure.com/v1',
|
||||
mistralModel: 'mistral-ocr-2503',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1870,6 +1874,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
await uploadAzureMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
@ -1915,17 +1920,16 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
const req = {
|
||||
user: { id: 'user456' },
|
||||
app: {
|
||||
locals: {
|
||||
ocr: {
|
||||
apiKey: 'hardcoded-api-key-12345',
|
||||
baseURL: '${CUSTOM_OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as unknown as ExpressRequest;
|
||||
|
||||
const appConfig = {
|
||||
ocr: {
|
||||
apiKey: 'hardcoded-api-key-12345',
|
||||
baseURL: '${CUSTOM_OCR_BASEURL}',
|
||||
mistralModel: 'mistral-ocr-latest',
|
||||
},
|
||||
} as AppConfig;
|
||||
|
||||
const file = {
|
||||
path: '/tmp/upload/file.pdf',
|
||||
originalname: 'document.pdf',
|
||||
|
|
@ -1934,6 +1938,7 @@ describe('MistralOCR Service', () => {
|
|||
|
||||
await uploadAzureMistralOCR({
|
||||
req,
|
||||
appConfig,
|
||||
file,
|
||||
loadAuthValues: mockLoadAuthValues,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import type {
|
|||
MistralOCRUploadResult,
|
||||
MistralOCRError,
|
||||
OCRResultPage,
|
||||
AppConfig,
|
||||
OCRResult,
|
||||
OCRImage,
|
||||
} from '~/types';
|
||||
|
|
@ -42,14 +43,10 @@ interface GoogleServiceAccount {
|
|||
|
||||
/** Helper type for OCR request context */
|
||||
interface OCRContext {
|
||||
req: Pick<ServerRequest, 'user' | 'app'> & {
|
||||
req: Pick<ServerRequest, 'user'> & {
|
||||
user?: { id: string };
|
||||
app: {
|
||||
locals?: {
|
||||
ocr?: TCustomConfig['ocr'];
|
||||
};
|
||||
};
|
||||
};
|
||||
appConfig: AppConfig;
|
||||
file: Express.Multer.File;
|
||||
loadAuthValues: (params: {
|
||||
userId: string;
|
||||
|
|
@ -241,7 +238,7 @@ async function resolveConfigValue(
|
|||
* Loads authentication configuration from OCR config
|
||||
*/
|
||||
async function loadAuthConfig(context: OCRContext): Promise<AuthConfig> {
|
||||
const ocrConfig = context.req.app.locals?.ocr;
|
||||
const ocrConfig = context.appConfig?.ocr;
|
||||
const apiKeyConfig = ocrConfig?.apiKey || '';
|
||||
const baseURLConfig = ocrConfig?.baseURL || '';
|
||||
|
||||
|
|
@ -357,6 +354,7 @@ function createOCRError(error: unknown, baseMessage: string): Error {
|
|||
* @param params - The params object.
|
||||
* @param params.req - The request object from Express. It should have a `user` property with an `id`
|
||||
* representing the user
|
||||
* @param params.appConfig - Application configuration object
|
||||
* @param params.file - The file object, which is part of the request. The file object should
|
||||
* have a `mimetype` property that tells us the file type
|
||||
* @param params.loadAuthValues - Function to load authentication values
|
||||
|
|
@ -372,7 +370,7 @@ export const uploadMistralOCR = async (context: OCRContext): Promise<MistralOCRU
|
|||
const authConfig = await loadAuthConfig(context);
|
||||
apiKey = authConfig.apiKey;
|
||||
baseURL = authConfig.baseURL;
|
||||
const model = getModelConfig(context.req.app.locals?.ocr);
|
||||
const model = getModelConfig(context.appConfig?.ocr);
|
||||
|
||||
const mistralFile = await uploadDocumentToMistral({
|
||||
filePath: context.file.path,
|
||||
|
|
@ -430,6 +428,7 @@ export const uploadMistralOCR = async (context: OCRContext): Promise<MistralOCRU
|
|||
* @param params - The params object.
|
||||
* @param params.req - The request object from Express. It should have a `user` property with an `id`
|
||||
* representing the user
|
||||
* @param params.appConfig - Application configuration object
|
||||
* @param params.file - The file object, which is part of the request. The file object should
|
||||
* have a `mimetype` property that tells us the file type
|
||||
* @param params.loadAuthValues - Function to load authentication values
|
||||
|
|
@ -441,7 +440,7 @@ export const uploadAzureMistralOCR = async (
|
|||
): Promise<MistralOCRUploadResult> => {
|
||||
try {
|
||||
const { apiKey, baseURL } = await loadAuthConfig(context);
|
||||
const model = getModelConfig(context.req.app.locals?.ocr);
|
||||
const model = getModelConfig(context.appConfig?.ocr);
|
||||
|
||||
const buffer = fs.readFileSync(context.file.path);
|
||||
const base64 = buffer.toString('base64');
|
||||
|
|
@ -644,6 +643,7 @@ async function performGoogleVertexOCR({
|
|||
* @param params - The params object.
|
||||
* @param params.req - The request object from Express. It should have a `user` property with an `id`
|
||||
* representing the user
|
||||
* @param params.appConfig - Application configuration object
|
||||
* @param params.file - The file object, which is part of the request. The file object should
|
||||
* have a `mimetype` property that tells us the file type
|
||||
* @param params.loadAuthValues - Function to load authentication values
|
||||
|
|
@ -655,7 +655,7 @@ export const uploadGoogleVertexMistralOCR = async (
|
|||
): Promise<MistralOCRUploadResult> => {
|
||||
try {
|
||||
const { serviceAccount, accessToken } = await loadGoogleAuthConfig();
|
||||
const model = getModelConfig(context.req.app.locals?.ocr);
|
||||
const model = getModelConfig(context.appConfig?.ocr);
|
||||
|
||||
const buffer = fs.readFileSync(context.file.path);
|
||||
const base64 = buffer.toString('base64');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue