mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 19:30: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,9 +1,15 @@
|
|||
const { nanoid } = require('nanoid');
|
||||
const { checkAccess } = require('@librechat/api');
|
||||
const { Tools, PermissionTypes, Permissions } = require('librechat-data-provider');
|
||||
const { getCustomConfig } = require('~/server/services/Config/getCustomConfig');
|
||||
const { logger } = require('@librechat/data-schemas');
|
||||
const {
|
||||
Tools,
|
||||
Permissions,
|
||||
FileSources,
|
||||
EModelEndpoint,
|
||||
PermissionTypes,
|
||||
} = require('librechat-data-provider');
|
||||
const { getAppConfig } = require('~/server/services/Config/app');
|
||||
const { getRoleByName } = require('~/models/Role');
|
||||
const { logger } = require('~/config');
|
||||
const { Files } = require('~/models');
|
||||
|
||||
/**
|
||||
|
|
@ -44,10 +50,10 @@ async function processFileCitations({ user, toolArtifact, toolCallId, metadata }
|
|||
}
|
||||
}
|
||||
|
||||
const customConfig = await getCustomConfig();
|
||||
const maxCitations = customConfig?.endpoints?.agents?.maxCitations ?? 30;
|
||||
const maxCitationsPerFile = customConfig?.endpoints?.agents?.maxCitationsPerFile ?? 5;
|
||||
const minRelevanceScore = customConfig?.endpoints?.agents?.minRelevanceScore ?? 0.45;
|
||||
const appConfig = await getAppConfig({ role: user?.role });
|
||||
const maxCitations = appConfig?.[EModelEndpoint.agents]?.maxCitations ?? 30;
|
||||
const maxCitationsPerFile = appConfig?.[EModelEndpoint.agents]?.maxCitationsPerFile ?? 5;
|
||||
const minRelevanceScore = appConfig?.[EModelEndpoint.agents]?.minRelevanceScore ?? 0.45;
|
||||
|
||||
const sources = toolArtifact[Tools.file_search].sources || [];
|
||||
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 enhancedSources = await enhanceSourcesWithMetadata(selectedSources, customConfig);
|
||||
const enhancedSources = await enhanceSourcesWithMetadata(selectedSources, appConfig);
|
||||
|
||||
if (enhancedSources.length > 0) {
|
||||
const fileSearchAttachment = {
|
||||
|
|
@ -110,10 +116,10 @@ function applyCitationLimits(sources, maxCitations, maxCitationsPerFile) {
|
|||
/**
|
||||
* Enhance sources with file metadata from database
|
||||
* @param {Array} sources - Selected sources
|
||||
* @param {Object} customConfig - Custom configuration
|
||||
* @param {AppConfig} appConfig - Custom configuration
|
||||
* @returns {Promise<Array>} Enhanced sources
|
||||
*/
|
||||
async function enhanceSourcesWithMetadata(sources, customConfig) {
|
||||
async function enhanceSourcesWithMetadata(sources, appConfig) {
|
||||
const fileIds = [...new Set(sources.map((source) => source.fileId))];
|
||||
|
||||
let fileMetadataMap = {};
|
||||
|
|
@ -129,7 +135,7 @@ async function enhanceSourcesWithMetadata(sources, customConfig) {
|
|||
|
||||
return sources.map((source) => {
|
||||
const fileRecord = fileMetadataMap[source.fileId] || {};
|
||||
const configuredStorageType = fileRecord.source || customConfig?.fileStrategy || 'local';
|
||||
const configuredStorageType = fileRecord.source || appConfig?.fileStrategy || FileSources.local;
|
||||
|
||||
return {
|
||||
...source,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue