General.svelte 11 KB

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