General.svelte 13 KB

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