Skip to content

Commit 6bfb2b5

Browse files
committed
add removeDuplicateURL
1 parent e11fdfc commit 6bfb2b5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/ui/src/views/chatmessage/ChatMessage.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
6464
window.open(data, '_blank')
6565
}
6666

67+
const removeDuplicateURL = (message) => {
68+
const visitedURLs = []
69+
const newSourceDocuments = []
70+
message.sourceDocuments.forEach((source) => {
71+
if (isValidURL(source.metadata.source) && !visitedURLs.includes(source.metadata.source)) {
72+
visitedURLs.push(source.metadata.source)
73+
newSourceDocuments.push(source)
74+
} else if (!isValidURL(source.metadata.source)) {
75+
newSourceDocuments.push(source)
76+
}
77+
})
78+
return newSourceDocuments
79+
}
80+
6781
const scrollToBottom = () => {
6882
if (ps.current) {
6983
ps.current.scrollTo({ top: maxScroll })
@@ -324,7 +338,7 @@ export const ChatMessage = ({ open, chatflowid, isDialog }) => {
324338
</div>
325339
{message.sourceDocuments && (
326340
<div style={{ display: 'block', flexDirection: 'row', width: '100%' }}>
327-
{message.sourceDocuments.map((source, index) => {
341+
{removeDuplicateURL(message).map((source, index) => {
328342
const URL = isValidURL(source.metadata.source)
329343
return (
330344
<Chip

0 commit comments

Comments
 (0)