mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-11 04:58:51 +01:00
✨ feat: Implement Token Rates Configuration Loader and Update Config Types
This commit is contained in:
parent
e14df5956a
commit
7dfb386f5a
3 changed files with 78 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ const { agentsConfigSetup } = require('./start/agents');
|
|||
const { initializeRoles } = require('~/models/Role');
|
||||
const { getMCPManager } = require('~/config');
|
||||
const paths = require('~/config/paths');
|
||||
const { loadTokenRatesConfig } = require('./Config/loadTokenRatesConfig');
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -21,9 +22,13 @@ const paths = require('~/config/paths');
|
|||
*/
|
||||
const AppService = async (app) => {
|
||||
await initializeRoles();
|
||||
/** @type {TCustomConfig}*/
|
||||
/** @type {TCustomConfig} */
|
||||
const config = (await loadCustomConfig()) ?? {};
|
||||
const configDefaults = getConfigDefaults();
|
||||
const tokenRatesConfig = loadTokenRatesConfig(config, configDefaults);
|
||||
//
|
||||
// // Set the global token rates configuration so that it can be used by the tx.js functions.
|
||||
// setTokenRatesConfig(tokenRatesConfig);
|
||||
|
||||
const filteredTools = config.filteredTools;
|
||||
const includedTools = config.includedTools;
|
||||
|
|
|
|||
27
api/server/services/Config/loadTokenRatesConfig.js
Normal file
27
api/server/services/Config/loadTokenRatesConfig.js
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const { removeNullishValues } = require('librechat-data-provider');
|
||||
const { logger } = require('~/config');
|
||||
|
||||
/**
|
||||
* Loads custom token rates from the user's YAML config, merging with default token rates if available.
|
||||
*
|
||||
* @param {TCustomConfig | undefined} config - The loaded custom configuration.
|
||||
* @param {TConfigDefaults} [configDefaults] - Optional default configuration values.
|
||||
* @returns {TCustomConfig['tokenRates']} - The final token rates configuration.
|
||||
*/
|
||||
function loadTokenRatesConfig(config, configDefaults) {
|
||||
const userTokenRates = removeNullishValues(config?.tokenRates ?? {});
|
||||
|
||||
if (!configDefaults?.tokenRates) {
|
||||
logger.info(`User tokenRates configuration:\n${JSON.stringify(userTokenRates, null, 2)}`);
|
||||
return userTokenRates;
|
||||
}
|
||||
|
||||
/** @type {TCustomConfig['tokenRates']} */
|
||||
const defaultTokenRates = removeNullishValues(configDefaults.tokenRates);
|
||||
const merged = { ...defaultTokenRates, ...userTokenRates };
|
||||
|
||||
logger.info(`Merged tokenRates configuration:\n${JSON.stringify(merged, null, 2)}`);
|
||||
return merged;
|
||||
}
|
||||
|
||||
module.exports = { loadTokenRatesConfig };
|
||||
Loading…
Add table
Add a link
Reference in a new issue