mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* fix: handle non-assistant role ChatCompletionMessage error * refactor(ModelController): decouple res.send from loading/caching models * fix(custom/initializeClient): only fetch custom endpoint models if models.fetch is true * refactor(validateModel): load models if modelsConfig is not yet cached * docs: update on file upload rate limiting
30 lines
1,014 B
JavaScript
30 lines
1,014 B
JavaScript
const { CacheKeys } = require('librechat-data-provider');
|
|
const { loadDefaultModels, loadConfigModels } = require('~/server/services/Config');
|
|
const { getLogStores } = require('~/cache');
|
|
|
|
/**
|
|
* Loads the models from the config.
|
|
* @param {Express.Request} 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) {
|
|
const modelConfig = await loadModels(req);
|
|
res.send(modelConfig);
|
|
}
|
|
|
|
module.exports = { modelController, loadModels };
|