General.svelte 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { createEventDispatcher, onMount, getContext } from 'svelte';
  4. import { getLanguages } from '$lib/i18n';
  5. const dispatch = createEventDispatcher();
  6. import { models, settings, theme, user } from '$lib/stores';
  7. const i18n = getContext('i18n');
  8. import AdvancedParams from './Advanced/AdvancedParams.svelte';
  9. export let saveSettings: Function;
  10. export let getModels: Function;
  11. // General
  12. let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light', 'oled-dark'];
  13. let selectedTheme = 'system';
  14. let languages = [];
  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. $i18n.t(
  27. 'Response notifications cannot be activated as the website permissions have been denied. Please visit your browser settings to grant the necessary access.'
  28. )
  29. );
  30. }
  31. };
  32. // Advanced
  33. let requestFormat = '';
  34. let keepAlive = null;
  35. let params = {
  36. // Advanced
  37. seed: null,
  38. temperature: null,
  39. frequency_penalty: null,
  40. repeat_last_n: null,
  41. mirostat: null,
  42. mirostat_eta: null,
  43. mirostat_tau: null,
  44. top_k: null,
  45. top_p: null,
  46. stop: null,
  47. tfs_z: null,
  48. num_ctx: null,
  49. num_batch: null,
  50. num_keep: null,
  51. max_tokens: null
  52. };
  53. const toggleRequestFormat = async () => {
  54. if (requestFormat === '') {
  55. requestFormat = 'json';
  56. } else {
  57. requestFormat = '';
  58. }
  59. saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
  60. };
  61. onMount(async () => {
  62. selectedTheme = localStorage.theme ?? 'system';
  63. languages = await getLanguages();
  64. notificationEnabled = $settings.notificationEnabled ?? false;
  65. system = $settings.system ?? '';
  66. requestFormat = $settings.requestFormat ?? '';
  67. keepAlive = $settings.keepAlive ?? null;
  68. params = { ...params, ...$settings.params };
  69. params.stop = $settings?.params?.stop ? ($settings?.params?.stop ?? []).join(',') : null;
  70. });
  71. const applyTheme = (_theme: string) => {
  72. let themeToApply = _theme === 'oled-dark' ? 'dark' : _theme;
  73. if (_theme === 'system') {
  74. themeToApply = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
  75. }
  76. if (themeToApply === 'dark' && !_theme.includes('oled')) {
  77. document.documentElement.style.setProperty('--color-gray-900', '#171717');
  78. document.documentElement.style.setProperty('--color-gray-950', '#0d0d0d');
  79. }
  80. themes
  81. .filter((e) => e !== themeToApply)
  82. .forEach((e) => {
  83. e.split(' ').forEach((e) => {
  84. document.documentElement.classList.remove(e);
  85. });
  86. });
  87. themeToApply.split(' ').forEach((e) => {
  88. document.documentElement.classList.add(e);
  89. });
  90. console.log(_theme);
  91. };
  92. const themeChangeHandler = (_theme: string) => {
  93. theme.set(_theme);
  94. localStorage.setItem('theme', _theme);
  95. if (_theme.includes('oled')) {
  96. document.documentElement.style.setProperty('--color-gray-900', '#000000');
  97. document.documentElement.style.setProperty('--color-gray-950', '#000000');
  98. document.documentElement.classList.add('dark');
  99. }
  100. applyTheme(_theme);
  101. };
  102. </script>
  103. <div class="flex flex-col h-full justify-between text-sm">
  104. <div class=" pr-1.5 overflow-y-scroll max-h-[25rem]">
  105. <div class="">
  106. <div class=" mb-1 text-sm font-medium">{$i18n.t('WebUI Settings')}</div>
  107. <div class="flex w-full justify-between">
  108. <div class=" self-center text-xs font-medium">{$i18n.t('Theme')}</div>
  109. <div class="flex items-center relative">
  110. <select
  111. class=" dark:bg-gray-900 w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
  112. bind:value={selectedTheme}
  113. placeholder="Select a theme"
  114. on:change={() => themeChangeHandler(selectedTheme)}
  115. >
  116. <option value="system">⚙️ {$i18n.t('System')}</option>
  117. <option value="dark">🌑 {$i18n.t('Dark')}</option>
  118. <option value="oled-dark">🌃 {$i18n.t('OLED Dark')}</option>
  119. <option value="light">☀️ {$i18n.t('Light')}</option>
  120. <option value="her">🌷 Her</option>
  121. <!-- <option value="rose-pine dark">🪻 {$i18n.t('Rosé Pine')}</option>
  122. <option value="rose-pine-dawn light">🌷 {$i18n.t('Rosé Pine Dawn')}</option> -->
  123. </select>
  124. </div>
  125. </div>
  126. <div class=" flex w-full justify-between">
  127. <div class=" self-center text-xs font-medium">{$i18n.t('Language')}</div>
  128. <div class="flex items-center relative">
  129. <select
  130. class=" dark:bg-gray-900 w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
  131. bind:value={lang}
  132. placeholder="Select a language"
  133. on:change={(e) => {
  134. $i18n.changeLanguage(lang);
  135. }}
  136. >
  137. {#each languages as language}
  138. <option value={language['code']}>{language['title']}</option>
  139. {/each}
  140. </select>
  141. </div>
  142. </div>
  143. {#if $i18n.language === 'en-US'}
  144. <div class="mb-2 text-xs text-gray-400 dark:text-gray-500">
  145. Couldn't find your language?
  146. <a
  147. class=" text-gray-300 font-medium underline"
  148. href="https://github.com/open-webui/open-webui/blob/main/docs/CONTRIBUTING.md#-translations-and-internationalization"
  149. target="_blank"
  150. >
  151. Help us translate Open WebUI!
  152. </a>
  153. </div>
  154. {/if}
  155. <div>
  156. <div class=" py-0.5 flex w-full justify-between">
  157. <div class=" self-center text-xs font-medium">{$i18n.t('Notifications')}</div>
  158. <button
  159. class="p-1 px-3 text-xs flex rounded transition"
  160. on:click={() => {
  161. toggleNotification();
  162. }}
  163. type="button"
  164. >
  165. {#if notificationEnabled === true}
  166. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  167. {:else}
  168. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  169. {/if}
  170. </button>
  171. </div>
  172. </div>
  173. </div>
  174. <hr class=" dark:border-gray-850 my-3" />
  175. <div>
  176. <div class=" my-2.5 text-sm font-medium">{$i18n.t('System Prompt')}</div>
  177. <textarea
  178. bind:value={system}
  179. class="w-full rounded-lg p-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none resize-none"
  180. rows="4"
  181. />
  182. </div>
  183. <div class="mt-2 space-y-3 pr-1.5">
  184. <div class="flex justify-between items-center text-sm">
  185. <div class=" font-medium">{$i18n.t('Advanced Parameters')}</div>
  186. <button
  187. class=" text-xs font-medium text-gray-500"
  188. type="button"
  189. on:click={() => {
  190. showAdvanced = !showAdvanced;
  191. }}>{showAdvanced ? $i18n.t('Hide') : $i18n.t('Show')}</button
  192. >
  193. </div>
  194. {#if showAdvanced}
  195. <AdvancedParams admin={$user?.role === 'admin'} bind:params />
  196. <hr class=" dark:border-gray-850" />
  197. <div class=" py-1 w-full justify-between">
  198. <div class="flex w-full justify-between">
  199. <div class=" self-center text-xs font-medium">{$i18n.t('Keep Alive')}</div>
  200. <button
  201. class="p-1 px-3 text-xs flex rounded transition"
  202. type="button"
  203. on:click={() => {
  204. keepAlive = keepAlive === null ? '5m' : null;
  205. }}
  206. >
  207. {#if keepAlive === null}
  208. <span class="ml-2 self-center"> {$i18n.t('Default')} </span>
  209. {:else}
  210. <span class="ml-2 self-center"> {$i18n.t('Custom')} </span>
  211. {/if}
  212. </button>
  213. </div>
  214. {#if keepAlive !== null}
  215. <div class="flex mt-1 space-x-2">
  216. <input
  217. class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
  218. type="text"
  219. placeholder={$i18n.t("e.g. '30s','10m'. Valid time units are 's', 'm', 'h'.")}
  220. bind:value={keepAlive}
  221. />
  222. </div>
  223. {/if}
  224. </div>
  225. <div>
  226. <div class=" py-1 flex w-full justify-between">
  227. <div class=" self-center text-sm font-medium">{$i18n.t('Request Mode')}</div>
  228. <button
  229. class="p-1 px-3 text-xs flex rounded transition"
  230. on:click={() => {
  231. toggleRequestFormat();
  232. }}
  233. >
  234. {#if requestFormat === ''}
  235. <span class="ml-2 self-center"> {$i18n.t('Default')} </span>
  236. {:else if requestFormat === 'json'}
  237. <!-- <svg
  238. xmlns="http://www.w3.org/2000/svg"
  239. viewBox="0 0 20 20"
  240. fill="currentColor"
  241. class="w-4 h-4 self-center"
  242. >
  243. <path
  244. 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"
  245. />
  246. </svg> -->
  247. <span class="ml-2 self-center"> {$i18n.t('JSON')} </span>
  248. {/if}
  249. </button>
  250. </div>
  251. </div>
  252. {/if}
  253. </div>
  254. </div>
  255. <div class="flex justify-end pt-3 text-sm font-medium">
  256. <button
  257. class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
  258. on:click={() => {
  259. saveSettings({
  260. system: system !== '' ? system : undefined,
  261. params: {
  262. seed: (params.seed !== null ? params.seed : undefined) ?? undefined,
  263. stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined,
  264. temperature: params.temperature !== null ? params.temperature : undefined,
  265. frequency_penalty:
  266. params.frequency_penalty !== null ? params.frequency_penalty : undefined,
  267. repeat_last_n: params.repeat_last_n !== null ? params.repeat_last_n : undefined,
  268. mirostat: params.mirostat !== null ? params.mirostat : undefined,
  269. mirostat_eta: params.mirostat_eta !== null ? params.mirostat_eta : undefined,
  270. mirostat_tau: params.mirostat_tau !== null ? params.mirostat_tau : undefined,
  271. top_k: params.top_k !== null ? params.top_k : undefined,
  272. top_p: params.top_p !== null ? params.top_p : undefined,
  273. tfs_z: params.tfs_z !== null ? params.tfs_z : undefined,
  274. num_ctx: params.num_ctx !== null ? params.num_ctx : undefined,
  275. num_batch: params.num_batch !== null ? params.num_batch : undefined,
  276. num_keep: params.num_keep !== null ? params.num_keep : undefined,
  277. max_tokens: params.max_tokens !== null ? params.max_tokens : undefined,
  278. use_mmap: params.use_mmap !== null ? params.use_mmap : undefined,
  279. use_mlock: params.use_mlock !== null ? params.use_mlock : undefined,
  280. num_thread: params.num_thread !== null ? params.num_thread : undefined
  281. },
  282. keepAlive: keepAlive ? (isNaN(keepAlive) ? keepAlive : parseInt(keepAlive)) : undefined
  283. });
  284. dispatch('save');
  285. }}
  286. >
  287. {$i18n.t('Save')}
  288. </button>
  289. </div>
  290. </div>