mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-07 00:15:23 +02:00
Merge 2925597365 into 8ed0bcf5ca
This commit is contained in:
commit
94810afde7
2 changed files with 24 additions and 1 deletions
|
|
@ -319,6 +319,23 @@ function getModelConfig(ocrConfig?: TCustomConfig['ocr']): string {
|
|||
return modelConfig.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region configuration for Vertex AI
|
||||
*/
|
||||
function getRegionConfig(ocrConfig?: TCustomConfig['ocr']): string | undefined {
|
||||
const regionConfig = ocrConfig?.region || '';
|
||||
|
||||
if (!regionConfig.trim()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (envVarRegex.test(regionConfig)) {
|
||||
return extractEnvVariable(regionConfig) || undefined;
|
||||
}
|
||||
|
||||
return regionConfig.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines document type based on file
|
||||
*/
|
||||
|
|
@ -608,15 +625,18 @@ async function performGoogleVertexOCR({
|
|||
accessToken,
|
||||
projectId,
|
||||
model,
|
||||
region,
|
||||
documentType = 'document_url',
|
||||
}: {
|
||||
url: string;
|
||||
accessToken: string;
|
||||
projectId: string;
|
||||
model: string;
|
||||
region?: string;
|
||||
documentType?: 'document_url' | 'image_url';
|
||||
}): Promise<OCRResult> {
|
||||
const location = process.env.GOOGLE_LOC || 'us-central1';
|
||||
// Priority: function parameter > MISTRAL_VERTEX_REGION > GOOGLE_LOC > default
|
||||
const location = region || process.env.MISTRAL_VERTEX_REGION || process.env.GOOGLE_LOC || 'us-central1';
|
||||
const modelId = model || 'mistral-ocr-2505';
|
||||
|
||||
let baseURL: string;
|
||||
|
|
@ -695,6 +715,7 @@ export const uploadGoogleVertexMistralOCR = async (
|
|||
try {
|
||||
const { serviceAccount, accessToken } = await loadGoogleAuthConfig();
|
||||
const model = getModelConfig(context.req.config?.ocr);
|
||||
const region = getRegionConfig(context.req.config?.ocr);
|
||||
|
||||
const { content: buffer } = await readFileAsBuffer(context.file.path, {
|
||||
fileSize: context.file.size,
|
||||
|
|
@ -708,6 +729,7 @@ export const uploadGoogleVertexMistralOCR = async (
|
|||
accessToken,
|
||||
projectId: serviceAccount.project_id!,
|
||||
model,
|
||||
region,
|
||||
documentType,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -976,6 +976,7 @@ export const ocrSchema = z.object({
|
|||
mistralModel: z.string().optional(),
|
||||
apiKey: z.string().optional().default('${OCR_API_KEY}'),
|
||||
baseURL: z.string().optional().default('${OCR_BASEURL}'),
|
||||
region: z.string().optional(),
|
||||
strategy: z.nativeEnum(OCRStrategy).default(OCRStrategy.MISTRAL_OCR),
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue