Skip to content

Commit

Permalink
🛠️ feat: Azure OpenAI Assistants File Downloads (#3653)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored Aug 15, 2024
1 parent 741e3e8 commit bcde0be
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch LibreChat (debug)",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/api/server/index.js",
"env": {
"NODE_ENV": "production"
},
"console": "integratedTerminal"
}
]
}
19 changes: 16 additions & 3 deletions api/server/routes/files/files.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const fs = require('fs').promises;
const express = require('express');
const { isUUID, checkOpenAIStorage } = require('librechat-data-provider');
const {
isUUID,
checkOpenAIStorage,
FileSources,
EModelEndpoint,
} = require('librechat-data-provider');
const {
filterFile,
processFileUpload,
processDeleteRequest,
} = require('~/server/services/Files/process');
const { initializeClient } = require('~/server/services/Endpoints/assistants');
const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const { getOpenAIClient } = require('~/server/controllers/assistants/helpers');
const { getFiles } = require('~/models/File');
const { logger } = require('~/config');

Expand Down Expand Up @@ -113,7 +118,15 @@ router.get('/download/:userId/:file_id', async (req, res) => {

if (checkOpenAIStorage(file.source)) {
req.body = { model: file.model };
const { openai } = await initializeClient({ req, res });
const endpointMap = {
[FileSources.openai]: EModelEndpoint.assistants,
[FileSources.azure]: EModelEndpoint.azureAssistants,
};
const { openai } = await getOpenAIClient({
req,
res,
overrideEndpoint: endpointMap[file.source],
});
logger.debug(`Downloading file ${file_id} from OpenAI`);
passThrough = await getDownloadStream(file_id, openai);
setHeaders();
Expand Down

0 comments on commit bcde0be

Please sign in to comment.