mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
This commit adds support for generating Azure OpenAI API endpoints in the `chatgpt-client.js` and `titleConvo.js` files. The `genAzureEndpoint` function in `genAzureEndpoints.js` generates the endpoint URL based on the provided parameters. The `chatgpt-client.js` and `titleConvo.js` files now use this function to generate the endpoint URL when the `AZURE_OPENAI_API_KEY` environment variable is set.
66 lines
1.6 KiB
JavaScript
66 lines
1.6 KiB
JavaScript
require('dotenv').config();
|
|
const { KeyvFile } = require('keyv-file');
|
|
const { genAzureEndpoint } = require('../../utils/genAzureEndpoints');
|
|
|
|
const askClient = async ({
|
|
text,
|
|
parentMessageId,
|
|
conversationId,
|
|
model,
|
|
chatGptLabel,
|
|
promptPrefix,
|
|
temperature,
|
|
top_p,
|
|
presence_penalty,
|
|
frequency_penalty,
|
|
onProgress,
|
|
abortController,
|
|
userId
|
|
}) => {
|
|
const { ChatGPTClient } = await import('@waylaidwanderer/chatgpt-api');
|
|
const store = {
|
|
store: new KeyvFile({ filename: './data/cache.json' })
|
|
};
|
|
|
|
const azure = process.env.AZURE_OPENAI_API_KEY ? true : false;
|
|
|
|
const clientOptions = {
|
|
reverseProxyUrl: process.env.OPENAI_REVERSE_PROXY || null,
|
|
azure,
|
|
modelOptions: {
|
|
model: model,
|
|
temperature,
|
|
top_p,
|
|
presence_penalty,
|
|
frequency_penalty
|
|
},
|
|
chatGptLabel,
|
|
promptPrefix,
|
|
proxy: process.env.PROXY || null,
|
|
debug: false
|
|
};
|
|
|
|
let apiKey = process.env.OPENAI_KEY;
|
|
|
|
if (azure) {
|
|
apiKey = process.env.AZURE_OPENAI_API_KEY;
|
|
clientOptions.reverseProxyUrl = genAzureEndpoint({
|
|
azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
|
|
azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION
|
|
});
|
|
}
|
|
|
|
const client = new ChatGPTClient(apiKey, clientOptions, store);
|
|
|
|
const options = {
|
|
onProgress,
|
|
abortController,
|
|
...(parentMessageId && conversationId ? { parentMessageId, conversationId } : {})
|
|
};
|
|
|
|
const res = await client.sendMessage(text, { ...options, userId });
|
|
return res;
|
|
};
|
|
|
|
module.exports = { askClient };
|