General.svelte 11 KB

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