| | const { loadCustomEndpointsConfig } = require('@librechat/api'); |
| | const { |
| | CacheKeys, |
| | EModelEndpoint, |
| | isAgentsEndpoint, |
| | orderEndpointsConfig, |
| | defaultAgentCapabilities, |
| | } = require('librechat-data-provider'); |
| | const loadDefaultEndpointsConfig = require('./loadDefaultEConfig'); |
| | const getLogStores = require('~/cache/getLogStores'); |
| | const { getAppConfig } = require('./app'); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async function getEndpointsConfig(req) { |
| | const cache = getLogStores(CacheKeys.CONFIG_STORE); |
| | const cachedEndpointsConfig = await cache.get(CacheKeys.ENDPOINT_CONFIG); |
| | if (cachedEndpointsConfig) { |
| | return cachedEndpointsConfig; |
| | } |
| |
|
| | const appConfig = req.config ?? (await getAppConfig({ role: req.user?.role })); |
| | const defaultEndpointsConfig = await loadDefaultEndpointsConfig(appConfig); |
| | const customEndpointsConfig = loadCustomEndpointsConfig(appConfig?.endpoints?.custom); |
| |
|
| | |
| | const mergedConfig = { |
| | ...defaultEndpointsConfig, |
| | ...customEndpointsConfig, |
| | }; |
| |
|
| | if (appConfig.endpoints?.[EModelEndpoint.azureOpenAI]) { |
| | |
| | mergedConfig[EModelEndpoint.azureOpenAI] = { |
| | userProvide: false, |
| | }; |
| | } |
| |
|
| | if (appConfig.endpoints?.[EModelEndpoint.azureOpenAI]?.assistants) { |
| | |
| | mergedConfig[EModelEndpoint.azureAssistants] = { |
| | userProvide: false, |
| | }; |
| | } |
| |
|
| | if ( |
| | mergedConfig[EModelEndpoint.assistants] && |
| | appConfig?.endpoints?.[EModelEndpoint.assistants] |
| | ) { |
| | const { disableBuilder, retrievalModels, capabilities, version, ..._rest } = |
| | appConfig.endpoints[EModelEndpoint.assistants]; |
| |
|
| | mergedConfig[EModelEndpoint.assistants] = { |
| | ...mergedConfig[EModelEndpoint.assistants], |
| | version, |
| | retrievalModels, |
| | disableBuilder, |
| | capabilities, |
| | }; |
| | } |
| | if (mergedConfig[EModelEndpoint.agents] && appConfig?.endpoints?.[EModelEndpoint.agents]) { |
| | const { disableBuilder, capabilities, allowedProviders, ..._rest } = |
| | appConfig.endpoints[EModelEndpoint.agents]; |
| |
|
| | mergedConfig[EModelEndpoint.agents] = { |
| | ...mergedConfig[EModelEndpoint.agents], |
| | allowedProviders, |
| | disableBuilder, |
| | capabilities, |
| | }; |
| | } |
| |
|
| | if ( |
| | mergedConfig[EModelEndpoint.azureAssistants] && |
| | appConfig?.endpoints?.[EModelEndpoint.azureAssistants] |
| | ) { |
| | const { disableBuilder, retrievalModels, capabilities, version, ..._rest } = |
| | appConfig.endpoints[EModelEndpoint.azureAssistants]; |
| |
|
| | mergedConfig[EModelEndpoint.azureAssistants] = { |
| | ...mergedConfig[EModelEndpoint.azureAssistants], |
| | version, |
| | retrievalModels, |
| | disableBuilder, |
| | capabilities, |
| | }; |
| | } |
| |
|
| | if (mergedConfig[EModelEndpoint.bedrock] && appConfig?.endpoints?.[EModelEndpoint.bedrock]) { |
| | const { availableRegions } = appConfig.endpoints[EModelEndpoint.bedrock]; |
| | mergedConfig[EModelEndpoint.bedrock] = { |
| | ...mergedConfig[EModelEndpoint.bedrock], |
| | availableRegions, |
| | }; |
| | } |
| |
|
| | const endpointsConfig = orderEndpointsConfig(mergedConfig); |
| |
|
| | await cache.set(CacheKeys.ENDPOINT_CONFIG, endpointsConfig); |
| | return endpointsConfig; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | const checkCapability = async (req, capability) => { |
| | const isAgents = isAgentsEndpoint(req.body?.endpointType || req.body?.endpoint); |
| | const endpointsConfig = await getEndpointsConfig(req); |
| | const capabilities = |
| | isAgents || endpointsConfig?.[EModelEndpoint.agents]?.capabilities != null |
| | ? (endpointsConfig?.[EModelEndpoint.agents]?.capabilities ?? []) |
| | : defaultAgentCapabilities; |
| | return capabilities.includes(capability); |
| | }; |
| |
|
| | module.exports = { getEndpointsConfig, checkCapability }; |
| |
|