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