fix: references gen

This commit is contained in:
Han Xiao
2025-02-18 14:54:54 +08:00
parent 4b38781cd8
commit ff5c6f142c

View File

@@ -36,7 +36,7 @@ function buildMdFromAnswer(answer: AnswerAction) {
return refs.map((ref, i) => { return refs.map((ref, i) => {
const cleanQuote = ref.exactQuote const cleanQuote = ref.exactQuote
.replace(/[^\p{L}\p{N}\s]/gu, ' ') .replace(/[^\p{L}\p{N}\s]/gu, ' ')
.replace(/\s+/, ' '); .replace(/\s+/g, ' ');
const citation = `[^${i + 1}]: ${cleanQuote}`; const citation = `[^${i + 1}]: ${cleanQuote}`;
@@ -80,6 +80,24 @@ ${references}
(footnotes.length === answer.references.length && footnotes.every(n => n === footnotes[0])) || (footnotes.length === answer.references.length && footnotes.every(n => n === footnotes[0])) ||
(footnotes.every(n => n === footnotes[0]) && parseInt(footnotes[0]) > answer.references.length); (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) { if (!needsCorrection) {
return ` return `
${answer.answer} ${answer.answer}