General.svelte 11 KB

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