From eed2d735a1caaae59ff6e94dc82cc03ab9dcb155 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 12 Sep 2024 02:06:02 -0400 Subject: [PATCH] refac --- .../components/chat/Messages/Citations.svelte | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/src/lib/components/chat/Messages/Citations.svelte b/src/lib/components/chat/Messages/Citations.svelte index 8112d37f4..1f7c69425 100644 --- a/src/lib/components/chat/Messages/Citations.svelte +++ b/src/lib/components/chat/Messages/Citations.svelte @@ -3,14 +3,9 @@ export let citations = []; - let showCitationModal = false; - let selectedCitation = null; - + let _citations = []; - - -
- {#each citations.reduce((acc, citation) => { + $: _citations = citations.reduce((acc, citation) => { citation.document.forEach((document, index) => { const metadata = citation.metadata?.[index]; const id = metadata?.source ?? 'N/A'; @@ -31,26 +26,42 @@ existingSource.document.push(document); existingSource.metadata.push(metadata); } else { - acc.push( { id: id, source: source, document: [document], metadata: metadata ? [metadata] : [] } ); + acc.push({ + id: id, + source: source, + document: [document], + metadata: metadata ? [metadata] : [] + }); } }); return acc; - }, []) as citation, idx} -
- -
- {/each} -
+ }, []); + + let showCitationModal = false; + let selectedCitation = null; + + + + +{#if _citations.length > 0} +
+ {#each _citations as citation, idx} +
+ +
+ {/each} +
+{/if}