LibreChat/api/server/services/Config/loadCustomConfig.js
Danny Avila ff057152e2
👤 feat: User ID in Model Query; chore: cleanup ModelService (#1753)
* 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
2024-02-08 10:06:58 -05:00

43 lines
1.4 KiB
JavaScript

const path = require('path');
const { CacheKeys, configSchema } = require('librechat-data-provider');
const loadYaml = require('~/utils/loadYaml');
const { getLogStores } = require('~/cache');
const { logger } = require('~/config');
const projectRoot = path.resolve(__dirname, '..', '..', '..', '..');
const configPath = path.resolve(projectRoot, 'librechat.yaml');
/**
* Load custom configuration files and caches the object if the `cache` field at root is true.
* Validation via parsing the config file with the config schema.
* @function loadCustomConfig
* @returns {Promise<TCustomConfig | null>} A promise that resolves to null or the custom config object.
* */
async function loadCustomConfig() {
const customConfig = loadYaml(configPath);
if (!customConfig) {
logger.info('Custom config file missing or YAML format invalid.');
return null;
}
const result = configSchema.strict().safeParse(customConfig);
if (!result.success) {
logger.error(`Invalid custom config file at ${configPath}`, result.error);
return null;
} else {
logger.info('Custom config file loaded:');
logger.info(JSON.stringify(customConfig, null, 2));
}
if (customConfig.cache) {
const cache = getLogStores(CacheKeys.CONFIG_STORE);
await cache.set(CacheKeys.CUSTOM_CONFIG, customConfig);
}
// TODO: handle remote config
return customConfig;
}
module.exports = loadCustomConfig;