mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
* 🧹 chore: Update logger imports to use @librechat/data-schemas across multiple files and remove unused sleep function from queue.js (#9930) * chore: Replace local isEnabled utility with @librechat/api import across multiple files, update test files * chore: Replace local logger import with @librechat/data-schemas logger in countTokens.js and fork.js * chore: Update logs volume path in docker-compose.yml to correct directory * chore: import order of isEnabled in static.js
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
const { logger } = require('@librechat/data-schemas');
|
|
const { CacheKeys } = require('librechat-data-provider');
|
|
const { loadDefaultModels, loadConfigModels } = require('~/server/services/Config');
|
|
const { getLogStores } = require('~/cache');
|
|
|
|
/**
|
|
* @param {ServerRequest} req
|
|
* @returns {Promise<TModelsConfig>} The models config.
|
|
*/
|
|
const getModelsConfig = async (req) => {
|
|
const cache = getLogStores(CacheKeys.CONFIG_STORE);
|
|
let modelsConfig = await cache.get(CacheKeys.MODELS_CONFIG);
|
|
if (!modelsConfig) {
|
|
modelsConfig = await loadModels(req);
|
|
}
|
|
|
|
return modelsConfig;
|
|
};
|
|
|
|
/**
|
|
* Loads the models from the config.
|
|
* @param {ServerRequest} req - The Express request object.
|
|
* @returns {Promise<TModelsConfig>} The models config.
|
|
*/
|
|
async function loadModels(req) {
|
|
const cache = getLogStores(CacheKeys.CONFIG_STORE);
|
|
const cachedModelsConfig = await cache.get(CacheKeys.MODELS_CONFIG);
|
|
if (cachedModelsConfig) {
|
|
return cachedModelsConfig;
|
|
}
|
|
const defaultModelsConfig = await loadDefaultModels(req);
|
|
const customModelsConfig = await loadConfigModels(req);
|
|
|
|
const modelConfig = { ...defaultModelsConfig, ...customModelsConfig };
|
|
|
|
await cache.set(CacheKeys.MODELS_CONFIG, modelConfig);
|
|
return modelConfig;
|
|
}
|
|
|
|
async function modelController(req, res) {
|
|
try {
|
|
const modelConfig = await loadModels(req);
|
|
res.send(modelConfig);
|
|
} catch (error) {
|
|
logger.error('Error fetching models:', error);
|
|
res.status(500).send({ error: error.message });
|
|
}
|
|
}
|
|
|
|
module.exports = { modelController, loadModels, getModelsConfig };
|