General.svelte 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  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. } from '$lib/apis/rag';
  14. import { documents, models } from '$lib/stores';
  15. import { onMount, getContext } from 'svelte';
  16. import { toast } from 'svelte-sonner';
  17. const i18n = getContext('i18n');
  18. export let saveHandler: Function;
  19. let scanDirLoading = false;
  20. let updateEmbeddingModelLoading = false;
  21. let updateRerankingModelLoading = false;
  22. let showResetConfirm = false;
  23. let showResetUploadDirConfirm = false;
  24. let embeddingEngine = '';
  25. let embeddingModel = '';
  26. let rerankingModel = '';
  27. let OpenAIKey = '';
  28. let OpenAIUrl = '';
  29. let OpenAIBatchSize = 1;
  30. let querySettings = {
  31. template: '',
  32. r: 0.0,
  33. k: 4,
  34. hybrid: false
  35. };
  36. const scanHandler = async () => {
  37. scanDirLoading = true;
  38. const res = await scanDocs(localStorage.token);
  39. scanDirLoading = false;
  40. if (res) {
  41. await documents.set(await getDocs(localStorage.token));
  42. toast.success($i18n.t('Scan complete!'));
  43. }
  44. };
  45. const embeddingModelUpdateHandler = async () => {
  46. if (embeddingEngine === '' && embeddingModel.split('/').length - 1 > 1) {
  47. toast.error(
  48. $i18n.t(
  49. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  50. )
  51. );
  52. return;
  53. }
  54. if (embeddingEngine === 'ollama' && embeddingModel === '') {
  55. toast.error(
  56. $i18n.t(
  57. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  58. )
  59. );
  60. return;
  61. }
  62. if (embeddingEngine === 'openai' && embeddingModel === '') {
  63. toast.error(
  64. $i18n.t(
  65. 'Model filesystem path detected. Model shortname is required for update, cannot continue.'
  66. )
  67. );
  68. return;
  69. }
  70. if ((embeddingEngine === 'openai' && OpenAIKey === '') || OpenAIUrl === '') {
  71. toast.error($i18n.t('OpenAI URL/Key required.'));
  72. return;
  73. }
  74. console.log('Update embedding model attempt:', embeddingModel);
  75. updateEmbeddingModelLoading = true;
  76. const res = await updateEmbeddingConfig(localStorage.token, {
  77. embedding_engine: embeddingEngine,
  78. embedding_model: embeddingModel,
  79. ...(embeddingEngine === 'openai'
  80. ? {
  81. openai_config: {
  82. key: OpenAIKey,
  83. url: OpenAIUrl,
  84. batch_size: OpenAIBatchSize
  85. }
  86. }
  87. : {})
  88. }).catch(async (error) => {
  89. toast.error(error);
  90. await setEmbeddingConfig();
  91. return null;
  92. });
  93. updateEmbeddingModelLoading = false;
  94. if (res) {
  95. console.log('embeddingModelUpdateHandler:', res);
  96. if (res.status === true) {
  97. toast.success($i18n.t('Embedding model set to "{{embedding_model}}"', res), {
  98. duration: 1000 * 10
  99. });
  100. }
  101. }
  102. };
  103. const rerankingModelUpdateHandler = async () => {
  104. console.log('Update reranking model attempt:', rerankingModel);
  105. updateRerankingModelLoading = true;
  106. const res = await updateRerankingConfig(localStorage.token, {
  107. reranking_model: rerankingModel
  108. }).catch(async (error) => {
  109. toast.error(error);
  110. await setRerankingConfig();
  111. return null;
  112. });
  113. updateRerankingModelLoading = false;
  114. if (res) {
  115. console.log('rerankingModelUpdateHandler:', res);
  116. if (res.status === true) {
  117. if (rerankingModel === '') {
  118. toast.success($i18n.t('Reranking model disabled', res), {
  119. duration: 1000 * 10
  120. });
  121. } else {
  122. toast.success($i18n.t('Reranking model set to "{{reranking_model}}"', res), {
  123. duration: 1000 * 10
  124. });
  125. }
  126. }
  127. }
  128. };
  129. const submitHandler = async () => {
  130. embeddingModelUpdateHandler();
  131. if (querySettings.hybrid) {
  132. rerankingModelUpdateHandler();
  133. }
  134. };
  135. const setEmbeddingConfig = async () => {
  136. const embeddingConfig = await getEmbeddingConfig(localStorage.token);
  137. if (embeddingConfig) {
  138. embeddingEngine = embeddingConfig.embedding_engine;
  139. embeddingModel = embeddingConfig.embedding_model;
  140. OpenAIKey = embeddingConfig.openai_config.key;
  141. OpenAIUrl = embeddingConfig.openai_config.url;
  142. OpenAIBatchSize = embeddingConfig.openai_config.batch_size ?? 1;
  143. }
  144. };
  145. const setRerankingConfig = async () => {
  146. const rerankingConfig = await getRerankingConfig(localStorage.token);
  147. if (rerankingConfig) {
  148. rerankingModel = rerankingConfig.reranking_model;
  149. }
  150. };
  151. const toggleHybridSearch = async () => {
  152. querySettings.hybrid = !querySettings.hybrid;
  153. querySettings = await updateQuerySettings(localStorage.token, querySettings);
  154. };
  155. onMount(async () => {
  156. await setEmbeddingConfig();
  157. await setRerankingConfig();
  158. querySettings = await getQuerySettings(localStorage.token);
  159. });
  160. </script>
  161. <form
  162. class="flex flex-col h-full justify-between space-y-3 text-sm"
  163. on:submit|preventDefault={() => {
  164. submitHandler();
  165. saveHandler();
  166. }}
  167. >
  168. <div class=" space-y-2.5 pr-1.5 overflow-y-scroll max-h-[28rem]">
  169. <div class="flex flex-col gap-0.5">
  170. <div class=" mb-0.5 text-sm font-medium">{$i18n.t('General Settings')}</div>
  171. <div class=" flex w-full justify-between">
  172. <div class=" self-center text-xs font-medium">
  173. {$i18n.t('Scan for documents from {{path}}', { path: 'DOCS_DIR (/data/docs)' })}
  174. </div>
  175. <button
  176. 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
  177. ? ' cursor-not-allowed'
  178. : ''}"
  179. on:click={() => {
  180. scanHandler();
  181. console.log('check');
  182. }}
  183. type="button"
  184. disabled={scanDirLoading}
  185. >
  186. <div class="self-center font-medium">{$i18n.t('Scan')}</div>
  187. {#if scanDirLoading}
  188. <div class="ml-3 self-center">
  189. <svg
  190. class=" w-3 h-3"
  191. viewBox="0 0 24 24"
  192. fill="currentColor"
  193. xmlns="http://www.w3.org/2000/svg"
  194. ><style>
  195. .spinner_ajPY {
  196. transform-origin: center;
  197. animation: spinner_AtaB 0.75s infinite linear;
  198. }
  199. @keyframes spinner_AtaB {
  200. 100% {
  201. transform: rotate(360deg);
  202. }
  203. }
  204. </style><path
  205. 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"
  206. opacity=".25"
  207. /><path
  208. 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"
  209. class="spinner_ajPY"
  210. /></svg
  211. >
  212. </div>
  213. {/if}
  214. </button>
  215. </div>
  216. <div class=" flex w-full justify-between">
  217. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Model Engine')}</div>
  218. <div class="flex items-center relative">
  219. <select
  220. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
  221. bind:value={embeddingEngine}
  222. placeholder="Select an embedding model engine"
  223. on:change={(e) => {
  224. if (e.target.value === 'ollama') {
  225. embeddingModel = '';
  226. } else if (e.target.value === 'openai') {
  227. embeddingModel = 'text-embedding-3-small';
  228. } else if (e.target.value === '') {
  229. embeddingModel = 'sentence-transformers/all-MiniLM-L6-v2';
  230. }
  231. }}
  232. >
  233. <option value="">{$i18n.t('Default (SentenceTransformers)')}</option>
  234. <option value="ollama">{$i18n.t('Ollama')}</option>
  235. <option value="openai">{$i18n.t('OpenAI')}</option>
  236. </select>
  237. </div>
  238. </div>
  239. {#if embeddingEngine === 'openai'}
  240. <div class="my-0.5 flex gap-2">
  241. <input
  242. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  243. placeholder={$i18n.t('API Base URL')}
  244. bind:value={OpenAIUrl}
  245. required
  246. />
  247. <input
  248. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  249. placeholder={$i18n.t('API Key')}
  250. bind:value={OpenAIKey}
  251. required
  252. />
  253. </div>
  254. <div class="flex mt-0.5 space-x-2">
  255. <div class=" self-center text-xs font-medium">{$i18n.t('Embedding Batch Size')}</div>
  256. <div class=" flex-1">
  257. <input
  258. id="steps-range"
  259. type="range"
  260. min="1"
  261. max="2048"
  262. step="1"
  263. bind:value={OpenAIBatchSize}
  264. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  265. />
  266. </div>
  267. <div class="">
  268. <input
  269. bind:value={OpenAIBatchSize}
  270. type="number"
  271. class=" bg-transparent text-center w-14"
  272. min="-2"
  273. max="16000"
  274. step="1"
  275. />
  276. </div>
  277. </div>
  278. {/if}
  279. <div class=" flex w-full justify-between">
  280. <div class=" self-center text-xs font-medium">{$i18n.t('Hybrid Search')}</div>
  281. <button
  282. class="p-1 px-3 text-xs flex rounded transition"
  283. on:click={() => {
  284. toggleHybridSearch();
  285. }}
  286. type="button"
  287. >
  288. {#if querySettings.hybrid === true}
  289. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  290. {:else}
  291. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  292. {/if}
  293. </button>
  294. </div>
  295. </div>
  296. <hr class=" dark:border-gray-850 my-1" />
  297. <div class="space-y-2" />
  298. <div>
  299. <div class=" mb-2 text-sm font-medium">{$i18n.t('Embedding Model')}</div>
  300. {#if embeddingEngine === 'ollama'}
  301. <div class="flex w-full">
  302. <div class="flex-1 mr-2">
  303. <select
  304. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  305. bind:value={embeddingModel}
  306. placeholder={$i18n.t('Select a model')}
  307. required
  308. >
  309. {#if !embeddingModel}
  310. <option value="" disabled selected>{$i18n.t('Select a model')}</option>
  311. {/if}
  312. {#each $models.filter((m) => m.id && m.ollama && !(m?.preset ?? false)) as model}
  313. <option value={model.id} class="bg-gray-100 dark:bg-gray-700">{model.name}</option>
  314. {/each}
  315. </select>
  316. </div>
  317. </div>
  318. {:else}
  319. <div class="flex w-full">
  320. <div class="flex-1 mr-2">
  321. <input
  322. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  323. placeholder={$i18n.t('Set embedding model (e.g. {{model}})', {
  324. model: embeddingModel.slice(-40)
  325. })}
  326. bind:value={embeddingModel}
  327. />
  328. </div>
  329. {#if embeddingEngine === ''}
  330. <button
  331. 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"
  332. on:click={() => {
  333. embeddingModelUpdateHandler();
  334. }}
  335. disabled={updateEmbeddingModelLoading}
  336. >
  337. {#if updateEmbeddingModelLoading}
  338. <div class="self-center">
  339. <svg
  340. class=" w-4 h-4"
  341. viewBox="0 0 24 24"
  342. fill="currentColor"
  343. xmlns="http://www.w3.org/2000/svg"
  344. ><style>
  345. .spinner_ajPY {
  346. transform-origin: center;
  347. animation: spinner_AtaB 0.75s infinite linear;
  348. }
  349. @keyframes spinner_AtaB {
  350. 100% {
  351. transform: rotate(360deg);
  352. }
  353. }
  354. </style><path
  355. 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"
  356. opacity=".25"
  357. /><path
  358. 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"
  359. class="spinner_ajPY"
  360. /></svg
  361. >
  362. </div>
  363. {:else}
  364. <svg
  365. xmlns="http://www.w3.org/2000/svg"
  366. viewBox="0 0 16 16"
  367. fill="currentColor"
  368. class="w-4 h-4"
  369. >
  370. <path
  371. 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"
  372. />
  373. <path
  374. 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"
  375. />
  376. </svg>
  377. {/if}
  378. </button>
  379. {/if}
  380. </div>
  381. {/if}
  382. <div class="mt-2 mb-1 text-xs text-gray-400 dark:text-gray-500">
  383. {$i18n.t(
  384. 'Warning: If you update or change your embedding model, you will need to re-import all documents.'
  385. )}
  386. </div>
  387. {#if querySettings.hybrid === true}
  388. <div class=" ">
  389. <div class=" mb-2 text-sm font-medium">{$i18n.t('Reranking Model')}</div>
  390. <div class="flex w-full">
  391. <div class="flex-1 mr-2">
  392. <input
  393. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  394. placeholder={$i18n.t('Set reranking model (e.g. {{model}})', {
  395. model: 'BAAI/bge-reranker-v2-m3'
  396. })}
  397. bind:value={rerankingModel}
  398. />
  399. </div>
  400. <button
  401. 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"
  402. on:click={() => {
  403. rerankingModelUpdateHandler();
  404. }}
  405. disabled={updateRerankingModelLoading}
  406. >
  407. {#if updateRerankingModelLoading}
  408. <div class="self-center">
  409. <svg
  410. class=" w-4 h-4"
  411. viewBox="0 0 24 24"
  412. fill="currentColor"
  413. xmlns="http://www.w3.org/2000/svg"
  414. ><style>
  415. .spinner_ajPY {
  416. transform-origin: center;
  417. animation: spinner_AtaB 0.75s infinite linear;
  418. }
  419. @keyframes spinner_AtaB {
  420. 100% {
  421. transform: rotate(360deg);
  422. }
  423. }
  424. </style><path
  425. 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"
  426. opacity=".25"
  427. /><path
  428. 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"
  429. class="spinner_ajPY"
  430. /></svg
  431. >
  432. </div>
  433. {:else}
  434. <svg
  435. xmlns="http://www.w3.org/2000/svg"
  436. viewBox="0 0 16 16"
  437. fill="currentColor"
  438. class="w-4 h-4"
  439. >
  440. <path
  441. 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"
  442. />
  443. <path
  444. 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"
  445. />
  446. </svg>
  447. {/if}
  448. </button>
  449. </div>
  450. </div>
  451. {/if}
  452. </div>
  453. <hr class=" dark:border-gray-850" />
  454. <div>
  455. {#if showResetUploadDirConfirm}
  456. <div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
  457. <div class="flex items-center space-x-3">
  458. <svg
  459. xmlns="http://www.w3.org/2000/svg"
  460. viewBox="0 0 24 24"
  461. fill="currentColor"
  462. class="size-4"
  463. >
  464. <path
  465. fill-rule="evenodd"
  466. 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"
  467. clip-rule="evenodd"
  468. />
  469. <path
  470. 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"
  471. />
  472. </svg>
  473. <span>{$i18n.t('Are you sure?')}</span>
  474. </div>
  475. <div class="flex space-x-1.5 items-center">
  476. <button
  477. class="hover:text-white transition"
  478. on:click={() => {
  479. const res = resetUploadDir(localStorage.token).catch((error) => {
  480. toast.error(error);
  481. return null;
  482. });
  483. if (res) {
  484. toast.success($i18n.t('Success'));
  485. }
  486. showResetUploadDirConfirm = false;
  487. }}
  488. type="button"
  489. >
  490. <svg
  491. xmlns="http://www.w3.org/2000/svg"
  492. viewBox="0 0 20 20"
  493. fill="currentColor"
  494. class="w-4 h-4"
  495. >
  496. <path
  497. fill-rule="evenodd"
  498. 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"
  499. clip-rule="evenodd"
  500. />
  501. </svg>
  502. </button>
  503. <button
  504. class="hover:text-white transition"
  505. type="button"
  506. on:click={() => {
  507. showResetUploadDirConfirm = false;
  508. }}
  509. >
  510. <svg
  511. xmlns="http://www.w3.org/2000/svg"
  512. viewBox="0 0 20 20"
  513. fill="currentColor"
  514. class="w-4 h-4"
  515. >
  516. <path
  517. 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"
  518. />
  519. </svg>
  520. </button>
  521. </div>
  522. </div>
  523. {:else}
  524. <button
  525. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  526. on:click={() => {
  527. showResetUploadDirConfirm = true;
  528. }}
  529. type="button"
  530. >
  531. <div class=" self-center mr-3">
  532. <svg
  533. xmlns="http://www.w3.org/2000/svg"
  534. viewBox="0 0 24 24"
  535. fill="currentColor"
  536. class="size-4"
  537. >
  538. <path
  539. fill-rule="evenodd"
  540. 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"
  541. clip-rule="evenodd"
  542. />
  543. <path
  544. 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"
  545. />
  546. </svg>
  547. </div>
  548. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Upload Directory')}</div>
  549. </button>
  550. {/if}
  551. {#if showResetConfirm}
  552. <div class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition">
  553. <div class="flex items-center space-x-3">
  554. <svg
  555. xmlns="http://www.w3.org/2000/svg"
  556. viewBox="0 0 16 16"
  557. fill="currentColor"
  558. class="w-4 h-4"
  559. >
  560. <path
  561. fill-rule="evenodd"
  562. 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"
  563. clip-rule="evenodd"
  564. />
  565. </svg>
  566. <span>{$i18n.t('Are you sure?')}</span>
  567. </div>
  568. <div class="flex space-x-1.5 items-center">
  569. <button
  570. class="hover:text-white transition"
  571. on:click={() => {
  572. const res = resetVectorDB(localStorage.token).catch((error) => {
  573. toast.error(error);
  574. return null;
  575. });
  576. if (res) {
  577. toast.success($i18n.t('Success'));
  578. }
  579. showResetConfirm = false;
  580. }}
  581. type="button"
  582. >
  583. <svg
  584. xmlns="http://www.w3.org/2000/svg"
  585. viewBox="0 0 20 20"
  586. fill="currentColor"
  587. class="w-4 h-4"
  588. >
  589. <path
  590. fill-rule="evenodd"
  591. 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"
  592. clip-rule="evenodd"
  593. />
  594. </svg>
  595. </button>
  596. <button
  597. class="hover:text-white transition"
  598. on:click={() => {
  599. showResetConfirm = false;
  600. }}
  601. type="button"
  602. >
  603. <svg
  604. xmlns="http://www.w3.org/2000/svg"
  605. viewBox="0 0 20 20"
  606. fill="currentColor"
  607. class="w-4 h-4"
  608. >
  609. <path
  610. 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"
  611. />
  612. </svg>
  613. </button>
  614. </div>
  615. </div>
  616. {:else}
  617. <button
  618. class=" flex rounded-xl py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  619. on:click={() => {
  620. showResetConfirm = true;
  621. }}
  622. type="button"
  623. >
  624. <div class=" self-center mr-3">
  625. <svg
  626. xmlns="http://www.w3.org/2000/svg"
  627. viewBox="0 0 16 16"
  628. fill="currentColor"
  629. class="w-4 h-4"
  630. >
  631. <path
  632. fill-rule="evenodd"
  633. 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"
  634. clip-rule="evenodd"
  635. />
  636. </svg>
  637. </div>
  638. <div class=" self-center text-sm font-medium">{$i18n.t('Reset Vector Storage')}</div>
  639. </button>
  640. {/if}
  641. </div>
  642. </div>
  643. <div class="flex justify-end pt-3 text-sm font-medium">
  644. <button
  645. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  646. type="submit"
  647. >
  648. {$i18n.t('Save')}
  649. </button>
  650. </div>
  651. </form>