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

109 lines
2.7 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';
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;
2024-09-28 08:53:25 +00:00
onMount(() => {
2024-10-04 05:22:22 +00:00
console.log(item);
2024-09-29 20:52:27 +00:00
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>
<Modal bind:show size="md">
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
2024-10-04 05:22:22 +00:00
href={item.url ? (item.type === 'file' ? `${item.url}/content` : `${item.url}`) : '#'}
2024-09-29 20:52:27 +00:00
target="_blank"
class="hover:underline line-clamp-1"
>
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>
<div class="max-h-96 overflow-scroll scrollbar-hidden text-xs whitespace-pre-wrap">
2024-10-04 05:22:22 +00:00
{item?.file?.data?.content ?? 'No content'}
2024-09-28 08:53:25 +00:00
</div>
</div>
</Modal>