General.svelte 12 KB

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