WebParams.svelte 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <script lang="ts">
  2. import { getRAGConfig, updateRAGConfig } from '$lib/apis/rag';
  3. import Switch from '$lib/components/common/Switch.svelte';
  4. import { documents, models } from '$lib/stores';
  5. import { onMount, getContext } from 'svelte';
  6. import { toast } from 'svelte-sonner';
  7. const i18n = getContext('i18n');
  8. export let saveHandler: Function;
  9. let webConfig = null;
  10. let webSearchEngines = ['searxng', 'google_pse', 'brave', 'serpstack', 'serper'];
  11. let youtubeLanguage = 'en';
  12. let youtubeTranslation = null;
  13. const submitHandler = async () => {
  14. const res = await updateRAGConfig(localStorage.token, {
  15. web: webConfig,
  16. youtube: {
  17. language: youtubeLanguage.split(',').map((lang) => lang.trim()),
  18. translation: youtubeTranslation
  19. }
  20. });
  21. };
  22. onMount(async () => {
  23. const res = await getRAGConfig(localStorage.token);
  24. if (res) {
  25. webConfig = res.web;
  26. youtubeLanguage = res.youtube.language.join(',');
  27. youtubeTranslation = res.youtube.translation;
  28. }
  29. });
  30. </script>
  31. <form
  32. class="flex flex-col h-full justify-between space-y-3 text-sm"
  33. on:submit|preventDefault={async () => {
  34. await submitHandler();
  35. saveHandler();
  36. }}
  37. >
  38. <div class=" space-y-3 pr-1.5 overflow-y-scroll h-full max-h-[22rem]">
  39. {#if webConfig}
  40. <div>
  41. <div class=" mb-1 text-sm font-medium">
  42. {$i18n.t('Web Search')}
  43. </div>
  44. <div>
  45. <div class=" py-0.5 flex w-full justify-between">
  46. <div class=" self-center text-xs font-medium">
  47. {$i18n.t('Enable Web Search')}
  48. </div>
  49. <Switch bind:state={webConfig.search.enable} />
  50. </div>
  51. </div>
  52. <div class=" py-0.5 flex w-full justify-between">
  53. <div class=" self-center text-xs font-medium">{$i18n.t('Web Search Engine')}</div>
  54. <div class="flex items-center relative">
  55. <select
  56. class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
  57. bind:value={webConfig.search.engine}
  58. placeholder="Select a engine"
  59. required
  60. >
  61. <option disabled selected value="">Select a engine</option>
  62. {#each webSearchEngines as engine}
  63. <option value={engine}>{engine}</option>
  64. {/each}
  65. </select>
  66. </div>
  67. </div>
  68. {#if webConfig.search.engine !== ''}
  69. <div class="mt-1.5">
  70. {#if webConfig.search.engine === 'searxng'}
  71. <div>
  72. <div class=" self-center text-xs font-medium mb-1">
  73. {$i18n.t('Searxng Query URL')}
  74. </div>
  75. <div class="flex w-full">
  76. <div class="flex-1">
  77. <input
  78. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  79. type="text"
  80. placeholder={$i18n.t('Enter Searxng Query URL')}
  81. bind:value={webConfig.search.searxng_query_url}
  82. autocomplete="off"
  83. />
  84. </div>
  85. </div>
  86. </div>
  87. {:else if webConfig.search.engine === 'google_pse'}
  88. <div>
  89. <div class=" self-center text-xs font-medium mb-1">
  90. {$i18n.t('Google PSE API Key')}
  91. </div>
  92. <div class="flex w-full">
  93. <div class="flex-1">
  94. <input
  95. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  96. type="text"
  97. placeholder={$i18n.t('Enter Google PSE API Key')}
  98. bind:value={webConfig.search.google_pse_api_key}
  99. autocomplete="off"
  100. />
  101. </div>
  102. </div>
  103. </div>
  104. <div class="mt-1.5">
  105. <div class=" self-center text-xs font-medium mb-1">
  106. {$i18n.t('Google PSE Engine Id')}
  107. </div>
  108. <div class="flex w-full">
  109. <div class="flex-1">
  110. <input
  111. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  112. type="text"
  113. placeholder={$i18n.t('Enter Google PSE Engine Id')}
  114. bind:value={webConfig.search.google_pse_engine_id}
  115. autocomplete="off"
  116. />
  117. </div>
  118. </div>
  119. </div>
  120. {:else if webConfig.search.engine === 'brave'}
  121. <div>
  122. <div class=" self-center text-xs font-medium mb-1">
  123. {$i18n.t('Brave Search API Key')}
  124. </div>
  125. <div class="flex w-full">
  126. <div class="flex-1">
  127. <input
  128. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  129. type="text"
  130. placeholder={$i18n.t('Enter Brave Search API Key')}
  131. bind:value={webConfig.search.brave_search_api_key}
  132. autocomplete="off"
  133. />
  134. </div>
  135. </div>
  136. </div>
  137. {:else if webConfig.search.engine === 'serpstack'}
  138. <div>
  139. <div class=" self-center text-xs font-medium mb-1">
  140. {$i18n.t('Serpstack API Key')}
  141. </div>
  142. <div class="flex w-full">
  143. <div class="flex-1">
  144. <input
  145. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  146. type="text"
  147. placeholder={$i18n.t('Enter Serpstack API Key')}
  148. bind:value={webConfig.search.serpstack_api_key}
  149. autocomplete="off"
  150. />
  151. </div>
  152. </div>
  153. </div>
  154. {:else if webConfig.search.engine === 'serper'}
  155. <div>
  156. <div class=" self-center text-xs font-medium mb-1">
  157. {$i18n.t('Serper API Key')}
  158. </div>
  159. <div class="flex w-full">
  160. <div class="flex-1">
  161. <input
  162. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  163. type="text"
  164. placeholder={$i18n.t('Enter Serper API Key')}
  165. bind:value={webConfig.search.serper_api_key}
  166. autocomplete="off"
  167. />
  168. </div>
  169. </div>
  170. </div>
  171. {/if}
  172. </div>
  173. {/if}
  174. </div>
  175. <hr class=" dark:border-gray-850 my-2" />
  176. <div>
  177. <div class=" mb-1 text-sm font-medium">
  178. {$i18n.t('Web Loader Settings')}
  179. </div>
  180. <div>
  181. <div class=" py-0.5 flex w-full justify-between">
  182. <div class=" self-center text-xs font-medium">
  183. {$i18n.t('Bypass SSL verification for Websites')}
  184. </div>
  185. <button
  186. class="p-1 px-3 text-xs flex rounded transition"
  187. on:click={() => {
  188. webConfig.ssl_verification = !webConfig.ssl_verification;
  189. submitHandler();
  190. }}
  191. type="button"
  192. >
  193. {#if webConfig.ssl_verification === true}
  194. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  195. {:else}
  196. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  197. {/if}
  198. </button>
  199. </div>
  200. </div>
  201. <div class=" mt-2 mb-1 text-sm font-medium">
  202. {$i18n.t('Youtube Loader Settings')}
  203. </div>
  204. <div>
  205. <div class=" py-0.5 flex w-full justify-between">
  206. <div class=" w-20 text-xs font-medium self-center">{$i18n.t('Language')}</div>
  207. <div class=" flex-1 self-center">
  208. <input
  209. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  210. type="text"
  211. placeholder={$i18n.t('Enter language codes')}
  212. bind:value={youtubeLanguage}
  213. autocomplete="off"
  214. />
  215. </div>
  216. </div>
  217. </div>
  218. </div>
  219. {/if}
  220. </div>
  221. <div class="flex justify-end pt-3 text-sm font-medium">
  222. <button
  223. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  224. type="submit"
  225. >
  226. {$i18n.t('Save')}
  227. </button>
  228. </div>
  229. </form>