mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
fix: filter valid references in buildFinalResult and repairMarkdownFootnotesOuter
This commit is contained in:
@@ -592,7 +592,7 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
|
|||||||
)
|
)
|
||||||
let finalAnswer = (finalStep as AnswerAction).mdAnswer;
|
let finalAnswer = (finalStep as AnswerAction).mdAnswer;
|
||||||
|
|
||||||
const annotations = (finalStep as AnswerAction).references?.map(ref => ({
|
const annotations = (finalStep as AnswerAction).references.filter(ref => ref?.url && ref?.title && ref?.exactQuote && ref?.dateTime).map(ref => ({
|
||||||
type: 'url_citation' as const,
|
type: 'url_citation' as const,
|
||||||
url_citation: {
|
url_citation: {
|
||||||
title: ref.title,
|
title: ref.title,
|
||||||
|
|||||||
@@ -290,10 +290,10 @@ function buildFinalResult(
|
|||||||
chunkToSourceMap: any
|
chunkToSourceMap: any
|
||||||
): { answer: string, references: Array<Reference> } {
|
): { answer: string, references: Array<Reference> } {
|
||||||
logDebug(`[buildFinalResult] Building final result with ${filteredMatches.length} references`);
|
logDebug(`[buildFinalResult] Building final result with ${filteredMatches.length} references`);
|
||||||
|
|
||||||
// Build reference objects
|
// Build reference objects
|
||||||
const references: Reference[] = filteredMatches.map((match) => {
|
const references = filteredMatches.map((match) => {
|
||||||
const source = chunkToSourceMap[match.webChunkIndex];
|
const source = chunkToSourceMap[match.webChunkIndex];
|
||||||
|
if (!source.text || !source.url || !source.title) return null;
|
||||||
return {
|
return {
|
||||||
exactQuote: source.text,
|
exactQuote: source.text,
|
||||||
url: source.url,
|
url: source.url,
|
||||||
@@ -303,7 +303,7 @@ function buildFinalResult(
|
|||||||
answerChunk: match.answerChunk,
|
answerChunk: match.answerChunk,
|
||||||
answerChunkPosition: match.answerChunkPosition
|
answerChunkPosition: match.answerChunkPosition
|
||||||
};
|
};
|
||||||
});
|
}).filter(Boolean) as Reference[];
|
||||||
|
|
||||||
// Inject reference markers ([^1], [^2], etc.) into the answer
|
// Inject reference markers ([^1], [^2], etc.) into the answer
|
||||||
let modifiedAnswer = answer;
|
let modifiedAnswer = answer;
|
||||||
|
|||||||
@@ -223,11 +223,13 @@ export function repairMarkdownFootnotesOuter(markdownString: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add to references array
|
// Add to references array
|
||||||
references.push({
|
if (content && title && url) {
|
||||||
exactQuote: content,
|
references.push({
|
||||||
url,
|
exactQuote: content,
|
||||||
title
|
url,
|
||||||
});
|
title,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only process if we found valid references
|
// Only process if we found valid references
|
||||||
|
|||||||
Reference in New Issue
Block a user