General.svelte 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { createEventDispatcher, onMount, getContext } from 'svelte';
  4. import { getLanguages, changeLanguage } from '$lib/i18n';
  5. const dispatch = createEventDispatcher();
  6. import { config, models, settings, theme, user } from '$lib/stores';
  7. const i18n = getContext('i18n');
  8. import AdvancedParams from './Advanced/AdvancedParams.svelte';
  9. import Textarea from '$lib/components/common/Textarea.svelte';
  10. export let saveSettings: Function;
  11. export let getModels: Function;
  12. // General
  13. let themes = ['dark', 'light', 'oled-dark'];
  14. let selectedTheme = 'system';
  15. let languages: Awaited<ReturnType<typeof getLanguages>> = [];
  16. let lang = $i18n.language;
  17. let notificationEnabled = false;
  18. let system = '';
  19. let showAdvanced = false;
  20. const toggleNotification = async () => {
  21. const permission = await Notification.requestPermission();
  22. if (permission === 'granted') {
  23. notificationEnabled = !notificationEnabled;
  24. saveSettings({ notificationEnabled: notificationEnabled });
  25. } else {
  26. toast.error(
  27. $i18n.t(
  28. 'Response notifications cannot be activated as the website permissions have been denied. Please visit your browser settings to grant the necessary access.'
  29. )
  30. );
  31. }
  32. };
  33. let params = {
  34. // Advanced
  35. stream_response: null,
  36. stream_delta_chunk_size: null,
  37. function_calling: null,
  38. seed: null,
  39. temperature: null,
  40. reasoning_effort: null,
  41. logit_bias: 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 saveHandler = async () => {
  61. saveSettings({
  62. system: system !== '' ? system : undefined,
  63. params: {
  64. stream_response: params.stream_response !== null ? params.stream_response : undefined,
  65. stream_delta_chunk_size:
  66. params.stream_delta_chunk_size !== null ? params.stream_delta_chunk_size : undefined,
  67. function_calling: params.function_calling !== null ? params.function_calling : undefined,
  68. seed: (params.seed !== null ? params.seed : undefined) ?? undefined,
  69. stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined,
  70. temperature: params.temperature !== null ? params.temperature : undefined,
  71. reasoning_effort: params.reasoning_effort !== null ? params.reasoning_effort : undefined,
  72. logit_bias: params.logit_bias !== null ? params.logit_bias : undefined,
  73. frequency_penalty: params.frequency_penalty !== null ? params.frequency_penalty : undefined,
  74. presence_penalty: params.frequency_penalty !== null ? params.frequency_penalty : undefined,
  75. repeat_penalty: params.frequency_penalty !== null ? params.frequency_penalty : undefined,
  76. repeat_last_n: params.repeat_last_n !== null ? params.repeat_last_n : undefined,
  77. mirostat: params.mirostat !== null ? params.mirostat : undefined,
  78. mirostat_eta: params.mirostat_eta !== null ? params.mirostat_eta : undefined,
  79. mirostat_tau: params.mirostat_tau !== null ? params.mirostat_tau : undefined,
  80. top_k: params.top_k !== null ? params.top_k : undefined,
  81. top_p: params.top_p !== null ? params.top_p : undefined,
  82. min_p: params.min_p !== null ? params.min_p : undefined,
  83. tfs_z: params.tfs_z !== null ? params.tfs_z : undefined,
  84. num_ctx: params.num_ctx !== null ? params.num_ctx : undefined,
  85. num_batch: params.num_batch !== null ? params.num_batch : undefined,
  86. num_keep: params.num_keep !== null ? params.num_keep : undefined,
  87. max_tokens: params.max_tokens !== null ? params.max_tokens : undefined,
  88. use_mmap: params.use_mmap !== null ? params.use_mmap : undefined,
  89. use_mlock: params.use_mlock !== null ? params.use_mlock : undefined,
  90. num_thread: params.num_thread !== null ? params.num_thread : undefined,
  91. num_gpu: params.num_gpu !== null ? params.num_gpu : undefined,
  92. think: params.think !== null ? params.think : undefined,
  93. keep_alive: params.keep_alive !== null ? params.keep_alive : undefined,
  94. format: params.format !== null ? params.format : undefined
  95. }
  96. });
  97. dispatch('save');
  98. };
  99. onMount(async () => {
  100. selectedTheme = localStorage.theme ?? 'system';
  101. languages = await getLanguages();
  102. notificationEnabled = $settings.notificationEnabled ?? false;
  103. system = $settings.system ?? '';
  104. params = { ...params, ...$settings.params };
  105. params.stop = $settings?.params?.stop ? ($settings?.params?.stop ?? []).join(',') : null;
  106. });
  107. const applyTheme = (_theme: string) => {
  108. let themeToApply = _theme === 'oled-dark' ? 'dark' : _theme === 'her' ? 'light' : _theme;
  109. if (_theme === 'system') {
  110. themeToApply = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
  111. }
  112. if (themeToApply === 'dark' && !_theme.includes('oled')) {
  113. document.documentElement.style.setProperty('--color-gray-800', '#333');
  114. document.documentElement.style.setProperty('--color-gray-850', '#262626');
  115. document.documentElement.style.setProperty('--color-gray-900', '#171717');
  116. document.documentElement.style.setProperty('--color-gray-950', '#0d0d0d');
  117. }
  118. themes
  119. .filter((e) => e !== themeToApply)
  120. .forEach((e) => {
  121. e.split(' ').forEach((e) => {
  122. document.documentElement.classList.remove(e);
  123. });
  124. });
  125. themeToApply.split(' ').forEach((e) => {
  126. document.documentElement.classList.add(e);
  127. });
  128. const metaThemeColor = document.querySelector('meta[name="theme-color"]');
  129. if (metaThemeColor) {
  130. if (_theme.includes('system')) {
  131. const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
  132. ? 'dark'
  133. : 'light';
  134. console.log('Setting system meta theme color: ' + systemTheme);
  135. metaThemeColor.setAttribute('content', systemTheme === 'light' ? '#ffffff' : '#171717');
  136. } else {
  137. console.log('Setting meta theme color: ' + _theme);
  138. metaThemeColor.setAttribute(
  139. 'content',
  140. _theme === 'dark'
  141. ? '#171717'
  142. : _theme === 'oled-dark'
  143. ? '#000000'
  144. : _theme === 'her'
  145. ? '#983724'
  146. : '#ffffff'
  147. );
  148. }
  149. }
  150. if (typeof window !== 'undefined' && window.applyTheme) {
  151. window.applyTheme();
  152. }
  153. if (_theme.includes('oled')) {
  154. document.documentElement.style.setProperty('--color-gray-800', '#101010');
  155. document.documentElement.style.setProperty('--color-gray-850', '#050505');
  156. document.documentElement.style.setProperty('--color-gray-900', '#000000');
  157. document.documentElement.style.setProperty('--color-gray-950', '#000000');
  158. document.documentElement.classList.add('dark');
  159. }
  160. console.log(_theme);
  161. };
  162. const themeChangeHandler = (_theme: string) => {
  163. theme.set(_theme);
  164. localStorage.setItem('theme', _theme);
  165. applyTheme(_theme);
  166. };
  167. </script>
  168. <div class="flex flex-col h-full justify-between text-sm" id="tab-general">
  169. <div class=" overflow-y-scroll max-h-[28rem] md:max-h-full">
  170. <div class="">
  171. <div class=" mb-1 text-sm font-medium">{$i18n.t('WebUI Settings')}</div>
  172. <div class="flex w-full justify-between">
  173. <div class=" self-center text-xs font-medium">{$i18n.t('Theme')}</div>
  174. <div class="flex items-center relative">
  175. <select
  176. class="dark:bg-gray-900 w-fit pr-8 rounded-sm py-2 px-2 text-xs bg-transparent text-right {$settings.highContrastMode
  177. ? ''
  178. : 'outline-hidden'}"
  179. bind:value={selectedTheme}
  180. placeholder={$i18n.t('Select a theme')}
  181. on:change={() => themeChangeHandler(selectedTheme)}
  182. >
  183. <option value="system">⚙️ {$i18n.t('System')}</option>
  184. <option value="dark">🌑 {$i18n.t('Dark')}</option>
  185. <option value="oled-dark">🌃 {$i18n.t('OLED Dark')}</option>
  186. <option value="light">☀️ {$i18n.t('Light')}</option>
  187. <option value="her">🌷 Her</option>
  188. <!-- <option value="rose-pine dark">🪻 {$i18n.t('Rosé Pine')}</option>
  189. <option value="rose-pine-dawn light">🌷 {$i18n.t('Rosé Pine Dawn')}</option> -->
  190. </select>
  191. </div>
  192. </div>
  193. <div class=" flex w-full justify-between">
  194. <div class=" self-center text-xs font-medium">{$i18n.t('Language')}</div>
  195. <div class="flex items-center relative">
  196. <select
  197. class="dark:bg-gray-900 w-fit pr-8 rounded-sm py-2 px-2 text-xs bg-transparent text-right {$settings.highContrastMode
  198. ? ''
  199. : 'outline-hidden'}"
  200. bind:value={lang}
  201. placeholder={$i18n.t('Select a language')}
  202. on:change={(e) => {
  203. changeLanguage(lang);
  204. }}
  205. >
  206. {#each languages as language}
  207. <option value={language['code']}>{language['title']}</option>
  208. {/each}
  209. </select>
  210. </div>
  211. </div>
  212. {#if $i18n.language === 'en-US' && !($config?.license_metadata ?? false)}
  213. <div
  214. class="mb-2 text-xs {($settings?.highContrastMode ?? false)
  215. ? 'text-gray-800 dark:text-gray-100'
  216. : 'text-gray-400 dark:text-gray-500'}"
  217. >
  218. Couldn't find your language?
  219. <a
  220. class="font-medium underline {($settings?.highContrastMode ?? false)
  221. ? 'text-gray-700 dark:text-gray-200'
  222. : 'text-gray-300'}"
  223. href="https://github.com/open-webui/open-webui/blob/main/docs/CONTRIBUTING.md#-translations-and-internationalization"
  224. target="_blank"
  225. >
  226. Help us translate Open WebUI!
  227. </a>
  228. </div>
  229. {/if}
  230. <div>
  231. <div class=" py-0.5 flex w-full justify-between">
  232. <div class=" self-center text-xs font-medium">{$i18n.t('Notifications')}</div>
  233. <button
  234. class="p-1 px-3 text-xs flex rounded-sm transition"
  235. on:click={() => {
  236. toggleNotification();
  237. }}
  238. type="button"
  239. >
  240. {#if notificationEnabled === true}
  241. <span class="ml-2 self-center">{$i18n.t('On')}</span>
  242. {:else}
  243. <span class="ml-2 self-center">{$i18n.t('Off')}</span>
  244. {/if}
  245. </button>
  246. </div>
  247. </div>
  248. </div>
  249. {#if $user?.role === 'admin' || ($user?.permissions.chat?.system_prompt ?? true)}
  250. <hr class="border-gray-100/50 dark:border-gray-850 my-3" />
  251. <div>
  252. <div class=" my-2.5 text-sm font-medium">{$i18n.t('System Prompt')}</div>
  253. <Textarea
  254. bind:value={system}
  255. className={'w-full text-sm outline-hidden resize-vertical' +
  256. ($settings.highContrastMode
  257. ? ' p-2.5 border-2 border-gray-300 dark:border-gray-700 rounded-lg bg-transparent text-gray-900 dark:text-gray-100 focus:ring-1 focus:ring-blue-500 focus:border-blue-500 overflow-y-hidden'
  258. : ' dark:text-gray-300 ')}
  259. rows="4"
  260. placeholder={$i18n.t('Enter system prompt here')}
  261. />
  262. </div>
  263. {/if}
  264. {#if $user?.role === 'admin' || ($user?.permissions.chat?.controls ?? true)}
  265. <div class="mt-2 space-y-3 pr-1.5">
  266. <div class="flex justify-between items-center text-sm">
  267. <div class=" font-medium">{$i18n.t('Advanced Parameters')}</div>
  268. <button
  269. class=" text-xs font-medium {($settings?.highContrastMode ?? false)
  270. ? 'text-gray-800 dark:text-gray-100'
  271. : 'text-gray-400 dark:text-gray-500'}"
  272. type="button"
  273. on:click={() => {
  274. showAdvanced = !showAdvanced;
  275. }}>{showAdvanced ? $i18n.t('Hide') : $i18n.t('Show')}</button
  276. >
  277. </div>
  278. {#if showAdvanced}
  279. <AdvancedParams admin={$user?.role === 'admin'} bind:params />
  280. {/if}
  281. </div>
  282. {/if}
  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. saveHandler();
  289. }}
  290. >
  291. {$i18n.t('Save')}
  292. </button>
  293. </div>
  294. </div>