Skip to content

Commit

Permalink
🤖 fix: Minor Assistants Endpoint Fixes (#2472)
Browse files Browse the repository at this point in the history
* fix(useCreateAssistantMutation): force re-render of assistants map by avoiding use shallow reference of listRes.data

* fix(AppService): regression by not including azure assistant defaults when no assistant endpoint values are set
  • Loading branch information
danny-avila authored Apr 19, 2024
1 parent 3d1dec6 commit e6310c8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
11 changes: 9 additions & 2 deletions api/server/services/AppService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const {
defaultSocialLogins,
} = require('librechat-data-provider');
const { checkVariables, checkHealth, checkConfig, checkAzureVariables } = require('./start/checks');
const { azureAssistantsDefaults, assistantsConfigSetup } = require('./start/assistants');
const { initializeFirebase } = require('./Files/Firebase/initialize');
const { assistantsConfigSetup } = require('./start/assistants');
const loadCustomConfig = require('./Config/loadCustomConfig');
const handleRateLimits = require('./Config/handleRateLimits');
const { azureConfigSetup } = require('./start/azureOpenAI');
Expand Down Expand Up @@ -70,8 +70,15 @@ const AppService = async (app) => {
checkAzureVariables();
}

if (config?.endpoints?.[EModelEndpoint.azureOpenAI]?.assistants) {
endpointLocals[EModelEndpoint.assistants] = azureAssistantsDefaults();
}

if (config?.endpoints?.[EModelEndpoint.assistants]) {
endpointLocals[EModelEndpoint.assistants] = assistantsConfigSetup(config);
endpointLocals[EModelEndpoint.assistants] = assistantsConfigSetup(
config,
endpointLocals[EModelEndpoint.assistants],
);
}

app.locals = {
Expand Down
25 changes: 22 additions & 3 deletions api/server/services/AppService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ describe('AppService', () => {
});

it('should default to `PNG` `imageOutputType` with no provided config', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() =>
Promise.resolve(undefined),
);
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(undefined));

await AppService(app);
expect(app.locals.imageOutputType).toEqual(EImageOutputType.PNG);
Expand Down Expand Up @@ -230,6 +228,27 @@ describe('AppService', () => {
);
});

it('should correctly configure minimum Azure OpenAI Assistant values', async () => {
const assistantGroups = [azureGroups[0], { ...azureGroups[1], assistants: true }];
require('./Config/loadCustomConfig').mockImplementationOnce(() =>
Promise.resolve({
endpoints: {
[EModelEndpoint.azureOpenAI]: {
groups: assistantGroups,
assistants: true,
},
},
}),
);

process.env.WESTUS_API_KEY = 'westus-key';
process.env.EASTUS_API_KEY = 'eastus-key';

await AppService(app);
expect(app.locals).toHaveProperty(EModelEndpoint.assistants);
expect(app.locals[EModelEndpoint.assistants].capabilities.length).toEqual(3);
});

it('should correctly configure Azure OpenAI endpoint based on custom config', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() =>
Promise.resolve({
Expand Down
22 changes: 14 additions & 8 deletions api/server/services/start/assistants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,24 @@ const {
} = require('librechat-data-provider');
const { logger } = require('~/config');

/**
* Sets up the minimum, default Assistants configuration if Azure OpenAI Assistants option is enabled.
* @returns {Partial<TAssistantEndpoint>} The Assistants endpoint configuration.
*/
function azureAssistantsDefaults() {
return {
capabilities: [Capabilities.tools, Capabilities.actions, Capabilities.code_interpreter],
};
}

/**
* Sets up the Assistants configuration from the config (`librechat.yaml`) file.
* @param {TCustomConfig} config - The loaded custom configuration.
* @param {Partial<TAssistantEndpoint>} [prevConfig]
* - The previously loaded assistants configuration from Azure OpenAI Assistants option.
* @returns {Partial<TAssistantEndpoint>} The Assistants endpoint configuration.
*/
function assistantsConfigSetup(config) {
function assistantsConfigSetup(config, prevConfig = {}) {
const assistantsConfig = config.endpoints[EModelEndpoint.assistants];
const parsedConfig = assistantEndpointSchema.parse(assistantsConfig);
if (assistantsConfig.supportedIds?.length && assistantsConfig.excludedIds?.length) {
Expand All @@ -19,12 +31,6 @@ function assistantsConfigSetup(config) {
);
}

const prevConfig = config.endpoints[EModelEndpoint.azureOpenAI]?.assistants
? {
capabilities: [Capabilities.tools, Capabilities.actions, Capabilities.code_interpreter],
}
: {};

return {
...prevConfig,
retrievalModels: parsedConfig.retrievalModels,
Expand All @@ -37,4 +43,4 @@ function assistantsConfigSetup(config) {
};
}

module.exports = { assistantsConfigSetup };
module.exports = { azureAssistantsDefaults, assistantsConfigSetup };
3 changes: 1 addition & 2 deletions client/src/data-provider/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ export const useCreateAssistantMutation = (
return options?.onSuccess?.(newAssistant, variables, context);
}

const currentAssistants = listRes.data;
currentAssistants.push(newAssistant);
const currentAssistants = [newAssistant, ...JSON.parse(JSON.stringify(listRes.data))];

queryClient.setQueryData<AssistantListResponse>([QueryKeys.assistants, defaultOrderQuery], {
...listRes,
Expand Down

0 comments on commit e6310c8

Please sign in to comment.