diff --git a/src/lib/components/chat/Messages/CitationsModal.svelte b/src/lib/components/chat/Messages/CitationsModal.svelte index 6ed4125ca..79a9a9720 100644 --- a/src/lib/components/chat/Messages/CitationsModal.svelte +++ b/src/lib/components/chat/Messages/CitationsModal.svelte @@ -49,7 +49,6 @@
{#each mergedDocuments as document} -
{$i18n.t('Source')} @@ -58,7 +57,6 @@ {document.metadata?.source ?? $i18n.t('No source available')}
-
{$i18n.t('Content')} diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index d7da104fe..de59239e1 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -67,6 +67,8 @@ let showRateComment = false; let showCitations = {}; + // Backend returns a list of citations per collection, we flatten it to citations per source + let flattenedCitations = {}; $: tokens = marked.lexer(sanitizeResponseContent(message.content)); @@ -133,6 +135,28 @@ allowHTML: true }); } + + if (message.citations) { + for (const citation of message.citations) { + const zipped = (citation?.document ?? []).map(function (document, index) { + return [document, citation.metadata?.[index]]; + }); + for (const [document, metadata] of zipped) { + const source = metadata?.source ?? 'N/A'; + if (source in flattenedCitations) { + flattenedCitations[source].document.push(document); + flattenedCitations[source].metadata.push(metadata); + } else { + flattenedCitations[source] = { + document: [document], + metadata: [metadata] + }; + } + } + } + console.log(flattenedCitations); + console.log(Object.keys(flattenedCitations)); + } }; const renderLatex = () => { @@ -363,16 +387,19 @@ {/each}
{/if} - {#if message.citations} + {#if flattenedCitations}
- {#each message.citations as citation} + {#each [...Object.keys(flattenedCitations)] as source}
- +