Skip to content

feat: add region configuration for Mistral OCR on Vertex AI#11539

Open
devanchohan wants to merge 2 commits intodanny-avila:mainfrom
devanchohan:feat/ocr-region-config
Open

feat: add region configuration for Mistral OCR on Vertex AI#11539
devanchohan wants to merge 2 commits intodanny-avila:mainfrom
devanchohan:feat/ocr-region-config

Conversation

@devanchohan
Copy link

Add separate region configuration for Mistral OCR to resolve conflicts with Gemini 3 models that require the global endpoint.

Changes:

  • Add region field to OCR schema in data-provider
  • Add MISTRAL_VERTEX_REGION environment variable support
  • Add getRegionConfig() helper function
  • Update performGoogleVertexOCR() to accept region parameter
  • Add region resolution logic with priority: config > MISTRAL_VERTEX_REGION > GOOGLE_LOC
  • Maintains full backward compatibility

This follows the pattern established by Anthropic Vertex AI configuration.

Pull Request Template

⚠️ Before Submitting a PR, Please Review:

  • Please ensure that you have thoroughly read and understood the Contributing Docs before submitting your Pull Request.

⚠️ Documentation Updates Notice:

  • Kindly note that documentation updates are managed in this repository: librechat.ai

Summary

Please provide a brief summary of your changes and the related issue. Include any motivation and context that is relevant to your changes. If there are any dependencies necessary for your changes, please list them here.

Change Type

Please delete any irrelevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Translation update

Testing

Please describe your test process and include instructions so that we can reproduce your test. If there are any important variables for your testing configuration, list them here.

Test Configuration:

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules.
  • A pull request for updating the documentation has been submitted.

Add separate region configuration for Mistral OCR to resolve conflicts with
Gemini 3 models that require the global endpoint.

Changes:
- Add `region` field to OCR schema in data-provider
- Add `MISTRAL_VERTEX_REGION` environment variable support
- Add `getRegionConfig()` helper function
- Update `performGoogleVertexOCR()` to accept region parameter
- Add region resolution logic with priority: config > MISTRAL_VERTEX_REGION > GOOGLE_LOC
- Maintains full backward compatibility

This follows the pattern established by Anthropic Vertex AI configuration.
Copilot AI review requested due to automatic review settings January 28, 2026 09:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit region configuration path for Google Vertex AI Mistral OCR to avoid conflicts with other Vertex model region requirements.

Changes:

  • Adds region to the OCR config schema (data-provider).
  • Introduces getRegionConfig() to resolve region from config/env placeholders.
  • Updates Vertex OCR call path to accept/use a region parameter with fallback precedence.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/data-provider/src/config.ts Extends OCR schema with a region field intended to support Mistral Vertex region configuration.
packages/api/src/files/mistral/crud.ts Adds region resolution helper and wires region into Vertex OCR request URL construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +323 to +335
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();
}
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRegionConfig() can return an unresolved env placeholder. extractEnvVariable('${MISTRAL_VERTEX_REGION}') returns the original string when the env var is missing (see extractEnvVariable implementation), and || undefined won’t remove it since the placeholder is truthy. This causes callers to treat '${...}' as a real region. After extracting, check envVarRegex on the resolved value and return undefined (or otherwise fall back) when it’s still unresolved.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +636 to +637
// Priority: function parameter > MISTRAL_VERTEX_REGION > GOOGLE_LOC > default
const location = region || process.env.MISTRAL_VERTEX_REGION || process.env.GOOGLE_LOC || 'us-central1';
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new region resolution path isn’t covered by tests in this module. Add unit tests that verify location selection precedence (explicit ocr.region string, ocr.region env placeholder with env set, fallback to MISTRAL_VERTEX_REGION, then GOOGLE_LOC, then default) and that unresolved placeholders are not used to build the Vertex endpoint URL.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant