General.svelte 13 KB

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