General.svelte 11 KB

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