Skip to content

Commit 5f2d1c5

Browse files
๐Ÿ‘๏ธ feat: Azure Mistral OCR Strategy (danny-avila#7888)
* ๐Ÿ‘๏ธ feat: Add Azure Mistral OCR strategy and endpoint integration This commit introduces a new OCR strategy named 'azure_mistral_ocr', allowing the use of a Mistral OCR endpoint deployed on Azure. The configuration, schemas, and file upload strategies have been updated to support this integration, enabling seamless OCR processing via Azure-hosted Mistral services. * ๐Ÿ—‘๏ธ chore: Clean up .gitignore by removing commented-out uncommon directory name * chore: remove unused vars * refactor: Move createAxiosInstance to packages/api/utils and update imports - Removed the createAxiosInstance function from the config module and relocated it to a new utils module for better organization. - Updated import paths in relevant files to reflect the new location of createAxiosInstance. - Added tests for createAxiosInstance to ensure proper functionality and proxy configuration handling. * chore: move axios helpers to packages/api - Added logAxiosError function to @librechat/api for centralized error logging. - Updated imports across various files to use the new logAxiosError function. - Removed the old axios.js utility file as it is no longer needed. * chore: Update Jest moduleNameMapper for improved path resolution - Added a new mapping for '~/' to resolve module paths in Jest configuration, enhancing import handling for the project. * feat: Implement Mistral OCR API integration in TS * chore: Update MistralOCR tests based on new imports * fix: Enhance MistralOCR configuration handling and tests - Introduced helper functions for resolving configuration values from environment variables or hardcoded settings. - Updated the uploadMistralOCR and uploadAzureMistralOCR functions to utilize the new configuration resolution logic. - Improved test cases to ensure correct behavior when mixing environment variables and hardcoded values. - Mocked file upload and signed URL responses in tests to validate functionality without external dependencies. * feat: Enhance MistralOCR functionality with improved configuration and error handling - Introduced helper functions for loading authentication configuration and resolving values from environment variables. - Updated uploadMistralOCR and uploadAzureMistralOCR functions to utilize the new configuration logic. - Added utility functions for processing OCR results and creating error messages. - Improved document type determination and result aggregation for better OCR processing. * refactor: Reorganize OCR type imports in Mistral CRUD file - Moved OCRResult, OCRResultPage, and OCRImage imports to a more logical grouping for better readability and maintainability. * feat: Add file exports to API and create files index * chore: Update OCR types for enhanced structure and clarity - Redesigned OCRImage interface to include mandatory fields and improved naming conventions. - Added PageDimensions interface for better representation of page metrics. - Updated OCRResultPage to include dimensions and mandatory images array. - Refined OCRResult to include document annotation and usage information. * refactor: use TS counterpart of uploadOCR methods * ci: Update MistralOCR tests to reflect new OCR result structure * chore: Bump version of @librechat/api to 1.2.3 in package.json and package-lock.json * chore: Update CONFIG_VERSION to 1.2.8 * chore: remove unused sendEvent function from config module (now imported from '@librechat/api') * chore: remove MistralOCR service files and tests (now in '@librechat/api') * ci: update logger import in ModelService tests to use @librechat/data-schemas --------- Co-authored-by: arthurolivierfortin <[email protected]>
1 parent 46ff008 commit 5f2d1c5

37 files changed

+2245
-1235
lines changed

โ€Žapi/app/clients/OllamaClient.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const { z } = require('zod');
22
const axios = require('axios');
33
const { Ollama } = require('ollama');
4+
const { sleep } = require('@librechat/agents');
5+
const { logAxiosError } = require('@librechat/api');
6+
const { logger } = require('@librechat/data-schemas');
47
const { Constants } = require('librechat-data-provider');
5-
const { deriveBaseURL, logAxiosError } = require('~/utils');
6-
const { sleep } = require('~/server/utils');
7-
const { logger } = require('~/config');
8+
const { deriveBaseURL } = require('~/utils');
89

910
const ollamaPayloadSchema = z.object({
1011
mirostat: z.number().optional(),
@@ -67,7 +68,7 @@ class OllamaClient {
6768
return models;
6869
} catch (error) {
6970
const logMessage =
70-
'Failed to fetch models from Ollama API. If you are not using Ollama directly, and instead, through some aggregator or reverse proxy that handles fetching via OpenAI spec, ensure the name of the endpoint doesn\'t start with `ollama` (case-insensitive).';
71+
"Failed to fetch models from Ollama API. If you are not using Ollama directly, and instead, through some aggregator or reverse proxy that handles fetching via OpenAI spec, ensure the name of the endpoint doesn't start with `ollama` (case-insensitive).";
7172
logAxiosError({ message: logMessage, error });
7273
return [];
7374
}

โ€Žapi/app/clients/tools/structured/OpenAIImageTools.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ const { v4 } = require('uuid');
44
const OpenAI = require('openai');
55
const FormData = require('form-data');
66
const { tool } = require('@langchain/core/tools');
7+
const { logAxiosError } = require('@librechat/api');
8+
const { logger } = require('@librechat/data-schemas');
79
const { HttpsProxyAgent } = require('https-proxy-agent');
810
const { ContentTypes, EImageOutputType } = require('librechat-data-provider');
911
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
10-
const { logAxiosError, extractBaseURL } = require('~/utils');
12+
const { extractBaseURL } = require('~/utils');
1113
const { getFiles } = require('~/models/File');
12-
const { logger } = require('~/config');
1314

1415
/** Default descriptions for image generation tool */
1516
const DEFAULT_IMAGE_GEN_DESCRIPTION = `

โ€Žapi/config/index.js

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const axios = require('axios');
21
const { EventSource } = require('eventsource');
32
const { Time } = require('librechat-data-provider');
43
const { MCPManager, FlowStateManager } = require('@librechat/api');
@@ -37,60 +36,8 @@ function getFlowStateManager(flowsCache) {
3736
return flowManager;
3837
}
3938

40-
/**
41-
* Sends message data in Server Sent Events format.
42-
* @param {ServerResponse} res - The server response.
43-
* @param {{ data: string | Record<string, unknown>, event?: string }} event - The message event.
44-
* @param {string} event.event - The type of event.
45-
* @param {string} event.data - The message to be sent.
46-
*/
47-
const sendEvent = (res, event) => {
48-
if (typeof event.data === 'string' && event.data.length === 0) {
49-
return;
50-
}
51-
res.write(`event: message\ndata: ${JSON.stringify(event)}\n\n`);
52-
};
53-
54-
/**
55-
* Creates and configures an Axios instance with optional proxy settings.
56-
*
57-
* @typedef {import('axios').AxiosInstance} AxiosInstance
58-
* @typedef {import('axios').AxiosProxyConfig} AxiosProxyConfig
59-
*
60-
* @returns {AxiosInstance} A configured Axios instance
61-
* @throws {Error} If there's an issue creating the Axios instance or parsing the proxy URL
62-
*/
63-
function createAxiosInstance() {
64-
const instance = axios.create();
65-
66-
if (process.env.proxy) {
67-
try {
68-
const url = new URL(process.env.proxy);
69-
70-
/** @type {AxiosProxyConfig} */
71-
const proxyConfig = {
72-
host: url.hostname.replace(/^\[|\]$/g, ''),
73-
protocol: url.protocol.replace(':', ''),
74-
};
75-
76-
if (url.port) {
77-
proxyConfig.port = parseInt(url.port, 10);
78-
}
79-
80-
instance.defaults.proxy = proxyConfig;
81-
} catch (error) {
82-
console.error('Error parsing proxy URL:', error);
83-
throw new Error(`Invalid proxy URL: ${process.env.proxy}`);
84-
}
85-
}
86-
87-
return instance;
88-
}
89-
9039
module.exports = {
9140
logger,
92-
sendEvent,
9341
getMCPManager,
94-
createAxiosInstance,
9542
getFlowStateManager,
9643
};

โ€Žapi/server/services/ActionService.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const jwt = require('jsonwebtoken');
22
const { nanoid } = require('nanoid');
3-
const { sendEvent } = require('@librechat/api');
43
const { tool } = require('@langchain/core/tools');
54
const { logger } = require('@librechat/data-schemas');
65
const { GraphEvents, sleep } = require('@librechat/agents');
6+
const { sendEvent, logAxiosError } = require('@librechat/api');
77
const {
88
Time,
99
CacheKeys,
@@ -19,7 +19,6 @@ const { encryptV2, decryptV2 } = require('~/server/utils/crypto');
1919
const { getActions, deleteActions } = require('~/models/Action');
2020
const { deleteAssistant } = require('~/models/Assistant');
2121
const { getFlowStateManager } = require('~/config');
22-
const { logAxiosError } = require('~/utils');
2322
const { getLogStores } = require('~/cache');
2423
const { findToken } = require('~/models');
2524

โ€Žapi/server/services/Files/Code/crud.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const FormData = require('form-data');
22
const { getCodeBaseURL } = require('@librechat/agents');
3-
const { createAxiosInstance } = require('~/config');
4-
const { logAxiosError } = require('~/utils');
3+
const { createAxiosInstance, logAxiosError } = require('@librechat/api');
54

65
const axios = createAxiosInstance();
76

โ€Žapi/server/services/Files/Code/process.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const path = require('path');
22
const { v4 } = require('uuid');
33
const axios = require('axios');
4+
const { logAxiosError } = require('@librechat/api');
5+
const { logger } = require('@librechat/data-schemas');
46
const { getCodeBaseURL } = require('@librechat/agents');
57
const {
68
Tools,
@@ -12,8 +14,6 @@ const {
1214
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
1315
const { convertImage } = require('~/server/services/Files/images/convert');
1416
const { createFile, getFiles, updateFile } = require('~/models/File');
15-
const { logAxiosError } = require('~/utils');
16-
const { logger } = require('~/config');
1717

1818
/**
1919
* Process OpenAI image files, convert to target format, save and return file metadata.

โ€Žapi/server/services/Files/MistralOCR/crud.js

Lines changed: 0 additions & 238 deletions
This file was deleted.

0 commit comments

Comments
ย (0)