This commit is contained in:
Timothy Jaeryang Baek 2025-09-09 18:01:59 +04:00
parent d0f338bb99
commit 77779b30d4

View file

@ -61,8 +61,34 @@
<Modal size="lg" bind:show> <Modal size="lg" bind:show>
<div> <div>
<div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2"> <div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-2">
<div class=" text-lg font-medium self-center capitalize"> <div class=" text-lg font-medium self-center">
{$i18n.t('Citation')} {#if citation?.source?.name}
{@const document = mergedDocuments?.[0]}
{#if document?.metadata?.file_id || document.source?.url?.includes('http')}
<Tooltip
className="w-fit"
content={$i18n.t('Open file')}
placement="top-start"
tippyOptions={{ duration: [500, 0] }}
>
<a
class="hover:text-gray-500 dark:hover:text-gray-100 underline grow"
href={document?.metadata?.file_id
? `${WEBUI_API_BASE_URL}/files/${document?.metadata?.file_id}/content${document?.metadata?.page !== undefined ? `#page=${document.metadata.page + 1}` : ''}`
: document.source?.url?.includes('http')
? document.source.url
: `#`}
target="_blank"
>
{decodeString(citation?.source?.name)}
</a>
</Tooltip>
{:else}
{decodeString(citation?.source?.name)}
{/if}
{:else}
{$i18n.t('Citation')}
{/if}
</div> </div>
<button <button
class="self-center" class="self-center"
@ -76,57 +102,31 @@
<div class="flex flex-col md:flex-row w-full px-6 pb-5 md:space-x-4"> <div class="flex flex-col md:flex-row w-full px-6 pb-5 md:space-x-4">
<div <div
class="flex flex-col w-full dark:text-gray-200 overflow-y-scroll max-h-[22rem] scrollbar-hidden" class="flex flex-col w-full dark:text-gray-200 overflow-y-scroll max-h-[22rem] scrollbar-hidden gap-1"
> >
{#each mergedDocuments as document, documentIdx} {#each mergedDocuments as document, documentIdx}
<div class="flex flex-col w-full"> <div class="flex flex-col w-full gap-2">
<div class="text-sm font-medium dark:text-gray-300"> {#if document.metadata?.parameters}
{$i18n.t('Source')} <div>
</div> <div class="text-sm font-medium dark:text-gray-300 mb-1">
{#if document.source?.name}
<Tooltip
className="w-fit"
content={$i18n.t('Open file')}
placement="top-start"
tippyOptions={{ duration: [500, 0] }}
>
<div class="text-sm dark:text-gray-400 flex items-center gap-2 w-fit">
<a
class="hover:text-gray-500 dark:hover:text-gray-100 underline grow"
href={document?.metadata?.file_id
? `${WEBUI_API_BASE_URL}/files/${document?.metadata?.file_id}/content${document?.metadata?.page !== undefined ? `#page=${document.metadata.page + 1}` : ''}`
: document.source?.url?.includes('http')
? document.source.url
: `#`}
target="_blank"
>
{decodeString(document?.metadata?.name ?? document.source.name)}
</a>
{#if Number.isInteger(document?.metadata?.page)}
<span class="text-xs text-gray-500 dark:text-gray-400">
({$i18n.t('page')}
{document.metadata.page + 1})
</span>
{/if}
</div>
</Tooltip>
{#if document.metadata?.parameters}
<div class="text-sm font-medium dark:text-gray-300 mt-2 mb-0.5">
{$i18n.t('Parameters')} {$i18n.t('Parameters')}
</div> </div>
<Textarea readonly value={JSON.stringify(document.metadata.parameters, null, 2)} <Textarea readonly value={JSON.stringify(document.metadata.parameters, null, 2)}
></Textarea> ></Textarea>
{/if} </div>
{#if showRelevance} {/if}
<div class="text-sm font-medium dark:text-gray-300 mt-2">
{$i18n.t('Relevance')} <div>
</div> <div
{#if document.distance !== undefined} class=" text-sm font-medium dark:text-gray-300 flex items-center gap-2 w-fit mb-1"
>
{$i18n.t('Content')}
{#if showRelevance && document.distance !== undefined}
<Tooltip <Tooltip
className="w-fit" className="w-fit"
content={$i18n.t('Semantic distance to query')} content={$i18n.t('Relevance')}
placement="top-start" placement="top-start"
tippyOptions={{ duration: [500, 0] }} tippyOptions={{ duration: [500, 0] }}
> >
@ -141,12 +141,6 @@
{percentage.toFixed(2)}% {percentage.toFixed(2)}%
</span> </span>
{/if} {/if}
{#if typeof document?.distance === 'number'}
<span class="text-gray-500 dark:text-gray-500">
({(document?.distance ?? 0).toFixed(4)})
</span>
{/if}
{:else if typeof document?.distance === 'number'} {:else if typeof document?.distance === 'number'}
<span class="text-gray-500 dark:text-gray-500"> <span class="text-gray-500 dark:text-gray-500">
({(document?.distance ?? 0).toFixed(4)}) ({(document?.distance ?? 0).toFixed(4)})
@ -154,39 +148,30 @@
{/if} {/if}
</div> </div>
</Tooltip> </Tooltip>
{:else}
<div class="text-sm dark:text-gray-400">
{$i18n.t('No distance available')}
</div>
{/if} {/if}
{/if}
{:else} {#if Number.isInteger(document?.metadata?.page)}
<div class="text-sm dark:text-gray-400"> <span class="text-sm text-gray-500 dark:text-gray-400">
{$i18n.t('No source available')} ({$i18n.t('page')}
{document.metadata.page + 1})
</span>
{/if}
</div> </div>
{/if}
</div> {#if document.metadata?.html}
<div class="flex flex-col w-full"> <iframe
<div class=" text-sm font-medium dark:text-gray-300 mt-2"> class="w-full border-0 h-auto rounded-none"
{$i18n.t('Content')} sandbox="allow-scripts allow-forms allow-same-origin"
</div> srcdoc={document.document}
{#if document.metadata?.html} title={$i18n.t('Content')}
<iframe ></iframe>
class="w-full border-0 h-auto rounded-none" {:else}
sandbox="allow-scripts allow-forms allow-same-origin" <pre class="text-sm dark:text-gray-400 whitespace-pre-line">
srcdoc={document.document}
title={$i18n.t('Content')}
></iframe>
{:else}
<pre class="text-sm dark:text-gray-400 whitespace-pre-line">
{document.document} {document.document}
</pre> </pre>
{/if} {/if}
</div>
</div> </div>
{#if documentIdx !== mergedDocuments.length - 1}
<hr class="border-gray-100 dark:border-gray-850 my-3" />
{/if}
{/each} {/each}
</div> </div>
</div> </div>