General.svelte 10 KB

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