mirror of
https://github.com/run-llama/chat-ui.git
synced 2026-07-22 11:45:34 -04:00
fix: use multiple sources per message (#91)
* fix: use multiple sources per message * remove node score threshhold and sorting * Create silly-swans-swim.md
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@llamaindex/chat-ui': patch
|
||||
---
|
||||
|
||||
fix: use multiple sources per message
|
||||
@@ -98,8 +98,6 @@ export type MessageAnnotation = {
|
||||
data: AnnotationData
|
||||
}
|
||||
|
||||
const NODE_SCORE_THRESHOLD = 0.25
|
||||
|
||||
/**
|
||||
* Gets custom message annotations that don't match any standard MessageAnnotationType
|
||||
* @param annotations - Array of message annotations to filter
|
||||
@@ -159,16 +157,13 @@ export function getSourceAnnotationData(
|
||||
|
||||
function preprocessSourceNodes(nodes: SourceNode[]): SourceNode[] {
|
||||
// Filter source nodes has lower score
|
||||
const processedNodes = nodes
|
||||
.filter(node => (node.score ?? 1) > NODE_SCORE_THRESHOLD)
|
||||
.sort((a, b) => (b.score ?? 1) - (a.score ?? 1))
|
||||
.map(node => {
|
||||
// remove trailing slash for node url if exists
|
||||
if (node.url) {
|
||||
node.url = node.url.replace(/\/$/, '')
|
||||
}
|
||||
return node
|
||||
})
|
||||
const processedNodes = nodes.map(node => {
|
||||
// remove trailing slash for node url if exists
|
||||
if (node.url) {
|
||||
node.url = node.url.replace(/\/$/, '')
|
||||
}
|
||||
return node
|
||||
})
|
||||
return processedNodes
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Bot, Check, Copy, RefreshCw } from 'lucide-react'
|
||||
import { ComponentType, memo } from 'react'
|
||||
import { ComponentType, memo, useMemo } from 'react'
|
||||
import { useCopyToClipboard } from '../hook/use-copy-to-clipboard'
|
||||
import { cn } from '../lib/utils'
|
||||
import { Button } from '../ui/button'
|
||||
@@ -135,12 +135,15 @@ function ChatMarkdown(props: ChatMarkdownProps) {
|
||||
const { message } = useChatMessage()
|
||||
const annotations = message.annotations as MessageAnnotation[] | undefined
|
||||
|
||||
const allNodes = useMemo(() => {
|
||||
const sourceData = getSourceAnnotationData(annotations ?? [])
|
||||
return sourceData.flatMap(item => item.nodes)
|
||||
}, [annotations])
|
||||
|
||||
return (
|
||||
<Markdown
|
||||
content={message.content}
|
||||
sources={
|
||||
annotations ? getSourceAnnotationData(annotations)[0] : undefined
|
||||
}
|
||||
sources={{ nodes: allNodes }}
|
||||
citationComponent={props.citationComponent}
|
||||
className={cn(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user