mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 04:06:18 +00:00
add answer quote number (#4658)
This commit is contained in:
@@ -338,7 +338,17 @@ async function filterDatasetQuote({
|
||||
model: LLMModelItemType;
|
||||
quoteTemplate: string;
|
||||
}) {
|
||||
function getValue(item: SearchDataResponseItemType, index: number) {
|
||||
function getValue({
|
||||
item,
|
||||
index,
|
||||
sourceList
|
||||
}: {
|
||||
item: SearchDataResponseItemType;
|
||||
index: number;
|
||||
sourceList: { sourceName: string; sourceId: string; sourceIndex: number }[];
|
||||
}) {
|
||||
const source = sourceList.find((source) => source.sourceId === item.sourceId);
|
||||
|
||||
return replaceVariable(quoteTemplate, {
|
||||
id: item.id,
|
||||
q: item.q,
|
||||
@@ -346,6 +356,7 @@ async function filterDatasetQuote({
|
||||
updateTime: formatTime2YMDHM(item.updateTime),
|
||||
source: item.sourceName,
|
||||
sourceId: String(item.sourceId || ''),
|
||||
sourceIndex: source?.sourceIndex || 1,
|
||||
index: index + 1
|
||||
});
|
||||
}
|
||||
@@ -353,9 +364,24 @@ async function filterDatasetQuote({
|
||||
// slice filterSearch
|
||||
const filterQuoteQA = await filterSearchResultsByMaxChars(quoteQA, model.quoteMaxToken);
|
||||
|
||||
const sourceList = Object.values(
|
||||
filterQuoteQA.reduce((acc: Record<string, SearchDataResponseItemType[]>, cur) => {
|
||||
if (!acc[cur.collectionId]) {
|
||||
acc[cur.collectionId] = [cur];
|
||||
}
|
||||
return acc;
|
||||
}, {})
|
||||
)
|
||||
.flat()
|
||||
.map((item, index) => ({
|
||||
sourceName: item.sourceName || '',
|
||||
sourceId: item.sourceId || '',
|
||||
sourceIndex: index + 1
|
||||
}));
|
||||
|
||||
const datasetQuoteText =
|
||||
filterQuoteQA.length > 0
|
||||
? `${filterQuoteQA.map((item, index) => getValue(item, index).trim()).join('\n------\n')}`
|
||||
? `${filterQuoteQA.map((item, index) => getValue({ item, index, sourceList }).trim()).join('\n------\n')}`
|
||||
: '';
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user