Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

🧹 chore: Cleanup base64 Handling for Azure Mistral OCR (#7892)

Danny Avila0103b4b08a6e
diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.js
index be64d5a0e3..41e457e5b8 100644
--- a/api/server/controllers/agents/client.js
+++ b/api/server/controllers/agents/client.js
@@ -330,7 +330,7 @@ class AgentClient extends BaseClient {
if (mcpServers.length > 0) {
try {
- const mcpInstructions = await getMCPManager().formatInstructionsForContext(mcpServers);
+ const mcpInstructions = getMCPManager().formatInstructionsForContext(mcpServers);
if (mcpInstructions) {
systemContent = [systemContent, mcpInstructions].filter(Boolean).join('\n\n');
logger.debug('[AgentClient] Injected MCP instructions for servers:', mcpServers);
diff --git a/packages/api/src/files/mistral/crud.spec.ts b/packages/api/src/files/mistral/crud.spec.ts
index 173c60edf2..309e5565b6 100644
--- a/packages/api/src/files/mistral/crud.spec.ts
+++ b/packages/api/src/files/mistral/crud.spec.ts
@@ -1421,7 +1421,7 @@ describe('MistralOCR Service', () => {
expect.objectContaining({
document: expect.objectContaining({
type: 'document_url',
- document_url: expect.stringMatching(/^data:image\/jpeg;base64,/),
+ document_url: expect.stringMatching(/^data:application\/pdf;base64,/),
}),
}),
expect.any(Object),
diff --git a/packages/api/src/files/mistral/crud.ts b/packages/api/src/files/mistral/crud.ts
index 200cc85196..1d36459886 100644
--- a/packages/api/src/files/mistral/crud.ts
+++ b/packages/api/src/files/mistral/crud.ts
@@ -208,7 +208,6 @@ async function loadAuthConfig(context: OCRContext): Promise<AuthConfig> {
const apiKeyConfig = ocrConfig?.apiKey || '';
const baseURLConfig = ocrConfig?.baseURL || '';
- // If both are hardcoded, return them directly
if (!needsEnvLoad(apiKeyConfig) && !needsEnvLoad(baseURLConfig)) {
return {
apiKey: apiKeyConfig,
@@ -216,7 +215,6 @@ async function loadAuthConfig(context: OCRContext): Promise<AuthConfig> {
};
}
- // Build auth fields array
const authFields: string[] = [];
if (needsEnvLoad(baseURLConfig)) {
@@ -227,14 +225,12 @@ async function loadAuthConfig(context: OCRContext): Promise<AuthConfig> {
authFields.push(getEnvVarName(apiKeyConfig, 'OCR_API_KEY'));
}
- // Load auth values
const authValues = await context.loadAuthValues({
userId: context.req.user?.id || '',
authFields,
optional: new Set(['OCR_BASEURL']),
});
- // Resolve each value
const apiKey = await resolveConfigValue(apiKeyConfig, 'OCR_API_KEY', authValues);
const baseURL = await resolveConfigValue(
baseURLConfig,
@@ -335,7 +331,6 @@ export const uploadMistralOCR = async (context: OCRContext): Promise<MistralOCRU
const { apiKey, baseURL } = await loadAuthConfig(context);
const model = getModelConfig(context.req.app.locals?.ocr);
- // Upload file
const mistralFile = await uploadDocumentToMistral({
filePath: context.file.path,
fileName: context.file.originalname,
@@ -343,14 +338,12 @@ export const uploadMistralOCR = async (context: OCRContext): Promise<MistralOCRU
baseURL,
});
- // Get signed URL
const signedUrlResponse = await getSignedUrl({
apiKey,
baseURL,
fileId: mistralFile.id,
});
- // Perform OCR
const documentType = getDocumentType(context.file);
const ocrResult = await performOCR({
apiKey,
@@ -394,21 +387,20 @@ export const uploadAzureMistralOCR = async (
const { apiKey, baseURL } = await loadAuthConfig(context);
const model = getModelConfig(context.req.app.locals?.ocr);
- // Read file as base64
const buffer = fs.readFileSync(context.file.path);
const base64 = buffer.toString('base64');
+ /** Uses actual mimetype of the file, 'image/jpeg' as fallback since it seems to be accepted regardless of mismatch */
+ const base64Prefix = `data:${context.file.mimetype || 'image/jpeg'};base64,`;
- // Perform OCR directly with base64
const documentType = getDocumentType(context.file);
const ocrResult = await performOCR({
apiKey,
baseURL,
model,
- url: `data:image/jpeg;base64,${base64}`,
+ url: `${base64Prefix}${base64}`,
documentType,
});
- // Process result
const { text, images } = processOCRResult(ocrResult);
return {