mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
28 lines
819 B
JavaScript
28 lines
819 B
JavaScript
|
|
const { OpenAIClient } = require('../../../../app');
|
||
|
|
const { getAzureCredentials } = require('../../../../utils');
|
||
|
|
|
||
|
|
const initializeClient = (req, endpointOption) => {
|
||
|
|
const clientOptions = {
|
||
|
|
// debug: true,
|
||
|
|
// contextStrategy: 'refine',
|
||
|
|
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.AZURE_API_KEY && endpointOption.endpoint === 'azureOpenAI') {
|
||
|
|
clientOptions.azure = JSON.parse(req.body?.token) ?? getAzureCredentials();
|
||
|
|
openAIApiKey = clientOptions.azure.azureOpenAIApiKey;
|
||
|
|
}
|
||
|
|
|
||
|
|
const client = new OpenAIClient(openAIApiKey, clientOptions);
|
||
|
|
return {
|
||
|
|
client,
|
||
|
|
openAIApiKey,
|
||
|
|
};
|
||
|
|
};
|
||
|
|
|
||
|
|
module.exports = initializeClient;
|