mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
feat(chatgpt-client.js, titleConvo.js, genAzureEndpoints.js): add support for Azure OpenAI API endpoint generation (#234)
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.
This commit is contained in:
parent
7997c3137a
commit
bd068c9a5a
3 changed files with 27 additions and 4 deletions
|
|
@ -1,7 +1,8 @@
|
|||
const { Configuration, OpenAIApi } = require('openai');
|
||||
const _ = require('lodash');
|
||||
const { genAzureEndpoint } = require('../utils/genAzureEndpoints');
|
||||
|
||||
const proxyEnvToAxiosProxy = proxyString => {
|
||||
const proxyEnvToAxiosProxy = (proxyString) => {
|
||||
if (!proxyString) return null;
|
||||
|
||||
const regex = /^([^:]+):\/\/(?:([^:@]*):?([^:@]*)@)?([^:]+)(?::(\d+))?/;
|
||||
|
|
@ -47,9 +48,21 @@ const titleConvo = async ({ endpoint, text, response }) => {
|
|||
frequency_penalty: 0
|
||||
};
|
||||
|
||||
const titleGenClient = new ChatGPTClient(process.env.OPENAI_KEY, titleGenClientOptions);
|
||||
const azure = process.env.AZURE_OPENAI_API_KEY ? true : false;
|
||||
let apiKey = process.env.OPENAI_KEY;
|
||||
|
||||
if (azure) {
|
||||
apiKey = process.env.AZURE_OPENAI_API_KEY;
|
||||
titleGenClientOptions.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 titleGenClient = new ChatGPTClient(apiKey, titleGenClientOptions);
|
||||
const result = await titleGenClient.getCompletion([instructionsPayload], null);
|
||||
title = result.choices[0].message.content.replace(/\s+/g, ' ').trim();
|
||||
title = result.choices[0].message.content.replace(/\s+/g, ' ').replaceAll('"', '').trim();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.log('There was an issue generating title, see error above');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue