General.svelte 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <script lang="ts">
  2. import { toast } from 'svelte-sonner';
  3. import { createEventDispatcher, onMount, getContext } from 'svelte';
  4. const dispatch = createEventDispatcher();
  5. import { models, user } from '$lib/stores';
  6. const i18n = getContext('i18n');
  7. import AdvancedParams from './Advanced/AdvancedParams.svelte';
  8. export let saveSettings: Function;
  9. export let getModels: Function;
  10. // General
  11. let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light'];
  12. let theme = 'dark';
  13. // TODO: Get these dynamically from the i18n module
  14. let languages = ['en', 'fa', 'fr', 'de'];
  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. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  59. theme = localStorage.theme ?? 'dark';
  60. notificationEnabled = settings.notificationEnabled ?? false;
  61. system = settings.system ?? '';
  62. requestFormat = settings.requestFormat ?? '';
  63. keepAlive = settings.keepAlive ?? null;
  64. options.seed = settings.seed ?? 0;
  65. options.temperature = settings.temperature ?? '';
  66. options.repeat_penalty = settings.repeat_penalty ?? '';
  67. options.top_k = settings.top_k ?? '';
  68. options.top_p = settings.top_p ?? '';
  69. options.num_ctx = settings.num_ctx ?? '';
  70. options = { ...options, ...settings.options };
  71. options.stop = (settings?.options?.stop ?? []).join(',');
  72. });
  73. </script>
  74. <div class="flex flex-col h-full justify-between text-sm">
  75. <div class=" pr-1.5 overflow-y-scroll max-h-[20.5rem]">
  76. <div class="">
  77. <div class=" mb-1 text-sm font-medium">WebUI Settings</div>
  78. <div class=" py-0.5 flex w-full justify-between">
  79. <div class=" self-center text-xs font-medium">Theme</div>
  80. <div class="flex items-center relative">
  81. <div class=" absolute right-16">
  82. {#if theme === 'dark'}
  83. <svg
  84. xmlns="http://www.w3.org/2000/svg"
  85. viewBox="0 0 20 20"
  86. fill="currentColor"
  87. class="w-4 h-4"
  88. >
  89. <path
  90. fill-rule="evenodd"
  91. 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"
  92. clip-rule="evenodd"
  93. />
  94. </svg>
  95. {:else if theme === 'light'}
  96. <svg
  97. xmlns="http://www.w3.org/2000/svg"
  98. viewBox="0 0 20 20"
  99. fill="currentColor"
  100. class="w-4 h-4 self-center"
  101. >
  102. <path
  103. 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"
  104. />
  105. </svg>
  106. {/if}
  107. </div>
  108. <select
  109. class="w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
  110. bind:value={theme}
  111. placeholder="Select a theme"
  112. on:change={(e) => {
  113. localStorage.theme = theme;
  114. themes
  115. .filter((e) => e !== theme)
  116. .forEach((e) => {
  117. e.split(' ').forEach((e) => {
  118. document.documentElement.classList.remove(e);
  119. });
  120. });
  121. theme.split(' ').forEach((e) => {
  122. document.documentElement.classList.add(e);
  123. });
  124. console.log(theme);
  125. }}
  126. >
  127. <option value="dark">Dark</option>
  128. <option value="light">Light</option>
  129. <option value="rose-pine dark">Rosé Pine</option>
  130. <option value="rose-pine-dawn light">Rosé Pine Dawn</option>
  131. </select>
  132. </div>
  133. </div>
  134. <div class=" py-0.5 flex w-full justify-between">
  135. <div class=" self-center text-xs font-medium">Language</div>
  136. <div class="flex items-center relative">
  137. <select
  138. class="w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
  139. bind:value={lang}
  140. placeholder="Select a language"
  141. on:change={(e) => {
  142. console.log($i18n);
  143. $i18n.changeLanguage(lang);
  144. }}
  145. >
  146. {#each languages as value}
  147. <option {value}>{value}</option>
  148. {/each}
  149. </select>
  150. </div>
  151. </div>
  152. <div>
  153. <div class=" py-0.5 flex w-full justify-between">
  154. <div class=" self-center text-xs font-medium">Notification</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">On</span>
  164. {:else}
  165. <span class="ml-2 self-center">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">System Prompt</div>
  174. <textarea
  175. bind:value={system}
  176. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 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">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 ? 'Hide' : '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">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"> Default </span>
  206. {:else}
  207. <span class="ml-2 self-center"> 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={`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">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"> 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"> 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-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  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. Save
  279. </button>
  280. </div>
  281. </div>