From 39799469d181dee02ff369aab6e7e6c97197a751 Mon Sep 17 00:00:00 2001 From: balibabu Date: Fri, 4 Jul 2025 19:12:13 +0800 Subject: [PATCH] Fix: Wrong Citation Display #8594 #8474 (#8671) ### What problem does this PR solve? Fix: Wrong Citation Display #8594 #8474 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/pages/chat/markdown-content/index.tsx | 4 ++-- web/src/pages/chat/utils.ts | 16 ++++++---------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/web/src/pages/chat/markdown-content/index.tsx b/web/src/pages/chat/markdown-content/index.tsx index 61b27347d..2d6393d42 100644 --- a/web/src/pages/chat/markdown-content/index.tsx +++ b/web/src/pages/chat/markdown-content/index.tsx @@ -31,7 +31,7 @@ import classNames from 'classnames'; import { pipe } from 'lodash/fp'; import styles from './index.less'; -const getChunkIndex = (match: string) => Number(match.slice(2, -2)); +const getChunkIndex = (match: string) => Number(match); // TODO: The display of the table is inconsistent with the display previously placed in the MessageItem. const MarkdownContent = ({ reference, @@ -121,7 +121,7 @@ const MarkdownContent = ({ document, }; }, - [fileThumbnails, reference?.chunks, reference?.doc_aggs], + [fileThumbnails, reference], ); const getPopoverContent = useCallback( diff --git a/web/src/pages/chat/utils.ts b/web/src/pages/chat/utils.ts index a36f08f3e..aa5cadd09 100644 --- a/web/src/pages/chat/utils.ts +++ b/web/src/pages/chat/utils.ts @@ -29,9 +29,9 @@ export const buildMessageItemReference = ( conversation: { message: IMessage[]; reference: IReference[] }, message: IMessage, ) => { - const assistantMessages = conversation.message?.filter( - (x) => x.role === MessageType.Assistant, - ); + const assistantMessages = conversation.message + ?.filter((x) => x.role === MessageType.Assistant) + .slice(1); const referenceIndex = assistantMessages.findIndex( (x) => x.id === message.id, ); @@ -47,11 +47,7 @@ export const currentReg = /\[ID:(\d+)\]/g; // To be compatible with the old index matching mode export const replaceTextByOldReg = (text: string) => { - return ( - text - // ?.replace(currentReg, transformReg) - .replace(oldReg, (substring: string) => { - return `[ID:${substring.slice(2, -2)}]`; - }) - ); + return text.replace(oldReg, (substring: string) => { + return `[ID:${substring.slice(2, -2)}]`; + }); };