From 7538dc051e47db058dc013b6b2dd31663a7c4455 Mon Sep 17 00:00:00 2001 From: Jun Siang Cheah Date: Sat, 11 May 2024 23:48:30 +0800 Subject: [PATCH] feat: use url as source name for citations --- src/lib/components/chat/Messages/ResponseMessage.svelte | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 5b228a9ff..2b8ef4077 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -453,6 +453,11 @@ citation.document.forEach((document, index) => { const metadata = citation.metadata?.[index]; const id = metadata?.source ?? 'N/A'; + let source = citation?.source; + // Check if ID looks like a URL + if (id.startsWith('http://') || id.startsWith('https://')) { + source = { name: id }; + } const existingSource = acc.find((item) => item.id === id); @@ -460,7 +465,7 @@ existingSource.document.push(document); existingSource.metadata.push(metadata); } else { - acc.push( { id: id, source: citation?.source, document: [document], metadata: metadata ? [metadata] : [] } ); + acc.push( { id: id, source: source, document: [document], metadata: metadata ? [metadata] : [] } ); } }); return acc;