mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 09:20:15 +01:00
🤖 feat: Azure OpenAI Responses API (#8195)
* 🤖 feat: Azure OpenAI Responses API
* chore: cleanup order of executions
This commit is contained in:
parent
1ceb52d2b5
commit
56ad92fb1c
1 changed files with 39 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
import { ProxyAgent } from 'undici';
|
import { ProxyAgent } from 'undici';
|
||||||
import { KnownEndpoints, removeNullishValues } from 'librechat-data-provider';
|
import { KnownEndpoints, removeNullishValues } from 'librechat-data-provider';
|
||||||
|
import type { AzureOpenAIInput } from '@langchain/openai';
|
||||||
import type { OpenAI } from 'openai';
|
import type { OpenAI } from 'openai';
|
||||||
import type * as t from '~/types';
|
import type * as t from '~/types';
|
||||||
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
|
import { sanitizeModelName, constructAzureURL } from '~/utils/azure';
|
||||||
|
|
@ -42,7 +43,9 @@ export function getOpenAIConfig(
|
||||||
dropParams,
|
dropParams,
|
||||||
} = options;
|
} = options;
|
||||||
const { reasoning_effort, reasoning_summary, ...modelOptions } = _modelOptions;
|
const { reasoning_effort, reasoning_summary, ...modelOptions } = _modelOptions;
|
||||||
const llmConfig: Partial<t.ClientOptions> & Partial<t.OpenAIParameters> = Object.assign(
|
const llmConfig: Partial<t.ClientOptions> &
|
||||||
|
Partial<t.OpenAIParameters> &
|
||||||
|
Partial<AzureOpenAIInput> = Object.assign(
|
||||||
{
|
{
|
||||||
streaming,
|
streaming,
|
||||||
model: modelOptions.model ?? '',
|
model: modelOptions.model ?? '',
|
||||||
|
|
@ -100,7 +103,10 @@ export function getOpenAIConfig(
|
||||||
llmConfig.model = process.env.AZURE_OPENAI_DEFAULT_MODEL;
|
llmConfig.model = process.env.AZURE_OPENAI_DEFAULT_MODEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configOptions.baseURL) {
|
const constructBaseURL = () => {
|
||||||
|
if (!configOptions.baseURL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const azureURL = constructAzureURL({
|
const azureURL = constructAzureURL({
|
||||||
baseURL: configOptions.baseURL,
|
baseURL: configOptions.baseURL,
|
||||||
azureOptions: updatedAzure,
|
azureOptions: updatedAzure,
|
||||||
|
|
@ -108,9 +114,39 @@ export function getOpenAIConfig(
|
||||||
updatedAzure.azureOpenAIBasePath = azureURL.split(
|
updatedAzure.azureOpenAIBasePath = azureURL.split(
|
||||||
`/${updatedAzure.azureOpenAIApiDeploymentName}`,
|
`/${updatedAzure.azureOpenAIApiDeploymentName}`,
|
||||||
)[0];
|
)[0];
|
||||||
|
};
|
||||||
|
|
||||||
|
constructBaseURL();
|
||||||
|
Object.assign(llmConfig, updatedAzure);
|
||||||
|
|
||||||
|
const constructAzureResponsesApi = () => {
|
||||||
|
if (!llmConfig.useResponsesApi) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(llmConfig, updatedAzure);
|
configOptions.baseURL = constructAzureURL({
|
||||||
|
baseURL: configOptions.baseURL || 'https://${INSTANCE_NAME}.openai.azure.com/openai/v1',
|
||||||
|
azureOptions: llmConfig,
|
||||||
|
});
|
||||||
|
|
||||||
|
delete llmConfig.azureOpenAIApiDeploymentName;
|
||||||
|
delete llmConfig.azureOpenAIApiInstanceName;
|
||||||
|
delete llmConfig.azureOpenAIApiVersion;
|
||||||
|
delete llmConfig.azureOpenAIBasePath;
|
||||||
|
delete llmConfig.azureOpenAIApiKey;
|
||||||
|
|
||||||
|
configOptions.defaultHeaders = {
|
||||||
|
...configOptions.defaultHeaders,
|
||||||
|
'api-key': apiKey,
|
||||||
|
};
|
||||||
|
configOptions.defaultQuery = {
|
||||||
|
...configOptions.defaultQuery,
|
||||||
|
'api-version': 'preview',
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
constructAzureResponsesApi();
|
||||||
|
|
||||||
llmConfig.model = updatedAzure.azureOpenAIApiDeploymentName;
|
llmConfig.model = updatedAzure.azureOpenAIApiDeploymentName;
|
||||||
} else {
|
} else {
|
||||||
llmConfig.apiKey = apiKey;
|
llmConfig.apiKey = apiKey;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue