General.svelte 11 KB

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