mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
🅰️ feat: Azure AI Studio, Models as a Service Support (#1902)
* feat(data-provider): add Azure serverless inference handling through librechat.yaml * feat(azureOpenAI): serverless inference handling in api * docs: update docs with new azureOpenAI endpoint config fields and serverless inference endpoint setup * chore: remove unnecessary checks for apiKey as schema would not allow apiKey to be undefined * ci(azureOpenAI): update tests for serverless configurations
This commit is contained in:
parent
6d6b3c9c1d
commit
08d4b3cc8a
9 changed files with 460 additions and 26 deletions
|
|
@ -71,6 +71,8 @@ export function validateAzureGroups(configs: TAzureGroups): TValidatedAzureConfi
|
|||
baseURL,
|
||||
additionalHeaders,
|
||||
models,
|
||||
serverless,
|
||||
...rest
|
||||
} = group;
|
||||
|
||||
if (groupMap[groupName]) {
|
||||
|
|
@ -78,6 +80,18 @@ export function validateAzureGroups(configs: TAzureGroups): TValidatedAzureConfi
|
|||
return { isValid: false, modelNames, modelGroupMap, groupMap, errors };
|
||||
}
|
||||
|
||||
if (serverless && !baseURL) {
|
||||
errors.push(`Group "${groupName}" is serverless but missing mandatory "baseURL."`);
|
||||
return { isValid: false, modelNames, modelGroupMap, groupMap, errors };
|
||||
}
|
||||
|
||||
if (!instanceName && !serverless) {
|
||||
errors.push(
|
||||
`Group "${groupName}" is missing an "instanceName" for non-serverless configuration.`,
|
||||
);
|
||||
return { isValid: false, modelNames, modelGroupMap, groupMap, errors };
|
||||
}
|
||||
|
||||
groupMap[groupName] = {
|
||||
apiKey,
|
||||
instanceName,
|
||||
|
|
@ -86,6 +100,8 @@ export function validateAzureGroups(configs: TAzureGroups): TValidatedAzureConfi
|
|||
baseURL,
|
||||
additionalHeaders,
|
||||
models,
|
||||
serverless,
|
||||
...rest,
|
||||
};
|
||||
|
||||
for (const modelName in group.models) {
|
||||
|
|
@ -99,6 +115,13 @@ export function validateAzureGroups(configs: TAzureGroups): TValidatedAzureConfi
|
|||
return { isValid: false, modelNames, modelGroupMap, groupMap, errors };
|
||||
}
|
||||
|
||||
if (serverless) {
|
||||
modelGroupMap[modelName] = {
|
||||
group: groupName,
|
||||
};
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof model === 'boolean') {
|
||||
// For boolean models, check if group-level deploymentName and version are present.
|
||||
if (!group.deploymentName || !group.version) {
|
||||
|
|
@ -138,15 +161,16 @@ export function validateAzureGroups(configs: TAzureGroups): TValidatedAzureConfi
|
|||
|
||||
type AzureOptions = {
|
||||
azureOpenAIApiKey: string;
|
||||
azureOpenAIApiInstanceName: string;
|
||||
azureOpenAIApiDeploymentName: string;
|
||||
azureOpenAIApiVersion: string;
|
||||
azureOpenAIApiInstanceName?: string;
|
||||
azureOpenAIApiDeploymentName?: string;
|
||||
azureOpenAIApiVersion?: string;
|
||||
};
|
||||
|
||||
type MappedAzureConfig = {
|
||||
azureOptions: AzureOptions;
|
||||
baseURL?: string;
|
||||
headers?: Record<string, string>;
|
||||
serverless?: boolean;
|
||||
};
|
||||
|
||||
export function mapModelToAzureConfig({
|
||||
|
|
@ -168,6 +192,47 @@ export function mapModelToAzureConfig({
|
|||
);
|
||||
}
|
||||
|
||||
const instanceName = groupConfig.instanceName;
|
||||
|
||||
if (!instanceName && !groupConfig.serverless) {
|
||||
throw new Error(
|
||||
`Group "${modelConfig.group}" is missing an instanceName for non-serverless configuration.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (groupConfig.serverless && !groupConfig.baseURL) {
|
||||
throw new Error(
|
||||
`Group "${modelConfig.group}" is missing the required base URL for serverless configuration.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (groupConfig.serverless) {
|
||||
const result: MappedAzureConfig = {
|
||||
azureOptions: {
|
||||
azureOpenAIApiKey: extractEnvVariable(groupConfig.apiKey),
|
||||
},
|
||||
baseURL: extractEnvVariable(groupConfig.baseURL as string),
|
||||
serverless: true,
|
||||
};
|
||||
|
||||
const apiKeyValue = result.azureOptions.azureOpenAIApiKey;
|
||||
if (typeof apiKeyValue === 'string' && envVarRegex.test(apiKeyValue)) {
|
||||
throw new Error(`Azure configuration environment variable "${apiKeyValue}" was not found.`);
|
||||
}
|
||||
|
||||
if (groupConfig.additionalHeaders) {
|
||||
result.headers = groupConfig.additionalHeaders;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!instanceName) {
|
||||
throw new Error(
|
||||
`Group "${modelConfig.group}" is missing an instanceName for non-serverless configuration.`,
|
||||
);
|
||||
}
|
||||
|
||||
const modelDetails = groupConfig.models[modelName];
|
||||
const deploymentName =
|
||||
typeof modelDetails === 'object'
|
||||
|
|
@ -186,7 +251,7 @@ export function mapModelToAzureConfig({
|
|||
|
||||
const azureOptions: AzureOptions = {
|
||||
azureOpenAIApiKey: extractEnvVariable(groupConfig.apiKey),
|
||||
azureOpenAIApiInstanceName: extractEnvVariable(groupConfig.instanceName),
|
||||
azureOpenAIApiInstanceName: extractEnvVariable(instanceName),
|
||||
azureOpenAIApiDeploymentName: extractEnvVariable(deploymentName),
|
||||
azureOpenAIApiVersion: extractEnvVariable(version),
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue