open-webui/src/lib/components/chat/Messages/CitationsModal.svelte

93 lines
2.4 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { getContext, onMount, tick } from 'svelte';
import Modal from '$lib/components/common/Modal.svelte';
const i18n = getContext('i18n');
export let show = false;
2024-05-06 22:59:38 +00:00
export let citation;
let mergedDocuments = [];
2024-05-06 22:59:38 +00:00
$: if (citation) {
mergedDocuments = citation.document?.map((c, i) => {
return {
2024-05-06 22:49:00 +00:00
source: citation.source,
document: c,
metadata: citation.metadata?.[i]
};
});
2024-05-06 22:59:38 +00:00
}
</script>
<Modal size="lg" bind:show>
<div>
2024-05-06 22:14:33 +00:00
<div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
<div class=" text-lg font-medium self-center capitalize">
{$i18n.t('Citation')}
</div>
<button
class="self-center"
on:click={() => {
show = false;
}}
>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-5 h-5"
>
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
/>
</svg>
</button>
</div>
2024-05-06 22:14:33 +00:00
2024-05-06 23:19:48 +00:00
<div class="flex flex-col md:flex-row w-full px-6 pb-5 md:space-x-4">
<div
2024-05-15 06:16:22 +00:00
class="flex flex-col w-full dark:text-gray-200 overflow-y-scroll max-h-[22rem] scrollbar-hidden"
2024-05-06 23:19:48 +00:00
>
2024-05-06 22:14:33 +00:00
{#each mergedDocuments as document, documentIdx}
<div class="flex flex-col w-full">
<div class="text-sm font-medium dark:text-gray-300">
{$i18n.t('Source')}
</div>
2024-07-15 09:54:56 +00:00
{#if document.source?.name}
<div class="text-sm dark:text-gray-400">
<a
2024-07-15 11:05:38 +00:00
href={document?.metadata?.file_id
? `/api/v1/files/${document?.metadata?.file_id}/content`
2024-07-15 12:16:28 +00:00
: document.source.name.includes('http')
? document.source.name
: `#`}
2024-07-15 09:54:56 +00:00
target="_blank"
>
2024-07-15 11:05:38 +00:00
{document?.metadata?.name ?? document.source.name}
2024-07-15 09:54:56 +00:00
</a>
</div>
{:else}
<div class="text-sm dark:text-gray-400">
{$i18n.t('No source available')}
</div>
{/if}
</div>
2024-05-06 22:14:33 +00:00
<div class="flex flex-col w-full">
<div class=" text-sm font-medium dark:text-gray-300">
{$i18n.t('Content')}
</div>
<pre class="text-sm dark:text-gray-400 whitespace-pre-line">
{document.document}
</pre>
</div>
2024-05-06 22:04:37 +00:00
2024-05-06 22:14:33 +00:00
{#if documentIdx !== mergedDocuments.length - 1}
<hr class=" dark:border-gray-850 my-3" />
{/if}
{/each}
</div>
</div>
</div>
</Modal>