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

* feat: send the LibreChat user ID as a query param when fetching the list of models * chore: update bun * chore: change bun command for building data-provider * refactor: prefer use of `getCustomConfig` to access custom config, also move to `server/services/Config` * refactor: make endpoints/custom option for the config optional, add userIdQuery, and use modelQueries log store in ModelService * refactor(ModelService): use env variables at runtime, use default models from data-provider, and add tests * docs: add `userIdQuery` * fix(ci): import changed
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
const { EModelEndpoint } = require('librechat-data-provider');
|
|
const { isUserProvided, extractEnvVariable } = require('~/server/utils');
|
|
const getCustomConfig = require('./getCustomConfig');
|
|
|
|
/**
|
|
* Load config endpoints from the cached configuration object
|
|
* @function loadConfigEndpoints */
|
|
async function loadConfigEndpoints() {
|
|
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, iconURL, modelDisplayLabel } = endpoint;
|
|
|
|
const resolvedApiKey = extractEnvVariable(apiKey);
|
|
const resolvedBaseURL = extractEnvVariable(baseURL);
|
|
|
|
endpointsConfig[name] = {
|
|
type: EModelEndpoint.custom,
|
|
userProvide: isUserProvided(resolvedApiKey),
|
|
userProvideURL: isUserProvided(resolvedBaseURL),
|
|
modelDisplayLabel,
|
|
iconURL,
|
|
};
|
|
}
|
|
}
|
|
|
|
return endpointsConfig;
|
|
}
|
|
|
|
module.exports = loadConfigEndpoints;
|