mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 17:30:16 +01:00
31 lines
965 B
JavaScript
31 lines
965 B
JavaScript
|
|
const { PluginsClient } = require('../../../../app');
|
||
|
|
const { getAzureCredentials } = require('../../../../utils');
|
||
|
|
|
||
|
|
const initializeClient = (req, endpointOption) => {
|
||
|
|
const clientOptions = {
|
||
|
|
debug: true,
|
||
|
|
reverseProxyUrl: process.env.OPENAI_REVERSE_PROXY || null,
|
||
|
|
proxy: process.env.PROXY || null,
|
||
|
|
...endpointOption,
|
||
|
|
};
|
||
|
|
|
||
|
|
let openAIApiKey = req.body?.token ?? process.env.OPENAI_API_KEY;
|
||
|
|
if (process.env.PLUGINS_USE_AZURE) {
|
||
|
|
clientOptions.azure = getAzureCredentials();
|
||
|
|
openAIApiKey = clientOptions.azure.azureOpenAIApiKey;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (openAIApiKey && openAIApiKey.includes('azure') && !clientOptions.azure) {
|
||
|
|
clientOptions.azure = JSON.parse(req.body?.token) ?? getAzureCredentials();
|
||
|
|
openAIApiKey = clientOptions.azure.azureOpenAIApiKey;
|
||
|
|
}
|
||
|
|
const client = new PluginsClient(openAIApiKey, clientOptions);
|
||
|
|
return {
|
||
|
|
client,
|
||
|
|
azure: clientOptions.azure,
|
||
|
|
openAIApiKey,
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = initializeClient;
|