This commit is contained in:
devanchohan 2026-04-05 02:26:13 +00:00 committed by GitHub
commit 94810afde7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -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,
});

View file

@ -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),
});