mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 11:20:15 +01:00
refactor: remove getCustomConfig usage and use app config in file citations
This commit is contained in:
parent
46f9c90223
commit
8525c8df36
4 changed files with 29 additions and 30 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
const appConfig = require('./app');
|
const appConfig = require('./app');
|
||||||
const { config } = require('./EndpointService');
|
const { config } = require('./EndpointService');
|
||||||
const getCachedTools = require('./getCachedTools');
|
const getCachedTools = require('./getCachedTools');
|
||||||
const getCustomConfig = require('./getCustomConfig');
|
|
||||||
const loadCustomConfig = require('./loadCustomConfig');
|
const loadCustomConfig = require('./loadCustomConfig');
|
||||||
const loadConfigModels = require('./loadConfigModels');
|
const loadConfigModels = require('./loadConfigModels');
|
||||||
const loadDefaultModels = require('./loadDefaultModels');
|
const loadDefaultModels = require('./loadDefaultModels');
|
||||||
|
|
@ -18,6 +17,5 @@ module.exports = {
|
||||||
loadAsyncEndpoints,
|
loadAsyncEndpoints,
|
||||||
...appConfig,
|
...appConfig,
|
||||||
...getCachedTools,
|
...getCachedTools,
|
||||||
...getCustomConfig,
|
|
||||||
...getEndpointsConfig,
|
...getEndpointsConfig,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
const { isUserProvided, normalizeEndpointName } = require('@librechat/api');
|
const { isUserProvided, normalizeEndpointName } = require('@librechat/api');
|
||||||
const { EModelEndpoint, extractEnvVariable } = require('librechat-data-provider');
|
const { EModelEndpoint, extractEnvVariable } = require('librechat-data-provider');
|
||||||
const { getCustomConfig } = require('./getCustomConfig');
|
|
||||||
const { getAppConfig } = require('./app');
|
const { getAppConfig } = require('./app');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -9,19 +8,15 @@ const { getAppConfig } = require('./app');
|
||||||
* @returns {Promise<TEndpointsConfig>} A promise that resolves to an object containing the endpoints configuration
|
* @returns {Promise<TEndpointsConfig>} A promise that resolves to an object containing the endpoints configuration
|
||||||
*/
|
*/
|
||||||
async function loadConfigEndpoints(req) {
|
async function loadConfigEndpoints(req) {
|
||||||
const customConfig = await getCustomConfig();
|
const appConfig = await getAppConfig({ role: req.user?.role });
|
||||||
|
if (!appConfig) {
|
||||||
if (!customConfig) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const appConfig = await getAppConfig({ role: req.user?.role });
|
|
||||||
|
|
||||||
const { endpoints = {} } = customConfig ?? {};
|
|
||||||
const endpointsConfig = {};
|
const endpointsConfig = {};
|
||||||
|
|
||||||
if (Array.isArray(endpoints[EModelEndpoint.custom])) {
|
if (Array.isArray(appConfig[EModelEndpoint.custom])) {
|
||||||
const customEndpoints = endpoints[EModelEndpoint.custom].filter(
|
const customEndpoints = appConfig[EModelEndpoint.custom].filter(
|
||||||
(endpoint) =>
|
(endpoint) =>
|
||||||
endpoint.baseURL &&
|
endpoint.baseURL &&
|
||||||
endpoint.apiKey &&
|
endpoint.apiKey &&
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
const { nanoid } = require('nanoid');
|
const { nanoid } = require('nanoid');
|
||||||
const { checkAccess } = require('@librechat/api');
|
const { checkAccess } = require('@librechat/api');
|
||||||
const { Tools, PermissionTypes, Permissions } = require('librechat-data-provider');
|
const { logger } = require('@librechat/data-schemas');
|
||||||
const { getCustomConfig } = require('~/server/services/Config/getCustomConfig');
|
const {
|
||||||
|
Tools,
|
||||||
|
Permissions,
|
||||||
|
FileSources,
|
||||||
|
EModelEndpoint,
|
||||||
|
PermissionTypes,
|
||||||
|
} = require('librechat-data-provider');
|
||||||
|
const { getAppConfig } = require('~/server/services/Config/app');
|
||||||
const { getRoleByName } = require('~/models/Role');
|
const { getRoleByName } = require('~/models/Role');
|
||||||
const { logger } = require('~/config');
|
|
||||||
const { Files } = require('~/models');
|
const { Files } = require('~/models');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,10 +50,10 @@ async function processFileCitations({ user, toolArtifact, toolCallId, metadata }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const customConfig = await getCustomConfig();
|
const appConfig = await getAppConfig({ role: user?.role });
|
||||||
const maxCitations = customConfig?.endpoints?.agents?.maxCitations ?? 30;
|
const maxCitations = appConfig?.[EModelEndpoint.agents]?.maxCitations ?? 30;
|
||||||
const maxCitationsPerFile = customConfig?.endpoints?.agents?.maxCitationsPerFile ?? 5;
|
const maxCitationsPerFile = appConfig?.[EModelEndpoint.agents]?.maxCitationsPerFile ?? 5;
|
||||||
const minRelevanceScore = customConfig?.endpoints?.agents?.minRelevanceScore ?? 0.45;
|
const minRelevanceScore = appConfig?.[EModelEndpoint.agents]?.minRelevanceScore ?? 0.45;
|
||||||
|
|
||||||
const sources = toolArtifact[Tools.file_search].sources || [];
|
const sources = toolArtifact[Tools.file_search].sources || [];
|
||||||
const filteredSources = sources.filter((source) => source.relevance >= minRelevanceScore);
|
const filteredSources = sources.filter((source) => source.relevance >= minRelevanceScore);
|
||||||
|
|
@ -59,7 +65,7 @@ async function processFileCitations({ user, toolArtifact, toolCallId, metadata }
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedSources = applyCitationLimits(filteredSources, maxCitations, maxCitationsPerFile);
|
const selectedSources = applyCitationLimits(filteredSources, maxCitations, maxCitationsPerFile);
|
||||||
const enhancedSources = await enhanceSourcesWithMetadata(selectedSources, customConfig);
|
const enhancedSources = await enhanceSourcesWithMetadata(selectedSources, appConfig);
|
||||||
|
|
||||||
if (enhancedSources.length > 0) {
|
if (enhancedSources.length > 0) {
|
||||||
const fileSearchAttachment = {
|
const fileSearchAttachment = {
|
||||||
|
|
@ -110,10 +116,10 @@ function applyCitationLimits(sources, maxCitations, maxCitationsPerFile) {
|
||||||
/**
|
/**
|
||||||
* Enhance sources with file metadata from database
|
* Enhance sources with file metadata from database
|
||||||
* @param {Array} sources - Selected sources
|
* @param {Array} sources - Selected sources
|
||||||
* @param {Object} customConfig - Custom configuration
|
* @param {AppConfig} appConfig - Custom configuration
|
||||||
* @returns {Promise<Array>} Enhanced sources
|
* @returns {Promise<Array>} Enhanced sources
|
||||||
*/
|
*/
|
||||||
async function enhanceSourcesWithMetadata(sources, customConfig) {
|
async function enhanceSourcesWithMetadata(sources, appConfig) {
|
||||||
const fileIds = [...new Set(sources.map((source) => source.fileId))];
|
const fileIds = [...new Set(sources.map((source) => source.fileId))];
|
||||||
|
|
||||||
let fileMetadataMap = {};
|
let fileMetadataMap = {};
|
||||||
|
|
@ -129,7 +135,7 @@ async function enhanceSourcesWithMetadata(sources, customConfig) {
|
||||||
|
|
||||||
return sources.map((source) => {
|
return sources.map((source) => {
|
||||||
const fileRecord = fileMetadataMap[source.fileId] || {};
|
const fileRecord = fileMetadataMap[source.fileId] || {};
|
||||||
const configuredStorageType = fileRecord.source || customConfig?.fileStrategy || 'local';
|
const configuredStorageType = fileRecord.source || appConfig?.fileStrategy || FileSources.local;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...source,
|
...source,
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,17 @@ jest.mock('@librechat/api', () => ({
|
||||||
checkAccess: jest.fn().mockResolvedValue(true),
|
checkAccess: jest.fn().mockResolvedValue(true),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('~/server/services/Config/getCustomConfig', () => ({
|
jest.mock('~/cache/getLogStores', () => () => ({
|
||||||
getCustomConfig: jest.fn().mockResolvedValue({
|
get: jest.fn().mockResolvedValue({
|
||||||
endpoints: {
|
|
||||||
agents: {
|
agents: {
|
||||||
maxCitations: 30,
|
maxCitations: 30,
|
||||||
maxCitationsPerFile: 5,
|
maxCitationsPerFile: 5,
|
||||||
minRelevanceScore: 0.45,
|
minRelevanceScore: 0.45,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
fileStrategy: 'local',
|
fileStrategy: 'local',
|
||||||
}),
|
}),
|
||||||
|
set: jest.fn(),
|
||||||
|
delete: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('~/config', () => ({
|
jest.mock('~/config', () => ({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue