mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
🤖 fix: Minor Assistants Endpoint Fixes (#2472)
* 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
This commit is contained in:
parent
3d1dec62a4
commit
e6310c806a
4 changed files with 48 additions and 17 deletions
|
|
@ -5,8 +5,8 @@ const {
|
||||||
defaultSocialLogins,
|
defaultSocialLogins,
|
||||||
} = require('librechat-data-provider');
|
} = require('librechat-data-provider');
|
||||||
const { checkVariables, checkHealth, checkConfig, checkAzureVariables } = require('./start/checks');
|
const { checkVariables, checkHealth, checkConfig, checkAzureVariables } = require('./start/checks');
|
||||||
|
const { azureAssistantsDefaults, assistantsConfigSetup } = require('./start/assistants');
|
||||||
const { initializeFirebase } = require('./Files/Firebase/initialize');
|
const { initializeFirebase } = require('./Files/Firebase/initialize');
|
||||||
const { assistantsConfigSetup } = require('./start/assistants');
|
|
||||||
const loadCustomConfig = require('./Config/loadCustomConfig');
|
const loadCustomConfig = require('./Config/loadCustomConfig');
|
||||||
const handleRateLimits = require('./Config/handleRateLimits');
|
const handleRateLimits = require('./Config/handleRateLimits');
|
||||||
const { azureConfigSetup } = require('./start/azureOpenAI');
|
const { azureConfigSetup } = require('./start/azureOpenAI');
|
||||||
|
|
@ -70,8 +70,15 @@ const AppService = async (app) => {
|
||||||
checkAzureVariables();
|
checkAzureVariables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config?.endpoints?.[EModelEndpoint.azureOpenAI]?.assistants) {
|
||||||
|
endpointLocals[EModelEndpoint.assistants] = azureAssistantsDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
if (config?.endpoints?.[EModelEndpoint.assistants]) {
|
if (config?.endpoints?.[EModelEndpoint.assistants]) {
|
||||||
endpointLocals[EModelEndpoint.assistants] = assistantsConfigSetup(config);
|
endpointLocals[EModelEndpoint.assistants] = assistantsConfigSetup(
|
||||||
|
config,
|
||||||
|
endpointLocals[EModelEndpoint.assistants],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.locals = {
|
app.locals = {
|
||||||
|
|
|
||||||
|
|
@ -154,9 +154,7 @@ describe('AppService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should default to `PNG` `imageOutputType` with no provided config', async () => {
|
it('should default to `PNG` `imageOutputType` with no provided config', async () => {
|
||||||
require('./Config/loadCustomConfig').mockImplementationOnce(() =>
|
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(undefined));
|
||||||
Promise.resolve(undefined),
|
|
||||||
);
|
|
||||||
|
|
||||||
await AppService(app);
|
await AppService(app);
|
||||||
expect(app.locals.imageOutputType).toEqual(EImageOutputType.PNG);
|
expect(app.locals.imageOutputType).toEqual(EImageOutputType.PNG);
|
||||||
|
|
@ -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 () => {
|
it('should correctly configure Azure OpenAI endpoint based on custom config', async () => {
|
||||||
require('./Config/loadCustomConfig').mockImplementationOnce(() =>
|
require('./Config/loadCustomConfig').mockImplementationOnce(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,23 @@ const {
|
||||||
const { logger } = require('~/config');
|
const { logger } = require('~/config');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the Assistants configuration from the config (`librechat.yaml`) file.
|
* Sets up the minimum, default Assistants configuration if Azure OpenAI Assistants option is enabled.
|
||||||
* @param {TCustomConfig} config - The loaded custom configuration.
|
|
||||||
* @returns {Partial<TAssistantEndpoint>} The Assistants endpoint configuration.
|
* @returns {Partial<TAssistantEndpoint>} The Assistants endpoint configuration.
|
||||||
*/
|
*/
|
||||||
function assistantsConfigSetup(config) {
|
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, prevConfig = {}) {
|
||||||
const assistantsConfig = config.endpoints[EModelEndpoint.assistants];
|
const assistantsConfig = config.endpoints[EModelEndpoint.assistants];
|
||||||
const parsedConfig = assistantEndpointSchema.parse(assistantsConfig);
|
const parsedConfig = assistantEndpointSchema.parse(assistantsConfig);
|
||||||
if (assistantsConfig.supportedIds?.length && assistantsConfig.excludedIds?.length) {
|
if (assistantsConfig.supportedIds?.length && assistantsConfig.excludedIds?.length) {
|
||||||
|
|
@ -19,12 +31,6 @@ function assistantsConfigSetup(config) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prevConfig = config.endpoints[EModelEndpoint.azureOpenAI]?.assistants
|
|
||||||
? {
|
|
||||||
capabilities: [Capabilities.tools, Capabilities.actions, Capabilities.code_interpreter],
|
|
||||||
}
|
|
||||||
: {};
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...prevConfig,
|
...prevConfig,
|
||||||
retrievalModels: parsedConfig.retrievalModels,
|
retrievalModels: parsedConfig.retrievalModels,
|
||||||
|
|
@ -37,4 +43,4 @@ function assistantsConfigSetup(config) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { assistantsConfigSetup };
|
module.exports = { azureAssistantsDefaults, assistantsConfigSetup };
|
||||||
|
|
|
||||||
|
|
@ -315,8 +315,7 @@ export const useCreateAssistantMutation = (
|
||||||
return options?.onSuccess?.(newAssistant, variables, context);
|
return options?.onSuccess?.(newAssistant, variables, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentAssistants = listRes.data;
|
const currentAssistants = [newAssistant, ...JSON.parse(JSON.stringify(listRes.data))];
|
||||||
currentAssistants.push(newAssistant);
|
|
||||||
|
|
||||||
queryClient.setQueryData<AssistantListResponse>([QueryKeys.assistants, defaultOrderQuery], {
|
queryClient.setQueryData<AssistantListResponse>([QueryKeys.assistants, defaultOrderQuery], {
|
||||||
...listRes,
|
...listRes,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue