Documents.svelte 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. <script lang="ts">
  2. import { getDocs } from '$lib/apis/documents';
  3. import {
  4. getQuerySettings,
  5. scanDocs,
  6. updateQuerySettings,
  7. resetVectorDB,
  8. getEmbeddingConfig,
  9. updateEmbeddingConfig,
  10. getRerankingConfig,
  11. updateRerankingConfig,
  12. resetUploadDir,
  13. getRAGConfig,
  14. updateRAGConfig
  15. } from '$lib/apis/rag';
  16. import { documents, models } from '$lib/stores';
  17. import { onMount, getContext } from 'svelte';
  18. import { toast } from 'svelte-sonner';
  19. const i18n = getContext('i18n');
  20. export let saveHandler: Function;
  21. let scanDirLoading = false;
  22. let updateEmbeddingModelLoading = false;
  23. let updateRerankingModelLoading = false;
  24. let showResetConfirm = false;
  25. let showResetUploadDirConfirm = false;
  26. let embeddingEngine = '';
  27. let embeddingModel = '';
  28. let rerankingModel = '';
  29. let chunkSize = 0;
  30. let chunkOverlap = 0;
  31. let pdfExtractImages = true;
  32. let OpenAIKey = '';
  33. let OpenAIUrl = '';
  34. let OpenAIBatchSize = 1;
  35. let querySettings = {
  36. template: '',
  37. r: 0.0,
  38. k: 4,
  39. hybrid: false
  40. };
  41. const scanHandler = async () => {
  42. scanDirLoading = true;
  43. const res = await scanDocs(localStorage.token);
  44. scanDirLoading = false;
  45. if (res) {
  46. await documents.set(await getDocs(localStorage.token));
  47. toast.success($i18n.t('Scan complete!'));
  48. }
  49. };
  50. const embeddingModelUpdateHandler = async () => {
  51. if (embeddingEngine === '' && embeddingModel.split('/').length - 1 > 1) {
  52. toast.error(
  53. $i18n.t(
  54. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  55. )
  56. );
  57. return;
  58. }
  59. if (embeddingEngine === 'ollama' && embeddingModel === '') {
  60. toast.error(
  61. $i18n.t(
  62. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  63. )
  64. );
  65. return;
  66. }
  67. if (embeddingEngine === 'openai' && embeddingModel === '') {
  68. toast.error(
  69. $i18n.t(
  70. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  71. )
  72. );
  73. return;
  74. }
  75. if ((embeddingEngine === 'openai' && OpenAIKey === '') || OpenAIUrl === '') {
  76. toast.error($i18n.t('OpenAI URL/Key required.'));
  77. return;
  78. }
  79. console.log('Update embedding model attempt:', embeddingModel);
  80. updateEmbeddingModelLoading = true;
  81. const res = await updateEmbeddingConfig(localStorage.token, {
  82. embedding_engine: embeddingEngine,
  83. embedding_model: embeddingModel,
  84. ...(embeddingEngine === 'openai'
  85. ? {
  86. openai_config: {
  87. key: OpenAIKey,
  88. url: OpenAIUrl,
  89. batch_size: OpenAIBatchSize
  90. }
  91. }
  92. : {})
  93. }).catch(async (error) => {
  94. toast.error(error);
  95. await setEmbeddingConfig();
  96. return null;
  97. });
  98. updateEmbeddingModelLoading = false;
  99. if (res) {
  100. console.log('embeddingModelUpdateHandler:', res);
  101. if (res.status === true) {
  102. toast.success($i18n.t('Embedding model set to "{{embedding_model}}"', res), {
  103. duration: 1000 * 10
  104. });
  105. }
  106. }
  107. };
  108. const rerankingModelUpdateHandler = async () => {
  109. console.log('Update reranking model attempt:', rerankingModel);
  110. updateRerankingModelLoading = true;
  111. const res = await updateRerankingConfig(localStorage.token, {
  112. reranking_model: rerankingModel
  113. }).catch(async (error) => {
  114. toast.error(error);
  115. await setRerankingConfig();
  116. return null;
  117. });
  118. updateRerankingModelLoading = false;
  119. if (res) {
  120. console.log('rerankingModelUpdateHandler:', res);
  121. if (res.status === true) {
  122. if (rerankingModel === '') {
  123. toast.success($i18n.t('Reranking model disabled', res), {
  124. duration: 1000 * 10
  125. });
  126. } else {
  127. toast.success($i18n.t('Reranking model set to "{{reranking_model}}"', res), {
  128. duration: 1000 * 10
  129. });
  130. }
  131. }
  132. }
  133. };
  134. const submitHandler = async () => {
  135. embeddingModelUpdateHandler();
  136. if (querySettings.hybrid) {
  137. rerankingModelUpdateHandler();
  138. }
  139. const res = await updateRAGConfig(localStorage.token, {
  140. pdf_extract_images: pdfExtractImages,
  141. chunk: {
  142. chunk_overlap: chunkOverlap,
  143. chunk_size: chunkSize
  144. }
  145. });
  146. };
  147. const setEmbeddingConfig = async () => {
  148. const embeddingConfig = await getEmbeddingConfig(localStorage.token);
  149. if (embeddingConfig) {
  150. embeddingEngine = embeddingConfig.embedding_engine;
  151. embeddingModel = embeddingConfig.embedding_model;
  152. OpenAIKey = embeddingConfig.openai_config.key;
  153. OpenAIUrl = embeddingConfig.openai_config.url;
  154. OpenAIBatchSize = embeddingConfig.openai_config.batch_size ?? 1;
  155. }
  156. };
  157. const setRerankingConfig = async () => {
  158. const rerankingConfig = await getRerankingConfig(localStorage.token);
  159. if (rerankingConfig) {
  160. rerankingModel = rerankingConfig.reranking_model;
  161. }
  162. };
  163. const toggleHybridSearch = async () => {
  164. querySettings.hybrid = !querySettings.hybrid;
  165. querySettings = await updateQuerySettings(localStorage.token, querySettings);
  166. };
  167. onMount(async () => {
  168. await setEmbeddingConfig();
  169. await setRerankingConfig();
  170. querySettings = await getQuerySettings(localStorage.token);
  171. const res = await getRAGConfig(localStorage.token);
  172. if (res) {
  173. pdfExtractImages = res.pdf_extract_images;
  174. chunkSize = res.chunk.chunk_size;
  175. chunkOverlap = res.chunk.chunk_overlap;
  176. }
  177. });
  178. </script>
  179. <form
  180. class="flex flex-col h-full justify-between space-y-3 text-sm"
  181. on:submit|preventDefault={() => {
  182. submitHandler();
  183. saveHandler();
  184. }}
  185. >
  186. <div class=" space-y-2.5 pr-1.5 overflow-y-scroll h-full">
  187. <div class="flex flex-col gap-0.5">
  188. <div class=" mb-0.5 text-sm font-medium">{$i18n.t('General Settings')}</div>
  189. <div class=" flex w-full justify-between">
  190. <div class=" self-center text-xs font-medium">
  191. {$i18n.t('Scan for documents from {{path}}', { path: 'DOCS_DIR (/data/docs)' })}
  192. </div>
  193. <button
  194. class=" self-center text-xs p-1 px-3 bg-gray-100 dark:bg-gray-800 dark:hover:bg-gray-700 rounded-lg flex flex-row space-x-1 items-center {scanDirLoading
  195. ? ' cursor-not-allowed'
  196. : ''}"
  197. on:click={() => {
  198. scanHandler();
  199. console.log('check');
  200. }}
  201. type="button"
  202. disabled={scanDirLoading}
  203. >
  204. <div class="self-center font-medium">{$i18n.t('Scan')}</div>
  205. {#if scanDirLoading}
  206. <div class="ml-3 self-center">
  207. <svg
  208. class=" w-3 h-3"
  209. viewBox="0 0 24 24"
  210. fill="currentColor"
  211. xmlns="http://www.w3.org/2000/svg"
  212. ><style>
  213. .spinner_ajPY {
  214. transform-origin: center;
  215. animation: spinner_AtaB 0.75s infinite linear;
  216. }
  217. @keyframes spinner_AtaB {
  218. 100% {
  219. transform: rotate(360deg);
  220. }
  221. }
  222. </style><path
  223. 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"
  224. opacity=".25"
  225. /><path
  226. 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"
  227. class="spinner_ajPY"
  228. /></svg
  229. >
  230. </div>
  231. {/if}
  232. </button>
  233. </div>
  234. <div class=" flex w-full justify-between">
  235. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Model Engine')}</div>
  236. <div class="flex items-center relative">
  237. <select
  238. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
  239. bind:value={embeddingEngine}
  240. placeholder="Select an embedding model engine"
  241. on:change={(e) => {
  242. if (e.target.value === 'ollama') {
  243. embeddingModel = '';
  244. } else if (e.target.value === 'openai') {
  245. embeddingModel = 'text-embedding-3-small';
  246. } else if (e.target.value === '') {
  247. embeddingModel = 'sentence-transformers/all-MiniLM-L6-v2';
  248. }
  249. }}
  250. >
  251. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  252. <option value="ollama">{$i18n.t('Ollama')}</option>
  253. <option value="openai">{$i18n.t('OpenAI')}</option>
  254. </select>
  255. </div>
  256. </div>
  257. {#if embeddingEngine === 'openai'}
  258. <div class="my-0.5 flex gap-2">
  259. <input
  260. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  261. placeholder={$i18n.t('API Base URL')}
  262. bind:value={OpenAIUrl}
  263. required
  264. />
  265. <input
  266. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  267. placeholder={$i18n.t('API Key')}
  268. bind:value={OpenAIKey}
  269. required
  270. />
  271. </div>
  272. <div class="flex mt-0.5 space-x-2">
  273. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Batch Size')}</div>
  274. <div class=" flex-1">
  275. <input
  276. id="steps-range"
  277. type="range"
  278. min="1"
  279. max="2048"
  280. step="1"
  281. bind:value={OpenAIBatchSize}
  282. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  283. />
  284. </div>
  285. <div class="">
  286. <input
  287. bind:value={OpenAIBatchSize}
  288. type="number"
  289. class=" bg-transparent text-center w-14"
  290. min="-2"
  291. max="16000"
  292. step="1"
  293. />
  294. </div>
  295. </div>
  296. {/if}
  297. <div class=" flex w-full justify-between">
  298. <div class=" self-center text-xs font-medium">{$i18n.t('Hybrid Search')}</div>
  299. <button
  300. class="p-1 px-3 text-xs flex rounded transition"
  301. on:click={() => {
  302. toggleHybridSearch();
  303. }}
  304. type="button"
  305. >
  306. {#if querySettings.hybrid === true}
  307. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  308. {:else}
  309. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  310. {/if}
  311. </button>
  312. </div>
  313. </div>
  314. <hr class=" dark:border-gray-850 my-1" />
  315. <div class="space-y-2" />
  316. <div>
  317. <div class=" mb-2 text-sm font-medium">{$i18n.t('Embedding Model')}</div>
  318. {#if embeddingEngine === 'ollama'}
  319. <div class="flex w-full">
  320. <div class="flex-1 mr-2">
  321. <select
  322. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  323. bind:value={embeddingModel}
  324. placeholder={$i18n.t('Select a model')}
  325. required
  326. >
  327. {#if !embeddingModel}
  328. <option value="" disabled selected>{$i18n.t('Select a model')}</option>
  329. {/if}
  330. {#each $models.filter((m) => m.id && m.ollama && !(m?.preset ?? false)) as model}
  331. <option value={model.id} class="bg-gray-100 dark:bg-gray-700">{model.name}</option>
  332. {/each}
  333. </select>
  334. </div>
  335. </div>
  336. {:else}
  337. <div class="flex w-full">
  338. <div class="flex-1 mr-2">
  339. <input
  340. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  341. placeholder={$i18n.t('Set embedding model (e.g. {{model}})', {
  342. model: embeddingModel.slice(-40)
  343. })}
  344. bind:value={embeddingModel}
  345. />
  346. </div>
  347. {#if embeddingEngine === ''}
  348. <button
  349. class="px-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  350. on:click={() => {
  351. embeddingModelUpdateHandler();
  352. }}
  353. disabled={updateEmbeddingModelLoading}
  354. >
  355. {#if updateEmbeddingModelLoading}
  356. <div class="self-center">
  357. <svg
  358. class=" w-4 h-4"
  359. viewBox="0 0 24 24"
  360. fill="currentColor"
  361. xmlns="http://www.w3.org/2000/svg"
  362. ><style>
  363. .spinner_ajPY {
  364. transform-origin: center;
  365. animation: spinner_AtaB 0.75s infinite linear;
  366. }
  367. @keyframes spinner_AtaB {
  368. 100% {
  369. transform: rotate(360deg);
  370. }
  371. }
  372. </style><path
  373. 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"
  374. opacity=".25"
  375. /><path
  376. 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"
  377. class="spinner_ajPY"
  378. /></svg
  379. >
  380. </div>
  381. {:else}
  382. <svg
  383. xmlns="http://www.w3.org/2000/svg"
  384. viewBox="0 0 16 16"
  385. fill="currentColor"
  386. class="w-4 h-4"
  387. >
  388. <path
  389. d="M8.75 2.75a.75.75 0 0 0-1.5 0v5.69L5.03 6.22a.75.75 0 0 0-1.06 1.06l3.5 3.5a.75.75 0 0 0 1.06 0l3.5-3.5a.75.75 0 0 0-1.06-1.06L8.75 8.44V2.75Z"
  390. />
  391. <path
  392. d="M3.5 9.75a.75.75 0 0 0-1.5 0v1.5A2.75 2.75 0 0 0 4.75 14h6.5A2.75 2.75 0 0 0 14 11.25v-1.5a.75.75 0 0 0-1.5 0v1.5c0 .69-.56 1.25-1.25 1.25h-6.5c-.69 0-1.25-.56-1.25-1.25v-1.5Z"
  393. />
  394. </svg>
  395. {/if}
  396. </button>
  397. {/if}
  398. </div>
  399. {/if}
  400. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  401. {$i18n.t(
  402. 'Warning: If you update or change your embedding model, you will need to re-import all documents.'
  403. )}
  404. </div>
  405. {#if querySettings.hybrid === true}
  406. <div class=" ">
  407. <div class=" mb-2 text-sm font-medium">{$i18n.t('Reranking Model')}</div>
  408. <div class="flex w-full">
  409. <div class="flex-1 mr-2">
  410. <input
  411. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  412. placeholder={$i18n.t('Set reranking model (e.g. {{model}})', {
  413. model: 'BAAI/bge-reranker-v2-m3'
  414. })}
  415. bind:value={rerankingModel}
  416. />
  417. </div>
  418. <button
  419. class="px-2.5 bg-gray-100 hover:bg-gray-200 text-gray-800 dark:bg-gray-850 dark:hover:bg-gray-800 dark:text-gray-100 rounded-lg transition"
  420. on:click={() => {
  421. rerankingModelUpdateHandler();
  422. }}
  423. disabled={updateRerankingModelLoading}
  424. >
  425. {#if updateRerankingModelLoading}
  426. <div class="self-center">
  427. <svg
  428. class=" w-4 h-4"
  429. viewBox="0 0 24 24"
  430. fill="currentColor"
  431. xmlns="http://www.w3.org/2000/svg"
  432. ><style>
  433. .spinner_ajPY {
  434. transform-origin: center;
  435. animation: spinner_AtaB 0.75s infinite linear;
  436. }
  437. @keyframes spinner_AtaB {
  438. 100% {
  439. transform: rotate(360deg);
  440. }
  441. }
  442. </style><path
  443. 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"
  444. opacity=".25"
  445. /><path
  446. 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"
  447. class="spinner_ajPY"
  448. /></svg
  449. >
  450. </div>
  451. {:else}
  452. <svg
  453. xmlns="http://www.w3.org/2000/svg"
  454. viewBox="0 0 16 16"
  455. fill="currentColor"
  456. class="w-4 h-4"
  457. >
  458. <path
  459. d="M8.75 2.75a.75.75 0 0 0-1.5 0v5.69L5.03 6.22a.75.75 0 0 0-1.06 1.06l3.5 3.5a.75.75 0 0 0 1.06 0l3.5-3.5a.75.75 0 0 0-1.06-1.06L8.75 8.44V2.75Z"
  460. />
  461. <path
  462. d="M3.5 9.75a.75.75 0 0 0-1.5 0v1.5A2.75 2.75 0 0 0 4.75 14h6.5A2.75 2.75 0 0 0 14 11.25v-1.5a.75.75 0 0 0-1.5 0v1.5c0 .69-.56 1.25-1.25 1.25h-6.5c-.69 0-1.25-.56-1.25-1.25v-1.5Z"
  463. />
  464. </svg>
  465. {/if}
  466. </button>
  467. </div>
  468. </div>
  469. {/if}
  470. </div>
  471. <hr class=" dark:border-gray-850" />
  472. <div class=" ">
  473. <div class=" text-sm font-medium">{$i18n.t('Query Params')}</div>
  474. <div class=" flex">
  475. <div class=" flex w-full justify-between">
  476. <div class="self-center text-xs font-medium min-w-fit">{$i18n.t('Top K')}</div>
  477. <div class="self-center p-3">
  478. <input
  479. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  480. type="number"
  481. placeholder={$i18n.t('Enter Top K')}
  482. bind:value={querySettings.k}
  483. autocomplete="off"
  484. min="0"
  485. />
  486. </div>
  487. </div>
  488. {#if querySettings.hybrid === true}
  489. <div class="flex w-full">
  490. <div class=" self-center text-xs font-medium min-w-fit">
  491. {$i18n.t('Minimum Score')}
  492. </div>
  493. <div class="self-center p-3">
  494. <input
  495. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  496. type="number"
  497. step="0.01"
  498. placeholder={$i18n.t('Enter Score')}
  499. bind:value={querySettings.r}
  500. autocomplete="off"
  501. min="0.0"
  502. title={$i18n.t('The score should be a value between 0.0 (0%) and 1.0 (100%).')}
  503. />
  504. </div>
  505. </div>
  506. {/if}
  507. </div>
  508. {#if querySettings.hybrid === true}
  509. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  510. {$i18n.t(
  511. 'Note: If you set a minimum score, the search will only return documents with a score greater than or equal to the minimum score.'
  512. )}
  513. </div>
  514. <hr class=" dark:border-gray-850 my-3" />
  515. {/if}
  516. <div>
  517. <div class=" mb-2.5 text-sm font-medium">{$i18n.t('RAG Template')}</div>
  518. <textarea
  519. bind:value={querySettings.template}
  520. class="w-full rounded-lg px-4 py-3 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none resize-none"
  521. rows="4"
  522. />
  523. </div>
  524. </div>
  525. <hr class=" dark:border-gray-850" />
  526. <div class=" ">
  527. <div class=" text-sm font-medium">{$i18n.t('Chunk Params')}</div>
  528. <div class=" flex">
  529. <div class=" flex w-full justify-between">
  530. <div class="self-center text-xs font-medium min-w-fit">{$i18n.t('Chunk Size')}</div>
  531. <div class="self-center p-3">
  532. <input
  533. class=" w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  534. type="number"
  535. placeholder={$i18n.t('Enter Chunk Size')}
  536. bind:value={chunkSize}
  537. autocomplete="off"
  538. min="0"
  539. />
  540. </div>
  541. </div>
  542. <div class="flex w-full">
  543. <div class=" self-center text-xs font-medium min-w-fit">
  544. {$i18n.t('Chunk Overlap')}
  545. </div>
  546. <div class="self-center p-3">
  547. <input
  548. class="w-full rounded-lg py-1.5 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  549. type="number"
  550. placeholder={$i18n.t('Enter Chunk Overlap')}
  551. bind:value={chunkOverlap}
  552. autocomplete="off"
  553. min="0"
  554. />
  555. </div>
  556. </div>
  557. </div>
  558. <div class="pr-2">
  559. <div class="flex justify-between items-center text-xs">
  560. <div class=" text-xs font-medium">{$i18n.t('PDF Extract Images (OCR)')}</div>
  561. <button
  562. class=" text-xs font-medium text-gray-500"
  563. type="button"
  564. on:click={() => {
  565. pdfExtractImages = !pdfExtractImages;
  566. }}>{pdfExtractImages ? $i18n.t('On') : $i18n.t('Off')}</button
  567. >
  568. </div>
  569. </div>
  570. </div>
  571. <hr class=" dark:border-gray-850" />
  572. <div>
  573. {#if showResetUploadDirConfirm}
  574. <div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
  575. <div class="flex items-center space-x-3">
  576. <svg
  577. xmlns="http://www.w3.org/2000/svg"
  578. viewBox="0 0 24 24"
  579. fill="currentColor"
  580. class="size-4"
  581. >
  582. <path
  583. fill-rule="evenodd"
  584. d="M5.625 1.5H9a3.75 3.75 0 0 1 3.75 3.75v1.875c0 1.036.84 1.875 1.875 1.875H16.5a3.75 3.75 0 0 1 3.75 3.75v7.875c0 1.035-.84 1.875-1.875 1.875H5.625a1.875 1.875 0 0 1-1.875-1.875V3.375c0-1.036.84-1.875 1.875-1.875ZM9.75 14.25a.75.75 0 0 0 0 1.5H15a.75.75 0 0 0 0-1.5H9.75Z"
  585. clip-rule="evenodd"
  586. />
  587. <path
  588. d="M14.25 5.25a5.23 5.23 0 0 0-1.279-3.434 9.768 9.768 0 0 1 6.963 6.963A5.23 5.23 0 0 0 16.5 7.5h-1.875a.375.375 0 0 1-.375-.375V5.25Z"
  589. />
  590. </svg>
  591. <span>{$i18n.t('Are you sure?')}</span>
  592. </div>
  593. <div class="flex space-x-1.5 items-center">
  594. <button
  595. class="hover:text-white transition"
  596. on:click={() => {
  597. const res = resetUploadDir(localStorage.token).catch((error) => {
  598. toast.error(error);
  599. return null;
  600. });
  601. if (res) {
  602. toast.success($i18n.t('Success'));
  603. }
  604. showResetUploadDirConfirm = false;
  605. }}
  606. type="button"
  607. >
  608. <svg
  609. xmlns="http://www.w3.org/2000/svg"
  610. viewBox="0 0 20 20"
  611. fill="currentColor"
  612. class="w-4 h-4"
  613. >
  614. <path
  615. fill-rule="evenodd"
  616. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  617. clip-rule="evenodd"
  618. />
  619. </svg>
  620. </button>
  621. <button
  622. class="hover:text-white transition"
  623. type="button"
  624. on:click={() => {
  625. showResetUploadDirConfirm = false;
  626. }}
  627. >
  628. <svg
  629. xmlns="http://www.w3.org/2000/svg"
  630. viewBox="0 0 20 20"
  631. fill="currentColor"
  632. class="w-4 h-4"
  633. >
  634. <path
  635. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  636. />
  637. </svg>
  638. </button>
  639. </div>
  640. </div>
  641. {:else}
  642. <button
  643. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  644. on:click={() => {
  645. showResetUploadDirConfirm = true;
  646. }}
  647. type="button"
  648. >
  649. <div class=" self-center mr-3">
  650. <svg
  651. xmlns="http://www.w3.org/2000/svg"
  652. viewBox="0 0 24 24"
  653. fill="currentColor"
  654. class="size-4"
  655. >
  656. <path
  657. fill-rule="evenodd"
  658. d="M5.625 1.5H9a3.75 3.75 0 0 1 3.75 3.75v1.875c0 1.036.84 1.875 1.875 1.875H16.5a3.75 3.75 0 0 1 3.75 3.75v7.875c0 1.035-.84 1.875-1.875 1.875H5.625a1.875 1.875 0 0 1-1.875-1.875V3.375c0-1.036.84-1.875 1.875-1.875ZM9.75 14.25a.75.75 0 0 0 0 1.5H15a.75.75 0 0 0 0-1.5H9.75Z"
  659. clip-rule="evenodd"
  660. />
  661. <path
  662. d="M14.25 5.25a5.23 5.23 0 0 0-1.279-3.434 9.768 9.768 0 0 1 6.963 6.963A5.23 5.23 0 0 0 16.5 7.5h-1.875a.375.375 0 0 1-.375-.375V5.25Z"
  663. />
  664. </svg>
  665. </div>
  666. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Upload Directory')}</div>
  667. </button>
  668. {/if}
  669. {#if showResetConfirm}
  670. <div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
  671. <div class="flex items-center space-x-3">
  672. <svg
  673. xmlns="http://www.w3.org/2000/svg"
  674. viewBox="0 0 16 16"
  675. fill="currentColor"
  676. class="w-4 h-4"
  677. >
  678. <path
  679. fill-rule="evenodd"
  680. d="M3.5 2A1.5 1.5 0 0 0 2 3.5v9A1.5 1.5 0 0 0 3.5 14h9a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 12.5 4H9.621a1.5 1.5 0 0 1-1.06-.44L7.439 2.44A1.5 1.5 0 0 0 6.38 2H3.5Zm6.75 7.75a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0 0 1.5h4.5Z"
  681. clip-rule="evenodd"
  682. />
  683. </svg>
  684. <span>{$i18n.t('Are you sure?')}</span>
  685. </div>
  686. <div class="flex space-x-1.5 items-center">
  687. <button
  688. class="hover:text-white transition"
  689. on:click={() => {
  690. const res = resetVectorDB(localStorage.token).catch((error) => {
  691. toast.error(error);
  692. return null;
  693. });
  694. if (res) {
  695. toast.success($i18n.t('Success'));
  696. }
  697. showResetConfirm = false;
  698. }}
  699. type="button"
  700. >
  701. <svg
  702. xmlns="http://www.w3.org/2000/svg"
  703. viewBox="0 0 20 20"
  704. fill="currentColor"
  705. class="w-4 h-4"
  706. >
  707. <path
  708. fill-rule="evenodd"
  709. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  710. clip-rule="evenodd"
  711. />
  712. </svg>
  713. </button>
  714. <button
  715. class="hover:text-white transition"
  716. on:click={() => {
  717. showResetConfirm = false;
  718. }}
  719. type="button"
  720. >
  721. <svg
  722. xmlns="http://www.w3.org/2000/svg"
  723. viewBox="0 0 20 20"
  724. fill="currentColor"
  725. class="w-4 h-4"
  726. >
  727. <path
  728. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  729. />
  730. </svg>
  731. </button>
  732. </div>
  733. </div>
  734. {:else}
  735. <button
  736. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  737. on:click={() => {
  738. showResetConfirm = true;
  739. }}
  740. type="button"
  741. >
  742. <div class=" self-center mr-3">
  743. <svg
  744. xmlns="http://www.w3.org/2000/svg"
  745. viewBox="0 0 16 16"
  746. fill="currentColor"
  747. class="w-4 h-4"
  748. >
  749. <path
  750. fill-rule="evenodd"
  751. d="M3.5 2A1.5 1.5 0 0 0 2 3.5v9A1.5 1.5 0 0 0 3.5 14h9a1.5 1.5 0 0 0 1.5-1.5v-7A1.5 1.5 0 0 0 12.5 4H9.621a1.5 1.5 0 0 1-1.06-.44L7.439 2.44A1.5 1.5 0 0 0 6.38 2H3.5Zm6.75 7.75a.75.75 0 0 0 0-1.5h-4.5a.75.75 0 0 0 0 1.5h4.5Z"
  752. clip-rule="evenodd"
  753. />
  754. </svg>
  755. </div>
  756. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Vector Storage')}</div>
  757. </button>
  758. {/if}
  759. </div>
  760. </div>
  761. <div class="flex justify-end pt-3 text-sm font-medium">
  762. <button
  763. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  764. type="submit"
  765. >
  766. {$i18n.t('Save')}
  767. </button>
  768. </div>
  769. </form>