mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
fix: md ref
This commit is contained in:
parent
1f9565ec84
commit
098564eb81
@ -996,7 +996,7 @@ But unfortunately, you failed to solve the issue. You need to think out of the b
|
|||||||
answerStep.answer = answer;
|
answerStep.answer = answer;
|
||||||
answerStep.references = references;
|
answerStep.references = references;
|
||||||
await updateReferences(answerStep, allURLs)
|
await updateReferences(answerStep, allURLs)
|
||||||
answerStep.mdAnswer = buildMdFromAnswer(answerStep);
|
answerStep.mdAnswer = repairMarkdownFootnotesOuter(buildMdFromAnswer(answerStep));
|
||||||
} else {
|
} else {
|
||||||
answerStep.mdAnswer =
|
answerStep.mdAnswer =
|
||||||
convertHtmlTablesToMd(
|
convertHtmlTablesToMd(
|
||||||
|
|||||||
@ -223,7 +223,7 @@ export async function buildReferences(
|
|||||||
const referencesByPosition = [...references]
|
const referencesByPosition = [...references]
|
||||||
.sort((a, b) => a.answerChunkPosition![0] - b.answerChunkPosition![0]);
|
.sort((a, b) => a.answerChunkPosition![0] - b.answerChunkPosition![0]);
|
||||||
|
|
||||||
// Insert markers from beginning to end, tracking offset
|
// Insert markers from beginning to end, tracking offset
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
for (let i = 0; i < referencesByPosition.length; i++) {
|
for (let i = 0; i < referencesByPosition.length; i++) {
|
||||||
const ref = referencesByPosition[i];
|
const ref = referencesByPosition[i];
|
||||||
@ -232,7 +232,24 @@ export async function buildReferences(
|
|||||||
// Calculate position to insert the marker (end of the chunk + current offset)
|
// Calculate position to insert the marker (end of the chunk + current offset)
|
||||||
let insertPosition = ref.answerChunkPosition![1] + offset;
|
let insertPosition = ref.answerChunkPosition![1] + offset;
|
||||||
|
|
||||||
// Check if there's a newline or table pipe at the end of the chunk and adjust position
|
// Look ahead to check if there's a list item coming next
|
||||||
|
const textAfterInsert = modifiedAnswer.substring(insertPosition);
|
||||||
|
const nextListItemMatch = textAfterInsert.match(/^\s*\n\s*\*/);
|
||||||
|
|
||||||
|
// If we're at a position where the next content is a list item,
|
||||||
|
// we need to adjust WHERE we place the footnote
|
||||||
|
if (nextListItemMatch) {
|
||||||
|
// Move the marker to right after the last content character,
|
||||||
|
// but INSIDE any punctuation at the end of the content
|
||||||
|
const beforeText = modifiedAnswer.substring(Math.max(0, insertPosition - 30), insertPosition);
|
||||||
|
const lastPunctuation = beforeText.match(/[!。?!.?]$/);
|
||||||
|
|
||||||
|
if (lastPunctuation) {
|
||||||
|
// If there's punctuation at the end, insert the marker before it
|
||||||
|
insertPosition--;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// The original conditions for newlines and table pipes can remain
|
||||||
const chunkEndText = modifiedAnswer.substring(Math.max(0, insertPosition - 5), insertPosition);
|
const chunkEndText = modifiedAnswer.substring(Math.max(0, insertPosition - 5), insertPosition);
|
||||||
const newlineMatch = chunkEndText.match(/\n+$/);
|
const newlineMatch = chunkEndText.match(/\n+$/);
|
||||||
const tableEndMatch = chunkEndText.match(/\s*\|\s*$/);
|
const tableEndMatch = chunkEndText.match(/\s*\|\s*$/);
|
||||||
@ -244,6 +261,7 @@ export async function buildReferences(
|
|||||||
// Move the insertion position before the table end pipe
|
// Move the insertion position before the table end pipe
|
||||||
insertPosition -= tableEndMatch[0].length;
|
insertPosition -= tableEndMatch[0].length;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Insert the marker
|
// Insert the marker
|
||||||
modifiedAnswer =
|
modifiedAnswer =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user