FileItemModal.svelte 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. ? $i18n.t(
  78. 'Inject the entire content as context for comprehensive processing, this is recommended for complex queries.'
  79. )
  80. : $i18n.t(
  81. 'Default to segmented retrieval for focused and relevant content extraction, this is recommended for most cases.'
  82. )}
  83. >
  84. <div class="flex items-center gap-1.5 text-xs">
  85. {#if enableFullContent}
  86. Using Entire Document
  87. {:else}
  88. Using Focused Retrieval
  89. {/if}
  90. <Switch
  91. bind:state={enableFullContent}
  92. on:change={(e) => {
  93. item.context = e.detail ? 'full' : undefined;
  94. }}
  95. />
  96. </div>
  97. </Tooltip>
  98. </div>
  99. {/if}
  100. </div>
  101. </div>
  102. </div>
  103. <div class="max-h-[75vh] overflow-auto">
  104. {#if isPDF}
  105. <iframe
  106. title={item?.name}
  107. src={`${WEBUI_API_BASE_URL}/files/${item.id}/content`}
  108. class="w-full h-[70vh] border-0 rounded-lg mt-4"
  109. />
  110. {:else}
  111. <div class="max-h-96 overflow-scroll scrollbar-hidden text-xs whitespace-pre-wrap">
  112. {item?.file?.data?.content ?? 'No content'}
  113. </div>
  114. {/if}
  115. </div>
  116. </div>
  117. </Modal>