Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Ability to order assistants by order of specified supported id's #4542

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/server/controllers/EndpointController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ async function endpointController(req, res) {
/** @type {TEndpointsConfig} */
const mergedConfig = { ...defaultEndpointsConfig, ...customConfigEndpoints };
if (mergedConfig[EModelEndpoint.assistants] && req.app.locals?.[EModelEndpoint.assistants]) {
const { disableBuilder, retrievalModels, capabilities, version, ..._rest } =
const { disableBuilder, orderBySupportIdsFirst, retrievalModels, capabilities, version, ..._rest } =
req.app.locals[EModelEndpoint.assistants];

mergedConfig[EModelEndpoint.assistants] = {
...mergedConfig[EModelEndpoint.assistants],
version,
retrievalModels,
disableBuilder,
orderBySupportIdsFirst,
capabilities,
};
}
Expand All @@ -32,14 +33,15 @@ async function endpointController(req, res) {
mergedConfig[EModelEndpoint.azureAssistants] &&
req.app.locals?.[EModelEndpoint.azureAssistants]
) {
const { disableBuilder, retrievalModels, capabilities, version, ..._rest } =
const { disableBuilder, orderBySupportIdsFirst, retrievalModels, capabilities, version, ..._rest } =
req.app.locals[EModelEndpoint.azureAssistants];

mergedConfig[EModelEndpoint.azureAssistants] = {
...mergedConfig[EModelEndpoint.azureAssistants],
version,
retrievalModels,
disableBuilder,
orderBySupportIdsFirst,
capabilities,
};
}
Expand Down
13 changes: 13 additions & 0 deletions api/server/controllers/assistants/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const _listAssistants = async ({ req, res, version, query }) => {
const listAllAssistants = async ({ req, res, version, query }) => {
/** @type {{ openai: OpenAIClient }} */
const { openai } = await getOpenAIClient({ req, res, version });
const { supportedIds, orderBySupportIdsFirst } = req.app.locals[EModelEndpoint.assistants];
const allAssistants = [];

let first_id;
Expand Down Expand Up @@ -98,6 +99,18 @@ const listAllAssistants = async ({ req, res, version, query }) => {
}
}

if (true === orderBySupportIdsFirst) {
supportedIds.forEach((supportedId, key) => {
const idx = allAssistants.findIndex(({id}) => id === supportedId);

if (idx > -1 && idx !== key) {
allAssistants.splice(key, 0, ...allAssistants.splice(idx, 1));
}
});
first_id = allAssistants[0].id;
last_id = allAssistants[allAssistants.length - 1].id;
}

return {
data: allAssistants,
body: {
Expand Down
5 changes: 5 additions & 0 deletions api/server/services/AppService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ describe('AppService', () => {
pollIntervalMs: 5000,
timeoutMs: 30000,
supportedIds: ['id1', 'id2'],
orderBySupportIdsFirst: false,
privateAssistants: false,
},
},
Expand All @@ -235,6 +236,7 @@ describe('AppService', () => {
pollIntervalMs: 5000,
timeoutMs: 30000,
supportedIds: expect.arrayContaining(['id1', 'id2']),
orderBySupportIdsFirst: false,
privateAssistants: false,
}),
);
Expand Down Expand Up @@ -473,6 +475,7 @@ describe('AppService updating app.locals and issuing warnings', () => {
pollIntervalMs: 5000,
timeoutMs: 30000,
supportedIds: ['id1', 'id2'],
orderBySupportIdsFirst: false,
},
},
};
Expand All @@ -487,6 +490,7 @@ describe('AppService updating app.locals and issuing warnings', () => {
expect(assistants.pollIntervalMs).toBe(5000);
expect(assistants.timeoutMs).toBe(30000);
expect(assistants.supportedIds).toEqual(['id1', 'id2']);
expect(assistants.orderBySupportIdsFirst).toEqual(false);
expect(assistants.excludedIds).toBeUndefined();
});

Expand All @@ -498,6 +502,7 @@ describe('AppService updating app.locals and issuing warnings', () => {
pollIntervalMs: 3000,
timeoutMs: 20000,
supportedIds: ['id1', 'id2'],
orderBySupportIdsFirst: false,
excludedIds: ['id3'],
},
},
Expand Down
1 change: 1 addition & 0 deletions api/server/services/start/assistants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function assistantsConfigSetup(config, assistantsEndpoint, prevConfig = {}) {
disableBuilder: parsedConfig.disableBuilder,
pollIntervalMs: parsedConfig.pollIntervalMs,
supportedIds: parsedConfig.supportedIds,
orderBySupportIdsFirst: parsedConfig.orderBySupportIdsFirst ?? assistantsConfig.orderBySupportIdsFirst,
capabilities: parsedConfig.capabilities,
excludedIds: parsedConfig.excludedIds,
privateAssistants: parsedConfig.privateAssistants,
Expand Down
5 changes: 3 additions & 2 deletions librechat.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface:
If you have any questions about these Terms, please contact us at [email protected].

By using the Website, you acknowledge that you have read these Terms of Service and agree to be bound by them.

# Example Registration Object Structure (optional)
registration:
socialLogins: ['github', 'google', 'discord', 'openid', 'facebook']
Expand All @@ -71,7 +71,7 @@ registration:
# model: ''
# voices: ['']

#
#
# stt:
# openai:
# url: ''
Expand All @@ -98,6 +98,7 @@ endpoints:
# timeoutMs: 180000 # Timeout for assistant operations
# # Should only be one or the other, either `supportedIds` or `excludedIds`
# supportedIds: ["asst_supportedAssistantId1", "asst_supportedAssistantId2"]
# orderBySupportIdsFirst: false # Sort by supportedIds array first
# # excludedIds: ["asst_excludedAssistantId"]
# Only show assistants that the user created or that were created externally (e.g. in Assistants playground).
# # privateAssistants: false # Does not work with `supportedIds` or `excludedIds`
Expand Down
2 changes: 2 additions & 0 deletions packages/data-provider/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const assistantEndpointSchema = baseEndpointSchema.merge(
timeoutMs: z.number().optional(),
version: z.union([z.string(), z.number()]).default(2),
supportedIds: z.array(z.string()).min(1).optional(),
orderBySupportIdsFirst: z.boolean().optional(),
excludedIds: z.array(z.string()).min(1).optional(),
privateAssistants: z.boolean().optional(),
retrievalModels: z.array(z.string()).min(1).optional().default(defaultRetrievalModels),
Expand Down Expand Up @@ -212,6 +213,7 @@ export const agentsEndpointSChema = baseEndpointSchema.merge(
timeoutMs: z.number().optional(),
version: z.union([z.string(), z.number()]).default(2),
supportedIds: z.array(z.string()).min(1).optional(),
orderBySupportIdsFirst: z.boolean().optional(),
excludedIds: z.array(z.string()).min(1).optional(),
privateAssistants: z.boolean().optional(),
retrievalModels: z.array(z.string()).min(1).optional().default(defaultRetrievalModels),
Expand Down
1 change: 1 addition & 0 deletions packages/data-provider/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export type TConfig = {
userProvide?: boolean | null;
userProvideURL?: boolean | null;
disableBuilder?: boolean;
orderBySupportIdsFirst?: boolean;
retrievalModels?: string[];
capabilities?: string[];
};
Expand Down