open-webui/src/lib/components/common/FileItemModal.svelte

123 lines
3.2 KiB
Svelte
Raw Normal View History

2024-09-28 08:53:25 +00:00
<script lang="ts">
import { getContext, onMount } from 'svelte';
import { formatFileSize, getLineCount } from '$lib/utils';
2025-02-20 07:44:11 +00:00
import { WEBUI_API_BASE_URL } from '$lib/constants';
2024-09-28 08:53:25 +00:00
const i18n = getContext('i18n');
import Modal from './Modal.svelte';
import XMark from '../icons/XMark.svelte';
import Info from '../icons/Info.svelte';
2024-09-29 20:52:27 +00:00
import Switch from './Switch.svelte';
import Tooltip from './Tooltip.svelte';
2024-09-28 08:53:25 +00:00
2024-10-04 05:22:22 +00:00
export let item;
2024-09-28 08:53:25 +00:00
export let show = false;
2024-09-29 20:52:27 +00:00
export let edit = false;
let enableFullContent = false;
2025-02-20 07:44:11 +00:00
$: isPDF = item?.meta?.content_type === 'application/pdf' ||
(item?.name && item?.name.toLowerCase().endsWith('.pdf'));
2024-09-29 20:52:27 +00:00
2024-09-28 08:53:25 +00:00
onMount(() => {
2024-10-04 05:22:22 +00:00
if (item?.context === 'full') {
2024-09-29 20:52:27 +00:00
enableFullContent = true;
}
2024-09-28 08:53:25 +00:00
});
</script>
2024-11-18 22:25:24 +00:00
<Modal bind:show size="lg">
2024-09-29 16:41:27 +00:00
<div class="font-primary px-6 py-5 w-full flex flex-col justify-center dark:text-gray-400">
2024-09-29 20:52:27 +00:00
<div class=" pb-2">
<div class="flex items-start justify-between">
<div>
<div class=" font-medium text-lg dark:text-gray-100">
<a
2025-02-20 07:44:11 +00:00
href="#"
2024-09-29 20:52:27 +00:00
class="hover:underline line-clamp-1"
2025-02-20 07:44:11 +00:00
on:click|preventDefault={() => {
if (!isPDF && item.url) {
window.open(item.type === 'file' ? `${item.url}/content` : `${item.url}`, '_blank');
}
}}
2024-09-29 20:52:27 +00:00
>
2024-10-04 05:22:22 +00:00
{item?.name ?? 'File'}
2024-09-29 20:52:27 +00:00
</a>
</div>
2024-09-28 08:53:25 +00:00
</div>
<div>
2024-09-29 20:52:27 +00:00
<button
on:click={() => {
show = false;
}}
>
<XMark />
</button>
</div>
</div>
<div>
<div class="flex flex-col items-center md:flex-row gap-1 justify-between w-full">
2024-09-29 20:52:27 +00:00
<div class=" flex flex-wrap text-sm gap-1 text-gray-500">
2024-10-04 05:22:22 +00:00
{#if item.size}
<div class="capitalize shrink-0">{formatFileSize(item.size)}</div>
2024-09-28 08:53:25 +00:00
{/if}
2024-10-04 05:22:22 +00:00
{#if item?.file?.data?.content}
2024-09-29 21:08:55 +00:00
<div class="capitalize shrink-0">
2024-10-04 05:22:22 +00:00
{getLineCount(item?.file?.data?.content ?? '')} extracted lines
2024-09-29 21:08:55 +00:00
</div>
2024-09-28 08:53:25 +00:00
2024-09-29 20:52:27 +00:00
<div class="flex items-center gap-1 shrink-0">
2024-09-28 08:53:25 +00:00
<Info />
Formatting may be inconsistent from source.
</div>
{/if}
</div>
2024-09-29 20:52:27 +00:00
{#if edit}
<div>
<Tooltip
content={enableFullContent
2024-09-29 21:11:22 +00:00
? 'Inject the entire document as context for comprehensive processing, this is recommended for complex queries.'
: 'Default to segmented retrieval for focused and relevant content extraction, this is recommended for most cases.'}
2024-09-29 20:52:27 +00:00
>
<div class="flex items-center gap-1.5 text-xs">
{#if enableFullContent}
2024-09-29 21:11:22 +00:00
Using Entire Document
2024-09-29 20:52:27 +00:00
{:else}
2024-09-29 21:11:22 +00:00
Using Focused Retrieval
2024-09-29 20:52:27 +00:00
{/if}
<Switch
bind:state={enableFullContent}
on:change={(e) => {
2024-10-04 05:22:22 +00:00
item.context = e.detail ? 'full' : undefined;
2024-09-29 20:52:27 +00:00
}}
/>
</div>
</Tooltip>
</div>
{/if}
</div>
2024-09-28 08:53:25 +00:00
</div>
</div>
2025-02-20 07:44:11 +00:00
<div class="max-h-[75vh] overflow-auto">
{#if isPDF}
<iframe
title={item?.name}
src={`${WEBUI_API_BASE_URL}/files/${item.id}/content`}
class="w-full h-[70vh] border-0 rounded-lg mt-4"
/>
{:else}
<div class="max-h-96 overflow-scroll scrollbar-hidden text-xs whitespace-pre-wrap">
{item?.file?.data?.content ?? 'No content'}
</div>
{/if}
2024-09-28 08:53:25 +00:00
</div>
</div>
</Modal>