mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 21:08:17 +00:00
🧭 fix: Honor Documented Azure Model Assistants and fileConfig.stt Keys (#17500)
* fix: Honor Documented Azure Model Assistants and fileConfig.stt Keys Read the model-level Azure assistants flag from the group's models entry, validate and merge fileConfig.stt, drop two never-read image tool env vars from .env.example and fix the SharePoint scope example. * test: Cover Model-Level Azure Assistants Through Config Overrides The mock harness runs without CONFIG_REDERIVE_ENDPOINTS, so override groups are never resolved there; cover the override path in the resolution spec instead of e2e.
This commit is contained in:
parent
65d0ba8563
commit
6515ec1387
7 changed files with 299 additions and 7 deletions
|
|
@ -726,8 +726,6 @@ AZURE_AI_SEARCH_SEARCH_OPTION_SELECT=
|
|||
# IMAGE_GEN_OAI_AZURE_API_VERSION= # Custom Azure OpenAI deployments
|
||||
# IMAGE_GEN_OAI_MODEL=gpt-image-2.5-flare # Override the image model or Azure deployment name
|
||||
# IMAGE_GEN_OAI_DESCRIPTION=
|
||||
# IMAGE_GEN_OAI_DESCRIPTION_WITH_FILES=Custom description for image generation tool when files are present
|
||||
# IMAGE_GEN_OAI_DESCRIPTION_NO_FILES=Custom description for image generation tool when no files are present
|
||||
# IMAGE_EDIT_OAI_DESCRIPTION=Custom description for image editing tool
|
||||
# IMAGE_GEN_OAI_PROMPT_DESCRIPTION=Custom prompt description for image generation tool
|
||||
# IMAGE_EDIT_OAI_PROMPT_DESCRIPTION=Custom prompt description for image editing tool
|
||||
|
|
@ -1133,7 +1131,7 @@ OPENID_MAX_LOGOUT_URL_LENGTH=
|
|||
# SHAREPOINT_BASE_URL=https://yourtenant.sharepoint.com
|
||||
|
||||
# Microsoft Graph API And SharePoint scopes for file picker
|
||||
# SHAREPOINT_PICKER_SHAREPOINT_SCOPE==https://yourtenant.sharepoint.com/AllSites.Read
|
||||
# SHAREPOINT_PICKER_SHAREPOINT_SCOPE=https://yourtenant.sharepoint.com/AllSites.Read
|
||||
# SHAREPOINT_PICKER_GRAPH_SCOPE=Files.Read.All
|
||||
#========================#
|
||||
|
||||
|
|
|
|||
132
e2e/specs/mock/scenarios/config-keys.spec.ts
Normal file
132
e2e/specs/mock/scenarios/config-keys.spec.ts
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import type { APIRequestContext } from '@playwright/test';
|
||||
import { getPrimaryE2EUser } from '../../../setup/users.mock';
|
||||
import { withMongo } from '../db';
|
||||
|
||||
/**
|
||||
* `fileConfig.stt`, written as a principal config override by the primary user (first
|
||||
* registered, ADMIN) for a user this file registers, whose own requests read the merged result.
|
||||
*/
|
||||
|
||||
type Session = { headers: Record<string, string>; userId: string };
|
||||
|
||||
async function login(
|
||||
request: APIRequestContext,
|
||||
user: { email: string; password: string },
|
||||
): Promise<Session> {
|
||||
const res = await request.post('/api/auth/login', {
|
||||
data: { email: user.email, password: user.password },
|
||||
});
|
||||
expect(res.ok()).toBeTruthy();
|
||||
const { token, user: body } = (await res.json()) as {
|
||||
token: string;
|
||||
user: { id?: string; _id?: string };
|
||||
};
|
||||
const userId = body.id ?? body._id;
|
||||
expect(token).toBeTruthy();
|
||||
expect(userId).toBeTruthy();
|
||||
return { headers: { Authorization: `Bearer ${token}` }, userId: userId as string };
|
||||
}
|
||||
|
||||
/** A user owned by this file, so no other spec's cleanup can remove it mid-run. */
|
||||
const targetUser = {
|
||||
email: `config-keys-${Date.now()}-${Math.random().toString(36).slice(2, 8)}@example.com`,
|
||||
name: 'Config Keys Target',
|
||||
password: 'securepassword789',
|
||||
};
|
||||
|
||||
let cachedSessions: { admin: Session; target: Session } | undefined;
|
||||
|
||||
/** Logs in once per worker: the harness allows 20 logins per window across all specs. */
|
||||
async function sessions(request: APIRequestContext): Promise<{ admin: Session; target: Session }> {
|
||||
if (!cachedSessions) {
|
||||
const admin = await login(request, getPrimaryE2EUser());
|
||||
const target = await login(request, targetUser);
|
||||
cachedSessions = { admin, target };
|
||||
}
|
||||
return cachedSessions;
|
||||
}
|
||||
|
||||
function configPath(userId: string): string {
|
||||
return `/api/admin/config/user/${userId}`;
|
||||
}
|
||||
|
||||
async function clearOverrides(
|
||||
request: APIRequestContext,
|
||||
admin: Session,
|
||||
userId: string,
|
||||
): Promise<void> {
|
||||
const res = await request.delete(configPath(userId), { headers: admin.headers });
|
||||
expect([200, 204, 404]).toContain(res.status());
|
||||
}
|
||||
|
||||
test.describe('fileConfig.stt', () => {
|
||||
test.describe.configure({ mode: 'serial' });
|
||||
|
||||
test.beforeAll(async ({ request }) => {
|
||||
const res = await request.post('/api/auth/register', {
|
||||
data: { ...targetUser, confirm_password: targetUser.password },
|
||||
});
|
||||
expect(res.ok()).toBeTruthy();
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
await withMongo(async (db) => {
|
||||
const user = await db.collection('users').findOne({ email: targetUser.email });
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
await db.collection('configs').deleteMany({ principalId: user._id.toString() });
|
||||
await db.collection('users').deleteOne({ _id: user._id });
|
||||
});
|
||||
});
|
||||
|
||||
test('an invalid fileConfig.stt MIME pattern is rejected when written @scenario:file-config-stt-validated', async ({
|
||||
request,
|
||||
}) => {
|
||||
const { admin, target } = await sessions(request);
|
||||
await clearOverrides(request, admin, target.userId);
|
||||
try {
|
||||
const res = await request.put(configPath(target.userId), {
|
||||
headers: admin.headers,
|
||||
data: { overrides: { fileConfig: { stt: { supportedMimeTypes: ['('] } } } },
|
||||
});
|
||||
expect(res.status()).toBe(400);
|
||||
const body = (await res.json()) as { code: string; issues: Array<{ path: string }> };
|
||||
expect(body.code).toBe('CONFIG_OVERRIDE_INVALID');
|
||||
expect(body.issues.map((issue) => issue.path)).toEqual([
|
||||
'fileConfig.stt.supportedMimeTypes.0',
|
||||
]);
|
||||
} finally {
|
||||
await clearOverrides(request, admin, target.userId);
|
||||
}
|
||||
});
|
||||
|
||||
test('a valid fileConfig.stt list reaches the user file config @scenario:file-config-stt-applied', async ({
|
||||
request,
|
||||
}) => {
|
||||
const { admin, target } = await sessions(request);
|
||||
await clearOverrides(request, admin, target.userId);
|
||||
try {
|
||||
const put = await request.put(configPath(target.userId), {
|
||||
headers: admin.headers,
|
||||
data: { overrides: { fileConfig: { stt: { supportedMimeTypes: ['^audio/ogg$'] } } } },
|
||||
});
|
||||
expect(put.status(), await put.text()).toBe(201);
|
||||
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const res = await request.get('/api/files/config', { headers: target.headers });
|
||||
expect(res.ok()).toBeTruthy();
|
||||
const body = (await res.json()) as { stt?: { supportedMimeTypes?: string[] } };
|
||||
return body.stt;
|
||||
},
|
||||
{ timeout: 30000, intervals: [500, 1000, 2000] },
|
||||
)
|
||||
.toEqual({ supportedMimeTypes: ['^audio/ogg$'] });
|
||||
} finally {
|
||||
await clearOverrides(request, admin, target.userId);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -1785,6 +1785,36 @@ describe('mergeFileConfig clientImageResize', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('fileConfig stt', () => {
|
||||
it('keeps stt.supportedMimeTypes when librechat.yaml is validated', () => {
|
||||
const result = fileConfigSchema.safeParse({
|
||||
stt: { supportedMimeTypes: ['^audio/(ogg|webm)$'] },
|
||||
});
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.success && result.data.stt).toEqual({
|
||||
supportedMimeTypes: ['^audio/(ogg|webm)$'],
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects an stt MIME pattern that is not a valid regex', () => {
|
||||
const result = fileConfigSchema.safeParse({ stt: { supportedMimeTypes: ['('] } });
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('replaces the default stt MIME types with the configured ones', () => {
|
||||
const merged = mergeFileConfig({ stt: { supportedMimeTypes: ['^audio/ogg$'] } });
|
||||
const types = merged.stt?.supportedMimeTypes ?? [];
|
||||
expect(merged.checkType?.('audio/ogg', types)).toBe(true);
|
||||
expect(merged.checkType?.('audio/mpeg', types)).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps the default stt MIME types when stt is not configured', () => {
|
||||
const merged = mergeFileConfig({ serverFileSizeLimit: 100 });
|
||||
const types = merged.stt?.supportedMimeTypes ?? [];
|
||||
expect(merged.checkType?.('audio/mpeg', types)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileConfigSchema clientImageResize', () => {
|
||||
it.each(['maxWidth', 'maxHeight'] as const)('rejects a non-positive %s', (dimension) => {
|
||||
const result = fileConfigSchema.safeParse({
|
||||
|
|
|
|||
|
|
@ -699,6 +699,11 @@ export const fileConfigSchema = z.object({
|
|||
supportedMimeTypes: supportedMimeTypesSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
stt: z
|
||||
.object({
|
||||
supportedMimeTypes: supportedMimeTypesSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
defaultLLMDeliveryPath: defaultLLMDeliveryPathSchema.optional(),
|
||||
legacyFileUploadUX: z.boolean().optional(),
|
||||
textFallbackWithoutTools: z.boolean().optional(),
|
||||
|
|
@ -1373,6 +1378,17 @@ function buildMergedFileConfig(dynamic: DynamicFileConfig | undefined): FileConf
|
|||
}
|
||||
}
|
||||
|
||||
if (dynamic.stt !== undefined) {
|
||||
const { supportedMimeTypes: sttMimeTypes, ...sttRest } = dynamic.stt;
|
||||
mergedConfig.stt = {
|
||||
...mergedConfig.stt,
|
||||
...sttRest,
|
||||
};
|
||||
if (sttMimeTypes) {
|
||||
mergedConfig.stt.supportedMimeTypes = convertStringsToRegex(sttMimeTypes);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dynamic.endpoints) {
|
||||
return mergedConfig;
|
||||
}
|
||||
|
|
|
|||
96
packages/data-schemas/src/app/azure.spec.ts
Normal file
96
packages/data-schemas/src/app/azure.spec.ts
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
import type { TCustomConfig } from 'librechat-data-provider';
|
||||
import { azureConfigSetup, narrowAzureServedModels, resolveAzureGroups } from './azure';
|
||||
|
||||
const baseGroup = {
|
||||
apiKey: 'test-key',
|
||||
instanceName: 'east',
|
||||
version: '2024-10-21',
|
||||
};
|
||||
|
||||
describe('Azure assistants model selection', () => {
|
||||
const groups = [
|
||||
{
|
||||
...baseGroup,
|
||||
group: 'east',
|
||||
models: {
|
||||
'gpt-4o': { deploymentName: 'gpt-4o', assistants: true },
|
||||
'gpt-4o-mini': { deploymentName: 'gpt-4o-mini' },
|
||||
'o3-mini': true,
|
||||
},
|
||||
deploymentName: 'o3-mini',
|
||||
},
|
||||
{
|
||||
...baseGroup,
|
||||
group: 'west',
|
||||
instanceName: 'west',
|
||||
assistants: true,
|
||||
models: { 'gpt-5': { deploymentName: 'gpt-5' } },
|
||||
},
|
||||
];
|
||||
|
||||
it('selects a model whose own entry sets assistants, beside a group that sets it', () => {
|
||||
const resolved = resolveAzureGroups(groups);
|
||||
|
||||
expect(resolved.isValid).toBe(true);
|
||||
expect(resolved.assistantModels).toEqual(['gpt-4o', 'gpt-5']);
|
||||
expect(resolved.assistantGroups).toEqual(['east', 'west']);
|
||||
});
|
||||
|
||||
it('keeps a model-level assistants model when the served lists are narrowed', () => {
|
||||
const resolved = resolveAzureGroups(groups);
|
||||
const { config, narrowed } = narrowAzureServedModels({
|
||||
groupMap: resolved.groupMap,
|
||||
modelGroupMap: resolved.modelGroupMap,
|
||||
modelNames: resolved.modelNames,
|
||||
assistantModels: ['gpt-4o', 'gpt-4o-mini', 'gpt-5'],
|
||||
assistantGroups: ['east', 'west'],
|
||||
});
|
||||
|
||||
expect(narrowed).toEqual(['assistantModels']);
|
||||
expect(config.assistantModels).toEqual(['gpt-4o', 'gpt-5']);
|
||||
expect(config.assistantGroups).toEqual(['east', 'west']);
|
||||
});
|
||||
|
||||
it('starts with endpoint-level assistants when only a model entry supports them', () => {
|
||||
const config = {
|
||||
endpoints: {
|
||||
azureOpenAI: {
|
||||
assistants: true,
|
||||
groups: [
|
||||
{
|
||||
...baseGroup,
|
||||
group: 'east',
|
||||
models: { 'gpt-4o': { deploymentName: 'gpt-4o', assistants: true } },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as unknown as Partial<TCustomConfig>;
|
||||
|
||||
const azure = azureConfigSetup(config);
|
||||
|
||||
expect(azure.assistantModels).toEqual(['gpt-4o']);
|
||||
expect(azure.assistantGroups).toEqual(['east']);
|
||||
});
|
||||
|
||||
it('still refuses endpoint-level assistants when no group or model supports them', () => {
|
||||
const config = {
|
||||
endpoints: {
|
||||
azureOpenAI: {
|
||||
assistants: true,
|
||||
groups: [
|
||||
{
|
||||
...baseGroup,
|
||||
group: 'east',
|
||||
models: { 'gpt-4o': { deploymentName: 'gpt-4o', assistants: false } },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
} as unknown as Partial<TCustomConfig>;
|
||||
|
||||
expect(() => azureConfigSetup(config)).toThrow(
|
||||
'No Azure models are configured to support assistants',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -108,9 +108,8 @@ function getServingGroupName(maps: AzureModelMaps, modelName: unknown): string |
|
|||
}
|
||||
|
||||
/**
|
||||
* Whether the group `modelGroupMap` maps `modelName` to serves it with assistants, as
|
||||
* `azureConfigSetup` has always judged it: the group's `assistants`, or an `assistants` flag on
|
||||
* an entry the group holds under the model's name.
|
||||
* Whether the group `modelGroupMap` maps `modelName` to serves it with assistants: the group's
|
||||
* `assistants`, or the `assistants` flag of the model's entry under the group's `models`.
|
||||
*/
|
||||
function supportsAzureAssistants(maps: AzureModelMaps, modelName: string): boolean {
|
||||
const groupName = maps.modelGroupMap?.[modelName]?.group;
|
||||
|
|
@ -121,7 +120,11 @@ function supportsAzureAssistants(maps: AzureModelMaps, modelName: string): boole
|
|||
if (group.assistants) {
|
||||
return true;
|
||||
}
|
||||
const named: unknown = Object.getOwnPropertyDescriptor(group, modelName)?.value;
|
||||
const models: unknown = group.models;
|
||||
const named: unknown =
|
||||
models != null && typeof models === 'object'
|
||||
? Object.getOwnPropertyDescriptor(models, modelName)?.value
|
||||
: undefined;
|
||||
return (
|
||||
named != null && typeof named === 'object' && 'assistants' in named && Boolean(named.assistants)
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2865,6 +2865,23 @@ describe('mergeConfigOverrides: Azure groups an override writes', () => {
|
|||
expect(later.endpoints?.azureOpenAI?.assistantModels).toEqual(['gpt-5', 'o3-mini']);
|
||||
});
|
||||
|
||||
it('keeps them on for a group whose model entry, not the group, supports them', () => {
|
||||
const modelLevel = {
|
||||
...plain,
|
||||
models: { 'gpt-5-mini': { deploymentName: 'gpt-5-mini', assistants: true } },
|
||||
};
|
||||
const merged = mergeWithGroups(assistantsBase, [
|
||||
fakeConfig({ endpoints: { azureOpenAI: { groups: [modelLevel] } } }, 10, [
|
||||
'endpoints.azureOpenAI.groups',
|
||||
]),
|
||||
]);
|
||||
|
||||
const azure = merged.endpoints?.azureOpenAI;
|
||||
expect(azure?.assistants).toBe(true);
|
||||
expect(azure?.assistantModels).toEqual(['gpt-5-mini']);
|
||||
expect(azure?.assistantGroups).toEqual(['plain']);
|
||||
});
|
||||
|
||||
it('turns off a layer that turns them on over models none of which supports them', () => {
|
||||
const warn = jest.spyOn(logger, 'warn').mockImplementation(() => logger);
|
||||
const merged = mergeWithGroups(base, [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue