mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00

* # * - refactor: simplified getCustomConfig func * # * - feature: persist values for parameters with optionType of custom * # * - refactor: moved `Parameters/settings.ts` into `data-provider` so that both frontend and backend code can use it. * - feature: loadCustomConfig can now parse and validate customParams property for `endpoints.custom` in `librechat.yaml` * # fixed linter * # removed .strict() in config.ts * change: added packages/data-provider/src to SOURCE_DIRS for i18n check * # removed unnecessary lodash imports * # addressed PR comments # fixed lint for updated files * # better import for lodash (w/o relying on tree-shaking)
73 lines
2.1 KiB
JavaScript
73 lines
2.1 KiB
JavaScript
const { EModelEndpoint, extractEnvVariable } = require('librechat-data-provider');
|
|
const { isUserProvided, normalizeEndpointName } = require('~/server/utils');
|
|
const { getCustomConfig } = require('./getCustomConfig');
|
|
|
|
/**
|
|
* Load config endpoints from the cached configuration object
|
|
* @param {Express.Request} req - The request object
|
|
* @returns {Promise<TEndpointsConfig>} A promise that resolves to an object containing the endpoints configuration
|
|
*/
|
|
async function loadConfigEndpoints(req) {
|
|
const customConfig = await getCustomConfig();
|
|
|
|
if (!customConfig) {
|
|
return {};
|
|
}
|
|
|
|
const { endpoints = {} } = customConfig ?? {};
|
|
const endpointsConfig = {};
|
|
|
|
if (Array.isArray(endpoints[EModelEndpoint.custom])) {
|
|
const customEndpoints = endpoints[EModelEndpoint.custom].filter(
|
|
(endpoint) =>
|
|
endpoint.baseURL &&
|
|
endpoint.apiKey &&
|
|
endpoint.name &&
|
|
endpoint.models &&
|
|
(endpoint.models.fetch || endpoint.models.default),
|
|
);
|
|
|
|
for (let i = 0; i < customEndpoints.length; i++) {
|
|
const endpoint = customEndpoints[i];
|
|
const {
|
|
baseURL,
|
|
apiKey,
|
|
name: configName,
|
|
iconURL,
|
|
modelDisplayLabel,
|
|
customParams,
|
|
} = endpoint;
|
|
const name = normalizeEndpointName(configName);
|
|
|
|
const resolvedApiKey = extractEnvVariable(apiKey);
|
|
const resolvedBaseURL = extractEnvVariable(baseURL);
|
|
|
|
endpointsConfig[name] = {
|
|
type: EModelEndpoint.custom,
|
|
userProvide: isUserProvided(resolvedApiKey),
|
|
userProvideURL: isUserProvided(resolvedBaseURL),
|
|
modelDisplayLabel,
|
|
iconURL,
|
|
customParams,
|
|
};
|
|
}
|
|
}
|
|
|
|
if (req.app.locals[EModelEndpoint.azureOpenAI]) {
|
|
/** @type {Omit<TConfig, 'order'>} */
|
|
endpointsConfig[EModelEndpoint.azureOpenAI] = {
|
|
userProvide: false,
|
|
};
|
|
}
|
|
|
|
if (req.app.locals[EModelEndpoint.azureOpenAI]?.assistants) {
|
|
/** @type {Omit<TConfig, 'order'>} */
|
|
endpointsConfig[EModelEndpoint.azureAssistants] = {
|
|
userProvide: false,
|
|
};
|
|
}
|
|
|
|
return endpointsConfig;
|
|
}
|
|
|
|
module.exports = loadConfigEndpoints;
|