General.svelte 21 KB

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