🔑 fix: Azure Serverless Support for API Key Header & Version (#4791)

* fix: azure validation/extraction types

* fix: typing, add optional chaining for modelGroup and groupMap properties; expect azureOpenAIApiVersion in serverless tests

* fix: add support for azureOpenAIApiVersion and api-key in serverless mode across clients

* chore: update CONFIG_VERSION to 1.1.8, data-provider bump
This commit is contained in:
Danny Avila 2024-11-25 13:33:06 -05:00 committed by GitHub
parent 07511b3db8
commit e0a5f879b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 100 additions and 42 deletions

View file

@ -135,6 +135,12 @@ const initializeClient = async ({ req, res, version, endpointOption, initAppClie
clientOptions.reverseProxyUrl = baseURL ?? clientOptions.reverseProxyUrl;
clientOptions.headers = opts.defaultHeaders;
clientOptions.azure = !serverless && azureOptions;
if (serverless === true) {
clientOptions.defaultQuery = azureOptions.azureOpenAIApiVersion
? { 'api-version': azureOptions.azureOpenAIApiVersion }
: undefined;
clientOptions.headers['api-key'] = apiKey;
}
}
}

View file

@ -96,6 +96,12 @@ const initializeClient = async ({ req, res, endpointOption }) => {
apiKey = azureOptions.azureOpenAIApiKey;
clientOptions.azure = !serverless && azureOptions;
if (serverless === true) {
clientOptions.defaultQuery = azureOptions.azureOpenAIApiVersion
? { 'api-version': azureOptions.azureOpenAIApiVersion }
: undefined;
clientOptions.headers['api-key'] = apiKey;
}
} else if (useAzure || (apiKey && apiKey.includes('{"azure') && !clientOptions.azure)) {
clientOptions.azure = userProvidesKey ? JSON.parse(userValues.apiKey) : getAzureCredentials();
apiKey = clientOptions.azure.azureOpenAIApiKey;

View file

@ -97,6 +97,12 @@ const initializeClient = async ({
apiKey = azureOptions.azureOpenAIApiKey;
clientOptions.azure = !serverless && azureOptions;
if (serverless === true) {
clientOptions.defaultQuery = azureOptions.azureOpenAIApiVersion
? { 'api-version': azureOptions.azureOpenAIApiVersion }
: undefined;
clientOptions.headers['api-key'] = apiKey;
}
} else if (isAzureOpenAI) {
clientOptions.azure = userProvidesKey ? JSON.parse(userValues.apiKey) : getAzureCredentials();
apiKey = clientOptions.azure.azureOpenAIApiKey;

View file

@ -29,6 +29,7 @@ function getLLMConfig(apiKey, options = {}) {
modelOptions = {},
reverseProxyUrl,
useOpenRouter,
defaultQuery,
headers,
proxy,
azure,
@ -74,6 +75,10 @@ function getLLMConfig(apiKey, options = {}) {
}
}
if (defaultQuery) {
configOptions.baseOptions.defaultQuery = defaultQuery;
}
if (proxy) {
const proxyAgent = new HttpsProxyAgent(proxy);
Object.assign(configOptions, {