mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 19:30:15 +01:00
refactor: consolidate endpoint loading logic into loadEndpoints function
This commit is contained in:
parent
8525c8df36
commit
89fb9c7e1c
2 changed files with 70 additions and 53 deletions
66
api/server/services/start/endpoints.js
Normal file
66
api/server/services/start/endpoints.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
const { agentsConfigSetup } = require('@librechat/api');
|
||||
const { EModelEndpoint } = require('librechat-data-provider');
|
||||
const { azureAssistantsDefaults, assistantsConfigSetup } = require('./assistants');
|
||||
const { azureConfigSetup } = require('./azureOpenAI');
|
||||
const { checkAzureVariables } = require('./checks');
|
||||
|
||||
/**
|
||||
* Loads custom config endpoints
|
||||
* @param {TCustomConfig} [config]
|
||||
* @param {TCustomConfig['endpoints']['agents']} [agentsDefaults]
|
||||
*/
|
||||
const loadEndpoints = (config, agentsDefaults) => {
|
||||
const loadedEndpoints = {};
|
||||
const endpoints = config?.endpoints;
|
||||
|
||||
if (endpoints?.[EModelEndpoint.azureOpenAI]) {
|
||||
loadedEndpoints[EModelEndpoint.azureOpenAI] = azureConfigSetup(config);
|
||||
checkAzureVariables();
|
||||
}
|
||||
|
||||
if (endpoints?.[EModelEndpoint.azureOpenAI]?.assistants) {
|
||||
loadedEndpoints[EModelEndpoint.azureAssistants] = azureAssistantsDefaults();
|
||||
}
|
||||
|
||||
if (endpoints?.[EModelEndpoint.azureAssistants]) {
|
||||
loadedEndpoints[EModelEndpoint.azureAssistants] = assistantsConfigSetup(
|
||||
config,
|
||||
EModelEndpoint.azureAssistants,
|
||||
loadedEndpoints[EModelEndpoint.azureAssistants],
|
||||
);
|
||||
}
|
||||
|
||||
if (endpoints?.[EModelEndpoint.assistants]) {
|
||||
loadedEndpoints[EModelEndpoint.assistants] = assistantsConfigSetup(
|
||||
config,
|
||||
EModelEndpoint.assistants,
|
||||
loadedEndpoints[EModelEndpoint.assistants],
|
||||
);
|
||||
}
|
||||
|
||||
loadedEndpoints[EModelEndpoint.agents] = agentsConfigSetup(config, agentsDefaults);
|
||||
|
||||
const endpointKeys = [
|
||||
EModelEndpoint.openAI,
|
||||
EModelEndpoint.google,
|
||||
EModelEndpoint.bedrock,
|
||||
EModelEndpoint.anthropic,
|
||||
EModelEndpoint.gptPlugins,
|
||||
];
|
||||
|
||||
endpointKeys.forEach((key) => {
|
||||
if (endpoints?.[key]) {
|
||||
loadedEndpoints[key] = endpoints[key];
|
||||
}
|
||||
});
|
||||
|
||||
if (endpoints?.all) {
|
||||
loadedEndpoints.all = endpoints.all;
|
||||
}
|
||||
|
||||
return loadedEndpoints;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
loadEndpoints,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue