From ff5c6f142cfcab598eb831b6053d50d9316ac55e Mon Sep 17 00:00:00 2001 From: Han Xiao Date: Tue, 18 Feb 2025 14:54:54 +0800 Subject: [PATCH] fix: references gen --- src/app.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 59d2dc9..1050f60 100644 --- a/src/app.ts +++ b/src/app.ts @@ -36,7 +36,7 @@ function buildMdFromAnswer(answer: AnswerAction) { return refs.map((ref, i) => { const cleanQuote = ref.exactQuote .replace(/[^\p{L}\p{N}\s]/gu, ' ') - .replace(/\s+/, ' '); + .replace(/\s+/g, ' '); const citation = `[^${i + 1}]: ${cleanQuote}`; @@ -80,6 +80,24 @@ ${references} (footnotes.length === answer.references.length && footnotes.every(n => n === footnotes[0])) || (footnotes.every(n => n === footnotes[0]) && parseInt(footnotes[0]) > answer.references.length); + // New case: we have more references than footnotes + if (answer.references.length > footnotes.length && !needsCorrection) { + // Get the used indices + const usedIndices = new Set(footnotes.map(n => parseInt(n))); + + // Create citations for unused references + const unusedReferences = Array.from( + {length: answer.references.length}, + (_, i) => !usedIndices.has(i + 1) ? `[^${i + 1}]` : '' + ).join(''); + + return ` +${answer.answer} ${unusedReferences} + +${formatReferences(answer.references)} +`.trim(); + } + if (!needsCorrection) { return ` ${answer.answer}