General.svelte 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <script lang="ts">
  2. import { getDocs } from '$lib/apis/documents';
  3. import { getChunkParams, scanDocs, updateChunkParams } from '$lib/apis/rag';
  4. import { documents } from '$lib/stores';
  5. import { onMount } from 'svelte';
  6. import toast from 'svelte-french-toast';
  7. export let saveHandler: Function;
  8. let loading = false;
  9. let chunkSize = 0;
  10. let chunkOverlap = 0;
  11. const scanHandler = async () => {
  12. loading = true;
  13. const res = await scanDocs(localStorage.token);
  14. loading = false;
  15. if (res) {
  16. await documents.set(await getDocs(localStorage.token));
  17. toast.success('Scan complete!');
  18. }
  19. };
  20. const submitHandler = async () => {
  21. const res = await updateChunkParams(localStorage.token, chunkSize, chunkOverlap);
  22. };
  23. onMount(async () => {
  24. const res = await getChunkParams(localStorage.token);
  25. if (res) {
  26. chunkSize = res.chunk_size;
  27. chunkOverlap = res.chunk_overlap;
  28. }
  29. });
  30. </script>
  31. <form
  32. class="flex flex-col h-full justify-between space-y-3 text-sm"
  33. on:submit|preventDefault={() => {
  34. submitHandler();
  35. saveHandler();
  36. }}
  37. >
  38. <div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-80">
  39. <div>
  40. <div class=" mb-2 text-sm font-medium">General Settings</div>
  41. <div class=" flex w-full justify-between">
  42. <div class=" self-center text-xs font-medium">Scan for documents from '/data/docs'</div>
  43. <button
  44. class=" self-center text-xs p-1 px-3 bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 rounded flex flex-row space-x-1 items-center {loading
  45. ? ' cursor-not-allowed'
  46. : ''}"
  47. on:click={() => {
  48. scanHandler();
  49. console.log('check');
  50. }}
  51. type="button"
  52. disabled={loading}
  53. >
  54. <div class="self-center font-medium">Scan</div>
  55. <!-- <svg
  56. xmlns="http://www.w3.org/2000/svg"
  57. viewBox="0 0 16 16"
  58. fill="currentColor"
  59. class="w-3 h-3"
  60. >
  61. <path
  62. fill-rule="evenodd"
  63. d="M13.836 2.477a.75.75 0 0 1 .75.75v3.182a.75.75 0 0 1-.75.75h-3.182a.75.75 0 0 1 0-1.5h1.37l-.84-.841a4.5 4.5 0 0 0-7.08.932.75.75 0 0 1-1.3-.75 6 6 0 0 1 9.44-1.242l.842.84V3.227a.75.75 0 0 1 .75-.75Zm-.911 7.5A.75.75 0 0 1 13.199 11a6 6 0 0 1-9.44 1.241l-.84-.84v1.371a.75.75 0 0 1-1.5 0V9.591a.75.75 0 0 1 .75-.75H5.35a.75.75 0 0 1 0 1.5H3.98l.841.841a4.5 4.5 0 0 0 7.08-.932.75.75 0 0 1 1.025-.273Z"
  64. clip-rule="evenodd"
  65. />
  66. </svg> -->
  67. {#if loading}
  68. <div class="ml-3 self-center">
  69. <svg
  70. class=" w-3 h-3"
  71. viewBox="0 0 24 24"
  72. fill="currentColor"
  73. xmlns="http://www.w3.org/2000/svg"
  74. ><style>
  75. .spinner_ajPY {
  76. transform-origin: center;
  77. animation: spinner_AtaB 0.75s infinite linear;
  78. }
  79. @keyframes spinner_AtaB {
  80. 100% {
  81. transform: rotate(360deg);
  82. }
  83. }
  84. </style><path
  85. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  86. opacity=".25"
  87. /><path
  88. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  89. class="spinner_ajPY"
  90. /></svg
  91. >
  92. </div>
  93. {/if}
  94. </button>
  95. </div>
  96. </div>
  97. <hr class=" dark:border-gray-700" />
  98. <div class=" ">
  99. <div class=" text-sm font-medium">Chunk Params</div>
  100. <div class=" flex">
  101. <div class=" flex w-full justify-between">
  102. <div class="self-center text-xs font-medium min-w-fit">Chunk Size</div>
  103. <div class="self-center p-3">
  104. <input
  105. class=" w-full rounded py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none border border-gray-100 dark:border-gray-600"
  106. type="number"
  107. placeholder="Enter Chunk Size"
  108. bind:value={chunkSize}
  109. autocomplete="off"
  110. min="0"
  111. />
  112. </div>
  113. </div>
  114. <div class="flex w-full">
  115. <div class=" self-center text-xs font-medium min-w-fit">Chunk Overlap</div>
  116. <div class="self-center p-3">
  117. <input
  118. class="w-full rounded py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none border border-gray-100 dark:border-gray-600"
  119. type="number"
  120. placeholder="Enter Chunk Overlap"
  121. bind:value={chunkOverlap}
  122. autocomplete="off"
  123. min="0"
  124. />
  125. </div>
  126. </div>
  127. </div>
  128. </div>
  129. </div>
  130. <div class="flex justify-end pt-3 text-sm font-medium">
  131. <button
  132. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  133. type="submit"
  134. >
  135. Save
  136. </button>
  137. </div>
  138. </form>