FileItemModal.svelte 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script lang="ts">
  2. import { getContext, onMount } from 'svelte';
  3. import { formatFileSize, getLineCount } from '$lib/utils';
  4. import { WEBUI_API_BASE_URL } from '$lib/constants';
  5. const i18n = getContext('i18n');
  6. import Modal from './Modal.svelte';
  7. import XMark from '../icons/XMark.svelte';
  8. import Info from '../icons/Info.svelte';
  9. import Switch from './Switch.svelte';
  10. import Tooltip from './Tooltip.svelte';
  11. export let item;
  12. export let show = false;
  13. export let edit = false;
  14. let enableFullContent = false;
  15. $: isPDF =
  16. item?.meta?.content_type === 'application/pdf' ||
  17. (item?.name && item?.name.toLowerCase().endsWith('.pdf'));
  18. onMount(() => {
  19. console.log(item);
  20. if (item?.context === 'full') {
  21. enableFullContent = true;
  22. }
  23. });
  24. </script>
  25. <Modal bind:show size="lg">
  26. <div class="font-primary px-6 py-5 w-full flex flex-col justify-center dark:text-gray-400">
  27. <div class=" pb-2">
  28. <div class="flex items-start justify-between">
  29. <div>
  30. <div class=" font-medium text-lg dark:text-gray-100">
  31. <a
  32. href="#"
  33. class="hover:underline line-clamp-1"
  34. on:click|preventDefault={() => {
  35. if (!isPDF && item.url) {
  36. window.open(
  37. item.type === 'file' ? `${item.url}/content` : `${item.url}`,
  38. '_blank'
  39. );
  40. }
  41. }}
  42. >
  43. {item?.name ?? 'File'}
  44. </a>
  45. </div>
  46. </div>
  47. <div>
  48. <button
  49. on:click={() => {
  50. show = false;
  51. }}
  52. >
  53. <XMark />
  54. </button>
  55. </div>
  56. </div>
  57. <div>
  58. <div class="flex flex-col items-center md:flex-row gap-1 justify-between w-full">
  59. <div class=" flex flex-wrap text-sm gap-1 text-gray-500">
  60. {#if item.size}
  61. <div class="capitalize shrink-0">{formatFileSize(item.size)}</div>
  62. {/if}
  63. {#if item?.file?.data?.content}
  64. <div class="capitalize shrink-0">
  65. {getLineCount(item?.file?.data?.content ?? '')} extracted lines
  66. </div>
  67. <div class="flex items-center gap-1 shrink-0">
  68. <Info />
  69. Formatting may be inconsistent from source.
  70. </div>
  71. {/if}
  72. </div>
  73. {#if edit}
  74. <div>
  75. <Tooltip
  76. content={enableFullContent
  77. ? 'Inject the entire document as context for comprehensive processing, this is recommended for complex queries.'
  78. : 'Default to segmented retrieval for focused and relevant content extraction, this is recommended for most cases.'}
  79. >
  80. <div class="flex items-center gap-1.5 text-xs">
  81. {#if enableFullContent}
  82. Using Entire Document
  83. {:else}
  84. Using Focused Retrieval
  85. {/if}
  86. <Switch
  87. bind:state={enableFullContent}
  88. on:change={(e) => {
  89. item.context = e.detail ? 'full' : undefined;
  90. }}
  91. />
  92. </div>
  93. </Tooltip>
  94. </div>
  95. {/if}
  96. </div>
  97. </div>
  98. </div>
  99. <div class="max-h-[75vh] overflow-auto">
  100. {#if isPDF}
  101. <iframe
  102. title={item?.name}
  103. src={`${WEBUI_API_BASE_URL}/files/${item.id}/content`}
  104. class="w-full h-[70vh] border-0 rounded-lg mt-4"
  105. />
  106. {:else}
  107. <div class="max-h-96 overflow-scroll scrollbar-hidden text-xs whitespace-pre-wrap">
  108. {item?.file?.data?.content ?? 'No content'}
  109. </div>
  110. {/if}
  111. </div>
  112. </div>
  113. </Modal>