General.svelte 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { createEventDispatcher, onMount, getContext } from 'svelte';
  4. const dispatch = createEventDispatcher();
  5. import { models, user } from '$lib/stores';
  6. const i18n = getContext('i18n');
  7. import AdvancedParams from './Advanced/AdvancedParams.svelte';
  8. export let saveSettings: Function;
  9. export let getModels: Function;
  10. // General
  11. let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light'];
  12. let theme = 'dark';
  13. // TODO: Get these dynamically from the i18n module
  14. let languages = ['en', 'fa', 'fr', 'de'];
  15. let lang = $i18n.language;
  16. let notificationEnabled = false;
  17. let system = '';
  18. let showAdvanced = false;
  19. const toggleNotification = async () => {
  20. const permission = await Notification.requestPermission();
  21. if (permission === 'granted') {
  22. notificationEnabled = !notificationEnabled;
  23. saveSettings({ notificationEnabled: notificationEnabled });
  24. } else {
  25. toast.error(
  26. 'Response notifications cannot be activated as the website permissions have been denied. Please visit your browser settings to grant the necessary access.'
  27. );
  28. }
  29. };
  30. // Advanced
  31. let requestFormat = '';
  32. let keepAlive = null;
  33. let options = {
  34. // Advanced
  35. seed: 0,
  36. temperature: '',
  37. repeat_penalty: '',
  38. repeat_last_n: '',
  39. mirostat: '',
  40. mirostat_eta: '',
  41. mirostat_tau: '',
  42. top_k: '',
  43. top_p: '',
  44. stop: '',
  45. tfs_z: '',
  46. num_ctx: '',
  47. num_predict: ''
  48. };
  49. const toggleRequestFormat = async () => {
  50. if (requestFormat === '') {
  51. requestFormat = 'json';
  52. } else {
  53. requestFormat = '';
  54. }
  55. saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
  56. };
  57. onMount(async () => {
  58. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  59. theme = localStorage.theme ?? 'dark';
  60. notificationEnabled = settings.notificationEnabled ?? false;
  61. system = settings.system ?? '';
  62. requestFormat = settings.requestFormat ?? '';
  63. keepAlive = settings.keepAlive ?? null;
  64. options.seed = settings.seed ?? 0;
  65. options.temperature = settings.temperature ?? '';
  66. options.repeat_penalty = settings.repeat_penalty ?? '';
  67. options.top_k = settings.top_k ?? '';
  68. options.top_p = settings.top_p ?? '';
  69. options.num_ctx = settings.num_ctx ?? '';
  70. options = { ...options, ...settings.options };
  71. options.stop = (settings?.options?.stop ?? []).join(',');
  72. });
  73. </script>
  74. <div class="flex flex-col h-full justify-between text-sm">
  75. <div class=" pr-1.5 overflow-y-scroll max-h-[20.5rem]">
  76. <div class="">
  77. <div class=" mb-1 text-sm font-medium">{$i18n.t('WebUI Settings')}</div>
  78. <div class=" py-0.5 flex w-full justify-between">
  79. <div class=" self-center text-xs font-medium">{$i18n.t('Theme')}</div>
  80. <div class="flex items-center relative">
  81. <select
  82. class=" dark:bg-gray-900 w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
  83. bind:value={theme}
  84. placeholder="Select a theme"
  85. on:change={(e) => {
  86. localStorage.theme = theme;
  87. themes
  88. .filter((e) => e !== theme)
  89. .forEach((e) => {
  90. e.split(' ').forEach((e) => {
  91. document.documentElement.classList.remove(e);
  92. });
  93. });
  94. theme.split(' ').forEach((e) => {
  95. document.documentElement.classList.add(e);
  96. });
  97. console.log(theme);
  98. }}
  99. >
  100. <option value="dark">🌑 {$i18n.t('Dark')}</option>
  101. <option value="light">☀️ {$i18n.t('Light')}</option>
  102. <option value="rose-pine dark">🪻 {$i18n.t('Rosé Pine')}</option>
  103. <option value="rose-pine-dawn light">🌷 {$i18n.t('Rosé Pine Dawn')}</option>
  104. </select>
  105. </div>
  106. </div>
  107. <div class=" py-0.5 flex w-full justify-between">
  108. <div class=" self-center text-xs font-medium">{$i18n.t('Language')}</div>
  109. <div class="flex items-center relative">
  110. <select
  111. class="w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
  112. bind:value={lang}
  113. placeholder="Select a language"
  114. on:change={(e) => {
  115. console.log($i18n);
  116. $i18n.changeLanguage(lang);
  117. }}
  118. >
  119. {#each languages as value}
  120. <option {value}>{value}</option>
  121. {/each}
  122. </select>
  123. </div>
  124. </div>
  125. <div>
  126. <div class=" py-0.5 flex w-full justify-between">
  127. <div class=" self-center text-xs font-medium">{$i18n.t('Desktop Notifications')}</div>
  128. <button
  129. class="p-1 px-3 text-xs flex rounded transition"
  130. on:click={() => {
  131. toggleNotification();
  132. }}
  133. type="button"
  134. >
  135. {#if notificationEnabled === true}
  136. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  137. {:else}
  138. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  139. {/if}
  140. </button>
  141. </div>
  142. </div>
  143. </div>
  144. <hr class=" dark:border-gray-700 my-3" />
  145. <div>
  146. <div class=" my-2.5 text-sm font-medium">{$i18n.t('System Prompt')}</div>
  147. <textarea
  148. bind:value={system}
  149. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  150. rows="4"
  151. />
  152. </div>
  153. <div class="mt-2 space-y-3 pr-1.5">
  154. <div class="flex justify-between items-center text-sm">
  155. <div class=" font-medium">{$i18n.t('Advanced Parameters')}</div>
  156. <button
  157. class=" text-xs font-medium text-gray-500"
  158. type="button"
  159. on:click={() => {
  160. showAdvanced = !showAdvanced;
  161. }}>{showAdvanced ? $i18n.t('Hide') : $i18n.t('Show')}</button
  162. >
  163. </div>
  164. {#if showAdvanced}
  165. <AdvancedParams bind:options />
  166. <hr class=" dark:border-gray-700" />
  167. <div class=" py-1 w-full justify-between">
  168. <div class="flex w-full justify-between">
  169. <div class=" self-center text-xs font-medium">{$i18n.t('Keep Alive')}</div>
  170. <button
  171. class="p-1 px-3 text-xs flex rounded transition"
  172. type="button"
  173. on:click={() => {
  174. keepAlive = keepAlive === null ? '5m' : null;
  175. }}
  176. >
  177. {#if keepAlive === null}
  178. <span class="ml-2 self-center"> {$i18n.t('Default')} </span>
  179. {:else}
  180. <span class="ml-2 self-center"> {$i18n.t('Custom')} </span>
  181. {/if}
  182. </button>
  183. </div>
  184. {#if keepAlive !== null}
  185. <div class="flex mt-1 space-x-2">
  186. <input
  187. 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"
  188. type="text"
  189. placeholder={$i18n.t("e.g. '30s','10m'. Valid time units are 's', 'm', 'h'.")}
  190. bind:value={keepAlive}
  191. />
  192. </div>
  193. {/if}
  194. </div>
  195. <div>
  196. <div class=" py-1 flex w-full justify-between">
  197. <div class=" self-center text-sm font-medium">{$i18n.t('Request Mode')}</div>
  198. <button
  199. class="p-1 px-3 text-xs flex rounded transition"
  200. on:click={() => {
  201. toggleRequestFormat();
  202. }}
  203. >
  204. {#if requestFormat === ''}
  205. <span class="ml-2 self-center"> {$i18n.t('Default')} </span>
  206. {:else if requestFormat === 'json'}
  207. <!-- <svg
  208. xmlns="http://www.w3.org/2000/svg"
  209. viewBox="0 0 20 20"
  210. fill="currentColor"
  211. class="w-4 h-4 self-center"
  212. >
  213. <path
  214. d="M10 2a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5A.75.75 0 0110 2zM10 15a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5A.75.75 0 0110 15zM10 7a3 3 0 100 6 3 3 0 000-6zM15.657 5.404a.75.75 0 10-1.06-1.06l-1.061 1.06a.75.75 0 001.06 1.06l1.06-1.06zM6.464 14.596a.75.75 0 10-1.06-1.06l-1.06 1.06a.75.75 0 001.06 1.06l1.06-1.06zM18 10a.75.75 0 01-.75.75h-1.5a.75.75 0 010-1.5h1.5A.75.75 0 0118 10zM5 10a.75.75 0 01-.75.75h-1.5a.75.75 0 010-1.5h1.5A.75.75 0 015 10zM14.596 15.657a.75.75 0 001.06-1.06l-1.06-1.061a.75.75 0 10-1.06 1.06l1.06 1.06zM5.404 6.464a.75.75 0 001.06-1.06l-1.06-1.06a.75.75 0 10-1.061 1.06l1.06 1.06z"
  215. />
  216. </svg> -->
  217. <span class="ml-2 self-center"> {$i18n.t('JSON')} </span>
  218. {/if}
  219. </button>
  220. </div>
  221. </div>
  222. {/if}
  223. </div>
  224. </div>
  225. <div class="flex justify-end pt-3 text-sm font-medium">
  226. <button
  227. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  228. on:click={() => {
  229. saveSettings({
  230. system: system !== '' ? system : undefined,
  231. options: {
  232. seed: (options.seed !== 0 ? options.seed : undefined) ?? undefined,
  233. stop: options.stop !== '' ? options.stop.split(',').filter((e) => e) : undefined,
  234. temperature: options.temperature !== '' ? options.temperature : undefined,
  235. repeat_penalty: options.repeat_penalty !== '' ? options.repeat_penalty : undefined,
  236. repeat_last_n: options.repeat_last_n !== '' ? options.repeat_last_n : undefined,
  237. mirostat: options.mirostat !== '' ? options.mirostat : undefined,
  238. mirostat_eta: options.mirostat_eta !== '' ? options.mirostat_eta : undefined,
  239. mirostat_tau: options.mirostat_tau !== '' ? options.mirostat_tau : undefined,
  240. top_k: options.top_k !== '' ? options.top_k : undefined,
  241. top_p: options.top_p !== '' ? options.top_p : undefined,
  242. tfs_z: options.tfs_z !== '' ? options.tfs_z : undefined,
  243. num_ctx: options.num_ctx !== '' ? options.num_ctx : undefined,
  244. num_predict: options.num_predict !== '' ? options.num_predict : undefined
  245. },
  246. keepAlive: keepAlive ? (isNaN(keepAlive) ? keepAlive : parseInt(keepAlive)) : undefined
  247. });
  248. dispatch('save');
  249. }}
  250. >
  251. {$i18n.t('Save')}
  252. </button>
  253. </div>
  254. </div>