SettingsModal.svelte 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. <script lang="ts">
  2. import sha256 from 'js-sha256';
  3. import Modal from '../common/Modal.svelte';
  4. import { WEB_UI_VERSION, API_BASE_URL as BUILD_TIME_API_BASE_URL } from '$lib/constants';
  5. import toast from 'svelte-french-toast';
  6. import { onMount } from 'svelte';
  7. export let show = false;
  8. export let saveSettings: Function;
  9. export let getModelTags: Function;
  10. let selectedTab = 'general';
  11. // General
  12. let API_BASE_URL = BUILD_TIME_API_BASE_URL;
  13. let theme = 'dark';
  14. let system = '';
  15. // Advanced
  16. let requestFormat = '';
  17. let seed = 0;
  18. let temperature = 0.8;
  19. let repeat_penalty = 1.1;
  20. let top_k = 40;
  21. let top_p = 0.9;
  22. // Models
  23. let modelTag = '';
  24. let deleteModelTag = '';
  25. let digest = '';
  26. let pullProgress = null;
  27. // Addons
  28. let speechAutoSend = false;
  29. let gravatarEmail = '';
  30. let OPENAI_API_KEY = '';
  31. // Auth
  32. let authEnabled = false;
  33. let authType = 'Basic';
  34. let authContent = '';
  35. function getGravatarURL(email) {
  36. // Trim leading and trailing whitespace from
  37. // an email address and force all characters
  38. // to lower case
  39. const address = String(email).trim().toLowerCase();
  40. // Create a SHA256 hash of the final string
  41. const hash = sha256(address);
  42. // Grab the actual image URL
  43. return `https://www.gravatar.com/avatar/${hash}`;
  44. }
  45. const splitStream = (splitOn) => {
  46. let buffer = '';
  47. return new TransformStream({
  48. transform(chunk, controller) {
  49. buffer += chunk;
  50. const parts = buffer.split(splitOn);
  51. parts.slice(0, -1).forEach((part) => controller.enqueue(part));
  52. buffer = parts[parts.length - 1];
  53. },
  54. flush(controller) {
  55. if (buffer) controller.enqueue(buffer);
  56. }
  57. });
  58. };
  59. const checkOllamaConnection = async () => {
  60. if (API_BASE_URL === '') {
  61. API_BASE_URL = BUILD_TIME_API_BASE_URL;
  62. }
  63. const res = await getModelTags(API_BASE_URL, 'ollama');
  64. if (res) {
  65. toast.success('Server connection verified');
  66. saveSettings({
  67. API_BASE_URL: API_BASE_URL
  68. });
  69. }
  70. };
  71. const toggleTheme = async () => {
  72. if (theme === 'dark') {
  73. theme = 'light';
  74. } else {
  75. theme = 'dark';
  76. }
  77. localStorage.theme = theme;
  78. document.documentElement.classList.remove(theme === 'dark' ? 'light' : 'dark');
  79. document.documentElement.classList.add(theme);
  80. };
  81. const toggleRequestFormat = async () => {
  82. if (requestFormat === '') {
  83. requestFormat = 'json';
  84. } else {
  85. requestFormat = '';
  86. }
  87. saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
  88. };
  89. const toggleSpeechAutoSend = async () => {
  90. speechAutoSend = !speechAutoSend;
  91. saveSettings({ speechAutoSend: speechAutoSend });
  92. };
  93. const toggleAuthHeader = async () => {
  94. authEnabled = !authEnabled;
  95. };
  96. const pullModelHandler = async () => {
  97. const res = await fetch(`${API_BASE_URL}/pull`, {
  98. method: 'POST',
  99. headers: {
  100. 'Content-Type': 'text/event-stream'
  101. },
  102. body: JSON.stringify({
  103. name: modelTag
  104. })
  105. });
  106. const reader = res.body
  107. .pipeThrough(new TextDecoderStream())
  108. .pipeThrough(splitStream('\n'))
  109. .getReader();
  110. while (true) {
  111. const { value, done } = await reader.read();
  112. if (done) break;
  113. try {
  114. let lines = value.split('\n');
  115. for (const line of lines) {
  116. if (line !== '') {
  117. console.log(line);
  118. let data = JSON.parse(line);
  119. console.log(data);
  120. if (data.error) {
  121. throw data.error;
  122. }
  123. if (data.status) {
  124. if (!data.status.includes('downloading')) {
  125. toast.success(data.status);
  126. } else {
  127. digest = data.digest;
  128. if (data.completed) {
  129. pullProgress = Math.round((data.completed / data.total) * 1000) / 10;
  130. } else {
  131. pullProgress = 100;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. } catch (error) {
  138. console.log(error);
  139. toast.error(error);
  140. }
  141. }
  142. modelTag = '';
  143. await getModelTags();
  144. };
  145. const deleteModelHandler = async () => {
  146. const res = await fetch(`${API_BASE_URL}/delete`, {
  147. method: 'DELETE',
  148. headers: {
  149. 'Content-Type': 'text/event-stream'
  150. },
  151. body: JSON.stringify({
  152. name: deleteModelTag
  153. })
  154. });
  155. const reader = res.body
  156. .pipeThrough(new TextDecoderStream())
  157. .pipeThrough(splitStream('\n'))
  158. .getReader();
  159. while (true) {
  160. const { value, done } = await reader.read();
  161. if (done) break;
  162. try {
  163. let lines = value.split('\n');
  164. for (const line of lines) {
  165. if (line !== '' && line !== 'null') {
  166. console.log(line);
  167. let data = JSON.parse(line);
  168. console.log(data);
  169. if (data.error) {
  170. throw data.error;
  171. }
  172. if (data.status) {
  173. }
  174. } else {
  175. toast.success(`Deleted ${deleteModelTag}`);
  176. }
  177. }
  178. } catch (error) {
  179. console.log(error);
  180. toast.error(error);
  181. }
  182. }
  183. deleteModelTag = '';
  184. await getModelTags();
  185. };
  186. $: if (show) {
  187. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  188. console.log(settings);
  189. theme = localStorage.theme ?? 'dark';
  190. API_BASE_URL = settings.API_BASE_URL ?? BUILD_TIME_API_BASE_URL;
  191. system = settings.system ?? '';
  192. requestFormat = settings.requestFormat ?? '';
  193. seed = settings.seed ?? 0;
  194. temperature = settings.temperature ?? 0.8;
  195. repeat_penalty = settings.repeat_penalty ?? 1.1;
  196. top_k = settings.top_k ?? 40;
  197. top_p = settings.top_p ?? 0.9;
  198. speechAutoSend = settings.speechAutoSend ?? false;
  199. gravatarEmail = settings.gravatarEmail ?? '';
  200. OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
  201. }
  202. onMount(() => {
  203. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  204. authEnabled = settings.authHeader !== undefined ? true : false;
  205. if (authEnabled) {
  206. authType = settings.authHeader.split(' ')[0];
  207. authContent = settings.authHeader.split(' ')[1];
  208. }
  209. });
  210. </script>
  211. <Modal bind:show>
  212. <div>
  213. <div class=" flex justify-between dark:text-gray-300 px-5 py-4">
  214. <div class=" text-lg font-medium self-center">Settings</div>
  215. <button
  216. class="self-center"
  217. on:click={() => {
  218. show = false;
  219. }}
  220. >
  221. <svg
  222. xmlns="http://www.w3.org/2000/svg"
  223. viewBox="0 0 20 20"
  224. fill="currentColor"
  225. class="w-5 h-5"
  226. >
  227. <path
  228. d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
  229. />
  230. </svg>
  231. </button>
  232. </div>
  233. <hr class=" dark:border-gray-800" />
  234. <div class="flex flex-col md:flex-row w-full p-4 md:space-x-4">
  235. <div
  236. class="tabs flex flex-row overflow-x-auto space-x-1 md:space-x-0 md:space-y-1 md:flex-col flex-1 md:flex-none md:w-40 dark:text-gray-200 text-xs text-left mb-3 md:mb-0"
  237. >
  238. <button
  239. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  240. 'general'
  241. ? 'bg-gray-200 dark:bg-gray-700'
  242. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  243. on:click={() => {
  244. selectedTab = 'general';
  245. }}
  246. >
  247. <div class=" self-center mr-2">
  248. <svg
  249. xmlns="http://www.w3.org/2000/svg"
  250. viewBox="0 0 20 20"
  251. fill="currentColor"
  252. class="w-4 h-4"
  253. >
  254. <path
  255. fill-rule="evenodd"
  256. d="M8.34 1.804A1 1 0 019.32 1h1.36a1 1 0 01.98.804l.295 1.473c.497.144.971.342 1.416.587l1.25-.834a1 1 0 011.262.125l.962.962a1 1 0 01.125 1.262l-.834 1.25c.245.445.443.919.587 1.416l1.473.294a1 1 0 01.804.98v1.361a1 1 0 01-.804.98l-1.473.295a6.95 6.95 0 01-.587 1.416l.834 1.25a1 1 0 01-.125 1.262l-.962.962a1 1 0 01-1.262.125l-1.25-.834a6.953 6.953 0 01-1.416.587l-.294 1.473a1 1 0 01-.98.804H9.32a1 1 0 01-.98-.804l-.295-1.473a6.957 6.957 0 01-1.416-.587l-1.25.834a1 1 0 01-1.262-.125l-.962-.962a1 1 0 01-.125-1.262l.834-1.25a6.957 6.957 0 01-.587-1.416l-1.473-.294A1 1 0 011 10.68V9.32a1 1 0 01.804-.98l1.473-.295c.144-.497.342-.971.587-1.416l-.834-1.25a1 1 0 01.125-1.262l.962-.962A1 1 0 015.38 3.03l1.25.834a6.957 6.957 0 011.416-.587l.294-1.473zM13 10a3 3 0 11-6 0 3 3 0 016 0z"
  257. clip-rule="evenodd"
  258. />
  259. </svg>
  260. </div>
  261. <div class=" self-center">General</div>
  262. </button>
  263. <button
  264. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  265. 'advanced'
  266. ? 'bg-gray-200 dark:bg-gray-700'
  267. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  268. on:click={() => {
  269. selectedTab = 'advanced';
  270. }}
  271. >
  272. <div class=" self-center mr-2">
  273. <svg
  274. xmlns="http://www.w3.org/2000/svg"
  275. viewBox="0 0 20 20"
  276. fill="currentColor"
  277. class="w-4 h-4"
  278. >
  279. <path
  280. d="M17 2.75a.75.75 0 00-1.5 0v5.5a.75.75 0 001.5 0v-5.5zM17 15.75a.75.75 0 00-1.5 0v1.5a.75.75 0 001.5 0v-1.5zM3.75 15a.75.75 0 01.75.75v1.5a.75.75 0 01-1.5 0v-1.5a.75.75 0 01.75-.75zM4.5 2.75a.75.75 0 00-1.5 0v5.5a.75.75 0 001.5 0v-5.5zM10 11a.75.75 0 01.75.75v5.5a.75.75 0 01-1.5 0v-5.5A.75.75 0 0110 11zM10.75 2.75a.75.75 0 00-1.5 0v1.5a.75.75 0 001.5 0v-1.5zM10 6a2 2 0 100 4 2 2 0 000-4zM3.75 10a2 2 0 100 4 2 2 0 000-4zM16.25 10a2 2 0 100 4 2 2 0 000-4z"
  281. />
  282. </svg>
  283. </div>
  284. <div class=" self-center">Advanced</div>
  285. </button>
  286. <button
  287. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  288. 'models'
  289. ? 'bg-gray-200 dark:bg-gray-700'
  290. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  291. on:click={() => {
  292. selectedTab = 'models';
  293. }}
  294. >
  295. <div class=" self-center mr-2">
  296. <svg
  297. xmlns="http://www.w3.org/2000/svg"
  298. viewBox="0 0 20 20"
  299. fill="currentColor"
  300. class="w-4 h-4"
  301. >
  302. <path
  303. fill-rule="evenodd"
  304. d="M10 1c3.866 0 7 1.79 7 4s-3.134 4-7 4-7-1.79-7-4 3.134-4 7-4zm5.694 8.13c.464-.264.91-.583 1.306-.952V10c0 2.21-3.134 4-7 4s-7-1.79-7-4V8.178c.396.37.842.688 1.306.953C5.838 10.006 7.854 10.5 10 10.5s4.162-.494 5.694-1.37zM3 13.179V15c0 2.21 3.134 4 7 4s7-1.79 7-4v-1.822c-.396.37-.842.688-1.306.953-1.532.875-3.548 1.369-5.694 1.369s-4.162-.494-5.694-1.37A7.009 7.009 0 013 13.179z"
  305. clip-rule="evenodd"
  306. />
  307. </svg>
  308. </div>
  309. <div class=" self-center">Models</div>
  310. </button>
  311. <button
  312. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  313. 'addons'
  314. ? 'bg-gray-200 dark:bg-gray-700'
  315. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  316. on:click={() => {
  317. selectedTab = 'addons';
  318. }}
  319. >
  320. <div class=" self-center mr-2">
  321. <svg
  322. xmlns="http://www.w3.org/2000/svg"
  323. viewBox="0 0 20 20"
  324. fill="currentColor"
  325. class="w-4 h-4"
  326. >
  327. <path
  328. d="M12 4.467c0-.405.262-.75.559-1.027.276-.257.441-.584.441-.94 0-.828-.895-1.5-2-1.5s-2 .672-2 1.5c0 .362.171.694.456.953.29.265.544.6.544.994a.968.968 0 01-1.024.974 39.655 39.655 0 01-3.014-.306.75.75 0 00-.847.847c.14.993.242 1.999.306 3.014A.968.968 0 014.447 10c-.393 0-.729-.253-.994-.544C3.194 9.17 2.862 9 2.5 9 1.672 9 1 9.895 1 11s.672 2 1.5 2c.356 0 .683-.165.94-.441.276-.297.622-.559 1.027-.559a.997.997 0 011.004 1.03 39.747 39.747 0 01-.319 3.734.75.75 0 00.64.842c1.05.146 2.111.252 3.184.318A.97.97 0 0010 16.948c0-.394-.254-.73-.545-.995C9.171 15.693 9 15.362 9 15c0-.828.895-1.5 2-1.5s2 .672 2 1.5c0 .356-.165.683-.441.94-.297.276-.559.622-.559 1.027a.998.998 0 001.03 1.005c1.337-.05 2.659-.162 3.961-.337a.75.75 0 00.644-.644c.175-1.302.288-2.624.337-3.961A.998.998 0 0016.967 12c-.405 0-.75.262-1.027.559-.257.276-.584.441-.94.441-.828 0-1.5-.895-1.5-2s.672-2 1.5-2c.362 0 .694.17.953.455.265.291.601.545.995.545a.97.97 0 00.976-1.024 41.159 41.159 0 00-.318-3.184.75.75 0 00-.842-.64c-1.228.164-2.473.271-3.734.319A.997.997 0 0112 4.467z"
  329. />
  330. </svg>
  331. </div>
  332. <div class=" self-center">Add-ons</div>
  333. </button>
  334. <button
  335. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  336. 'auth'
  337. ? 'bg-gray-200 dark:bg-gray-700'
  338. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  339. on:click={() => {
  340. selectedTab = 'auth';
  341. }}
  342. >
  343. <div class=" self-center mr-2">
  344. <svg
  345. xmlns="http://www.w3.org/2000/svg"
  346. viewBox="0 0 24 24"
  347. fill="currentColor"
  348. class="w-4 h-4"
  349. >
  350. <path
  351. fill-rule="evenodd"
  352. d="M12.516 2.17a.75.75 0 00-1.032 0 11.209 11.209 0 01-7.877 3.08.75.75 0 00-.722.515A12.74 12.74 0 002.25 9.75c0 5.942 4.064 10.933 9.563 12.348a.749.749 0 00.374 0c5.499-1.415 9.563-6.406 9.563-12.348 0-1.39-.223-2.73-.635-3.985a.75.75 0 00-.722-.516l-.143.001c-2.996 0-5.717-1.17-7.734-3.08zm3.094 8.016a.75.75 0 10-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.14-.094l3.75-5.25z"
  353. clip-rule="evenodd"
  354. />
  355. </svg>
  356. </div>
  357. <div class=" self-center">Authentication</div>
  358. </button>
  359. <button
  360. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  361. 'about'
  362. ? 'bg-gray-200 dark:bg-gray-700'
  363. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  364. on:click={() => {
  365. selectedTab = 'about';
  366. }}
  367. >
  368. <div class=" self-center mr-2">
  369. <svg
  370. xmlns="http://www.w3.org/2000/svg"
  371. viewBox="0 0 20 20"
  372. fill="currentColor"
  373. class="w-4 h-4"
  374. >
  375. <path
  376. fill-rule="evenodd"
  377. d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a.75.75 0 000 1.5h.253a.25.25 0 01.244.304l-.459 2.066A1.75 1.75 0 0010.747 15H11a.75.75 0 000-1.5h-.253a.25.25 0 01-.244-.304l.459-2.066A1.75 1.75 0 009.253 9H9z"
  378. clip-rule="evenodd"
  379. />
  380. </svg>
  381. </div>
  382. <div class=" self-center">About</div>
  383. </button>
  384. </div>
  385. <div class="flex-1 md:min-h-[330px]">
  386. {#if selectedTab === 'general'}
  387. <div class="flex flex-col space-y-3">
  388. <div>
  389. <div class=" py-1 flex w-full justify-between">
  390. <div class=" self-center text-sm font-medium">Theme</div>
  391. <button
  392. class="p-1 px-3 text-xs flex rounded transition"
  393. on:click={() => {
  394. toggleTheme();
  395. }}
  396. >
  397. {#if theme === 'dark'}
  398. <svg
  399. xmlns="http://www.w3.org/2000/svg"
  400. viewBox="0 0 20 20"
  401. fill="currentColor"
  402. class="w-4 h-4"
  403. >
  404. <path
  405. fill-rule="evenodd"
  406. 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"
  407. clip-rule="evenodd"
  408. />
  409. </svg>
  410. <span class="ml-2 self-center"> Dark </span>
  411. {:else}
  412. <svg
  413. xmlns="http://www.w3.org/2000/svg"
  414. viewBox="0 0 20 20"
  415. fill="currentColor"
  416. class="w-4 h-4 self-center"
  417. >
  418. <path
  419. 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"
  420. />
  421. </svg>
  422. <span class="ml-2 self-center"> Light </span>
  423. {/if}
  424. </button>
  425. </div>
  426. </div>
  427. <hr class=" dark:border-gray-700" />
  428. <div>
  429. <div class=" mb-2.5 text-sm font-medium">Ollama Server URL</div>
  430. <div class="flex w-full">
  431. <div class="flex-1 mr-2">
  432. <input
  433. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  434. placeholder="Enter URL (e.g. http://localhost:11434/api)"
  435. bind:value={API_BASE_URL}
  436. />
  437. </div>
  438. <button
  439. class="px-3 bg-gray-200 hover:bg-gray-300 dark:bg-gray-600 dark:hover:bg-gray-700 rounded transition"
  440. on:click={() => {
  441. checkOllamaConnection();
  442. }}
  443. >
  444. <svg
  445. xmlns="http://www.w3.org/2000/svg"
  446. viewBox="0 0 20 20"
  447. fill="currentColor"
  448. class="w-4 h-4"
  449. >
  450. <path
  451. fill-rule="evenodd"
  452. d="M15.312 11.424a5.5 5.5 0 01-9.201 2.466l-.312-.311h2.433a.75.75 0 000-1.5H3.989a.75.75 0 00-.75.75v4.242a.75.75 0 001.5 0v-2.43l.31.31a7 7 0 0011.712-3.138.75.75 0 00-1.449-.39zm1.23-3.723a.75.75 0 00.219-.53V2.929a.75.75 0 00-1.5 0V5.36l-.31-.31A7 7 0 003.239 8.188a.75.75 0 101.448.389A5.5 5.5 0 0113.89 6.11l.311.31h-2.432a.75.75 0 000 1.5h4.243a.75.75 0 00.53-.219z"
  453. clip-rule="evenodd"
  454. />
  455. </svg>
  456. </button>
  457. </div>
  458. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  459. Trouble accessing Ollama? <a
  460. class=" text-gray-500 dark:text-gray-300 font-medium"
  461. href="https://github.com/ollama-webui/ollama-webui#troubleshooting"
  462. target="_blank"
  463. >
  464. Click here for help.
  465. </a>
  466. </div>
  467. </div>
  468. <hr class=" dark:border-gray-700" />
  469. <div>
  470. <div class=" mb-2.5 text-sm font-medium">System Prompt</div>
  471. <textarea
  472. bind:value={system}
  473. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  474. rows="4"
  475. />
  476. </div>
  477. <div class="flex justify-end pt-3 text-sm font-medium">
  478. <button
  479. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  480. on:click={() => {
  481. saveSettings({
  482. API_BASE_URL: API_BASE_URL === '' ? BUILD_TIME_API_BASE_URL : API_BASE_URL,
  483. system: system !== '' ? system : undefined
  484. });
  485. show = false;
  486. }}
  487. >
  488. Save
  489. </button>
  490. </div>
  491. </div>
  492. {:else if selectedTab === 'advanced'}
  493. <div class="flex flex-col h-full justify-between space-y-3 text-sm">
  494. <div class=" space-y-3">
  495. <div>
  496. <div class=" py-1 flex w-full justify-between">
  497. <div class=" self-center text-sm font-medium">Request Mode</div>
  498. <button
  499. class="p-1 px-3 text-xs flex rounded transition"
  500. on:click={() => {
  501. toggleRequestFormat();
  502. }}
  503. >
  504. {#if requestFormat === ''}
  505. <span class="ml-2 self-center"> Default </span>
  506. {:else if requestFormat === 'json'}
  507. <!-- <svg
  508. xmlns="http://www.w3.org/2000/svg"
  509. viewBox="0 0 20 20"
  510. fill="currentColor"
  511. class="w-4 h-4 self-center"
  512. >
  513. <path
  514. 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"
  515. />
  516. </svg> -->
  517. <span class="ml-2 self-center"> JSON </span>
  518. {/if}
  519. </button>
  520. </div>
  521. </div>
  522. <hr class=" dark:border-gray-700" />
  523. <div>
  524. <div class=" py-1 flex w-full justify-between">
  525. <div class=" w-20 text-sm font-medium self-center">Seed</div>
  526. <div class=" flex-1 self-center">
  527. <input
  528. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  529. type="number"
  530. placeholder="Enter Seed"
  531. bind:value={seed}
  532. autocomplete="off"
  533. min="0"
  534. />
  535. </div>
  536. </div>
  537. </div>
  538. <hr class=" dark:border-gray-700" />
  539. <div>
  540. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  541. <div>Temperature</div>
  542. <div>
  543. {temperature}
  544. </div></label
  545. >
  546. <input
  547. id="steps-range"
  548. type="range"
  549. min="0"
  550. max="1"
  551. bind:value={temperature}
  552. step="0.05"
  553. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  554. />
  555. </div>
  556. <div>
  557. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  558. <div>Repeat Penalty</div>
  559. <div>
  560. {repeat_penalty}
  561. </div></label
  562. >
  563. <input
  564. id="steps-range"
  565. type="range"
  566. min="0"
  567. max="2"
  568. bind:value={repeat_penalty}
  569. step="0.05"
  570. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  571. />
  572. </div>
  573. <div>
  574. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  575. <div>Top K</div>
  576. <div>
  577. {top_k}
  578. </div></label
  579. >
  580. <input
  581. id="steps-range"
  582. type="range"
  583. min="0"
  584. max="100"
  585. bind:value={top_k}
  586. step="0.5"
  587. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  588. />
  589. </div>
  590. <div>
  591. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  592. <div>Top P</div>
  593. <div>
  594. {top_p}
  595. </div></label
  596. >
  597. <input
  598. id="steps-range"
  599. type="range"
  600. min="0"
  601. max="1"
  602. bind:value={top_p}
  603. step="0.05"
  604. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  605. />
  606. </div>
  607. </div>
  608. <div class="flex justify-end pt-3 text-sm font-medium">
  609. <button
  610. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  611. on:click={() => {
  612. saveSettings({
  613. seed: (seed !== 0 ? seed : undefined) ?? undefined,
  614. temperature: temperature !== 0.8 ? temperature : undefined,
  615. repeat_penalty: repeat_penalty !== 1.1 ? repeat_penalty : undefined,
  616. top_k: top_k !== 40 ? top_k : undefined,
  617. top_p: top_p !== 0.9 ? top_p : undefined
  618. });
  619. show = false;
  620. }}
  621. >
  622. Save
  623. </button>
  624. </div>
  625. </div>
  626. {:else if selectedTab === 'models'}
  627. <div class="flex flex-col space-y-3 text-sm mb-10">
  628. <div>
  629. <div class=" mb-2.5 text-sm font-medium">Pull a model</div>
  630. <div class="flex w-full">
  631. <div class="flex-1 mr-2">
  632. <input
  633. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  634. placeholder="Enter model tag (e.g. mistral:7b)"
  635. bind:value={modelTag}
  636. />
  637. </div>
  638. <button
  639. class="px-3 text-gray-100 bg-emerald-600 hover:bg-emerald-700 rounded transition"
  640. on:click={() => {
  641. pullModelHandler();
  642. }}
  643. >
  644. <svg
  645. xmlns="http://www.w3.org/2000/svg"
  646. viewBox="0 0 20 20"
  647. fill="currentColor"
  648. class="w-4 h-4"
  649. >
  650. <path
  651. d="M10.75 2.75a.75.75 0 00-1.5 0v8.614L6.295 8.235a.75.75 0 10-1.09 1.03l4.25 4.5a.75.75 0 001.09 0l4.25-4.5a.75.75 0 00-1.09-1.03l-2.955 3.129V2.75z"
  652. />
  653. <path
  654. d="M3.5 12.75a.75.75 0 00-1.5 0v2.5A2.75 2.75 0 004.75 18h10.5A2.75 2.75 0 0018 15.25v-2.5a.75.75 0 00-1.5 0v2.5c0 .69-.56 1.25-1.25 1.25H4.75c-.69 0-1.25-.56-1.25-1.25v-2.5z"
  655. />
  656. </svg>
  657. </button>
  658. </div>
  659. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  660. To access the available model names for downloading, <a
  661. class=" text-gray-500 dark:text-gray-300 font-medium"
  662. href="https://ollama.ai/library"
  663. target="_blank">click here.</a
  664. >
  665. </div>
  666. {#if pullProgress !== null}
  667. <div class="mt-2">
  668. <div class=" mb-2 text-xs">Pull Progress</div>
  669. <div class="w-full rounded-full dark:bg-gray-800">
  670. <div
  671. class="dark:bg-gray-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full"
  672. style="width: {Math.max(15, pullProgress ?? 0)}%"
  673. >
  674. {pullProgress ?? 0}%
  675. </div>
  676. </div>
  677. <div class="mt-1 text-xs dark:text-gray-700" style="font-size: 0.5rem;">
  678. {digest}
  679. </div>
  680. </div>
  681. {/if}
  682. </div>
  683. <hr class=" dark:border-gray-700" />
  684. <div>
  685. <div class=" mb-2.5 text-sm font-medium">Delete a model</div>
  686. <div class="flex w-full">
  687. <div class="flex-1 mr-2">
  688. <input
  689. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  690. placeholder="Enter model tag (e.g. mistral:7b)"
  691. bind:value={deleteModelTag}
  692. />
  693. </div>
  694. <button
  695. class="px-3 bg-red-700 hover:bg-red-800 text-gray-100 rounded transition"
  696. on:click={() => {
  697. deleteModelHandler();
  698. }}
  699. >
  700. <svg
  701. xmlns="http://www.w3.org/2000/svg"
  702. viewBox="0 0 20 20"
  703. fill="currentColor"
  704. class="w-4 h-4"
  705. >
  706. <path
  707. fill-rule="evenodd"
  708. d="M8.75 1A2.75 2.75 0 006 3.75v.443c-.795.077-1.584.176-2.365.298a.75.75 0 10.23 1.482l.149-.022.841 10.518A2.75 2.75 0 007.596 19h4.807a2.75 2.75 0 002.742-2.53l.841-10.52.149.023a.75.75 0 00.23-1.482A41.03 41.03 0 0014 4.193V3.75A2.75 2.75 0 0011.25 1h-2.5zM10 4c.84 0 1.673.025 2.5.075V3.75c0-.69-.56-1.25-1.25-1.25h-2.5c-.69 0-1.25.56-1.25 1.25v.325C8.327 4.025 9.16 4 10 4zM8.58 7.72a.75.75 0 00-1.5.06l.3 7.5a.75.75 0 101.5-.06l-.3-7.5zm4.34.06a.75.75 0 10-1.5-.06l-.3 7.5a.75.75 0 101.5.06l.3-7.5z"
  709. clip-rule="evenodd"
  710. />
  711. </svg>
  712. </button>
  713. </div>
  714. </div>
  715. </div>
  716. {:else if selectedTab === 'addons'}
  717. <form
  718. class="flex flex-col h-full justify-between space-y-3 text-sm"
  719. on:submit|preventDefault={() => {
  720. saveSettings({
  721. gravatarEmail: gravatarEmail !== '' ? gravatarEmail : undefined,
  722. gravatarUrl: gravatarEmail !== '' ? getGravatarURL(gravatarEmail) : undefined,
  723. OPENAI_API_KEY: OPENAI_API_KEY !== '' ? OPENAI_API_KEY : undefined
  724. });
  725. show = false;
  726. }}
  727. >
  728. <div class=" space-y-3">
  729. <div>
  730. <div class=" py-1 flex w-full justify-between">
  731. <div class=" self-center text-sm font-medium">Voice Input Auto-Send</div>
  732. <button
  733. class="p-1 px-3 text-xs flex rounded transition"
  734. on:click={() => {
  735. toggleSpeechAutoSend();
  736. }}
  737. type="button"
  738. >
  739. {#if speechAutoSend === true}
  740. <span class="ml-2 self-center">On</span>
  741. {:else}
  742. <span class="ml-2 self-center">Off</span>
  743. {/if}
  744. </button>
  745. </div>
  746. </div>
  747. <hr class=" dark:border-gray-700" />
  748. <div>
  749. <div class=" mb-2.5 text-sm font-medium">
  750. Gravatar Email <span class=" text-gray-400 text-sm">(optional)</span>
  751. </div>
  752. <div class="flex w-full">
  753. <div class="flex-1">
  754. <input
  755. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  756. placeholder="Enter Your Email"
  757. bind:value={gravatarEmail}
  758. autocomplete="off"
  759. type="email"
  760. />
  761. </div>
  762. </div>
  763. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  764. Changes user profile image to match your <a
  765. class=" text-gray-500 dark:text-gray-300 font-medium"
  766. href="https://gravatar.com/"
  767. target="_blank">Gravatar.</a
  768. >
  769. </div>
  770. </div>
  771. <hr class=" dark:border-gray-700" />
  772. <div>
  773. <div class=" mb-2.5 text-sm font-medium">
  774. OpenAI API Key <span class=" text-gray-400 text-sm">(optional)</span>
  775. </div>
  776. <div class="flex w-full">
  777. <div class="flex-1">
  778. <input
  779. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  780. placeholder="Enter OpenAI API Key"
  781. bind:value={OPENAI_API_KEY}
  782. autocomplete="off"
  783. />
  784. </div>
  785. </div>
  786. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  787. Adds optional support for 'gpt-*' models available.
  788. </div>
  789. </div>
  790. </div>
  791. <div class="flex justify-end pt-3 text-sm font-medium">
  792. <button
  793. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  794. type="submit"
  795. >
  796. Save
  797. </button>
  798. </div>
  799. </form>
  800. {:else if selectedTab === 'auth'}
  801. <form
  802. class="flex flex-col h-full justify-between space-y-3 text-sm"
  803. on:submit|preventDefault={() => {
  804. console.log('auth save');
  805. saveSettings({
  806. authHeader: authEnabled ? `${authType} ${authContent}` : undefined
  807. });
  808. show = false;
  809. }}
  810. >
  811. <div class=" space-y-3">
  812. <div>
  813. <div class=" py-1 flex w-full justify-between">
  814. <div class=" self-center text-sm font-medium">Authorization Header</div>
  815. <button
  816. class="p-1 px-3 text-xs flex rounded transition"
  817. type="button"
  818. on:click={() => {
  819. toggleAuthHeader();
  820. }}
  821. >
  822. {#if authEnabled === true}
  823. <svg
  824. xmlns="http://www.w3.org/2000/svg"
  825. viewBox="0 0 24 24"
  826. fill="currentColor"
  827. class="w-4 h-4"
  828. >
  829. <path
  830. fill-rule="evenodd"
  831. d="M12 1.5a5.25 5.25 0 00-5.25 5.25v3a3 3 0 00-3 3v6.75a3 3 0 003 3h10.5a3 3 0 003-3v-6.75a3 3 0 00-3-3v-3c0-2.9-2.35-5.25-5.25-5.25zm3.75 8.25v-3a3.75 3.75 0 10-7.5 0v3h7.5z"
  832. clip-rule="evenodd"
  833. />
  834. </svg>
  835. <span class="ml-2 self-center"> On </span>
  836. {:else}
  837. <svg
  838. xmlns="http://www.w3.org/2000/svg"
  839. viewBox="0 0 24 24"
  840. fill="currentColor"
  841. class="w-4 h-4"
  842. >
  843. <path
  844. d="M18 1.5c2.9 0 5.25 2.35 5.25 5.25v3.75a.75.75 0 01-1.5 0V6.75a3.75 3.75 0 10-7.5 0v3a3 3 0 013 3v6.75a3 3 0 01-3 3H3.75a3 3 0 01-3-3v-6.75a3 3 0 013-3h9v-3c0-2.9 2.35-5.25 5.25-5.25z"
  845. />
  846. </svg>
  847. <span class="ml-2 self-center">Off</span>
  848. {/if}
  849. </button>
  850. </div>
  851. </div>
  852. {#if authEnabled}
  853. <hr class=" dark:border-gray-700" />
  854. <div class="mt-2">
  855. <div class=" py-1 flex w-full space-x-2">
  856. <button
  857. class=" py-1 font-semibold flex rounded transition"
  858. on:click={() => {
  859. authType = authType === 'Basic' ? 'Bearer' : 'Basic';
  860. }}
  861. type="button"
  862. >
  863. {#if authType === 'Basic'}
  864. <span class="self-center mr-2">Basic</span>
  865. {:else if authType === 'Bearer'}
  866. <span class="self-center mr-2">Bearer</span>
  867. {/if}
  868. </button>
  869. <div class="flex-1">
  870. <input
  871. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  872. placeholder="Enter Authorization Header Content"
  873. bind:value={authContent}
  874. />
  875. </div>
  876. </div>
  877. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  878. Toggle between <span class=" text-gray-500 dark:text-gray-300 font-medium"
  879. >'Basic'</span
  880. >
  881. and <span class=" text-gray-500 dark:text-gray-300 font-medium">'Bearer'</span> by
  882. clicking on the label next to the input.
  883. </div>
  884. </div>
  885. <hr class=" dark:border-gray-700" />
  886. <div>
  887. <div class=" mb-2.5 text-sm font-medium">Preview Authorization Header</div>
  888. <textarea
  889. value={JSON.stringify({
  890. Authorization: `${authType} ${authContent}`
  891. })}
  892. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  893. rows="2"
  894. disabled
  895. />
  896. </div>
  897. {/if}
  898. </div>
  899. <div class="flex justify-end pt-3 text-sm font-medium">
  900. <button
  901. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  902. type="submit"
  903. >
  904. Save
  905. </button>
  906. </div>
  907. </form>
  908. {:else if selectedTab === 'about'}
  909. <div class="flex flex-col h-full justify-between space-y-3 text-sm mb-6">
  910. <div class=" space-y-3">
  911. <div>
  912. <div class=" mb-2.5 text-sm font-medium">Ollama Web UI Version</div>
  913. <div class="flex w-full">
  914. <div class="flex-1 text-xs text-gray-700 dark:text-gray-200">
  915. {WEB_UI_VERSION}
  916. </div>
  917. </div>
  918. </div>
  919. <hr class=" dark:border-gray-700" />
  920. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  921. Created by <a
  922. class=" text-gray-500 dark:text-gray-300 font-medium"
  923. href="https://github.com/tjbck"
  924. target="_blank">Timothy J. Baek</a
  925. >
  926. </div>
  927. <div>
  928. <a href="https://github.com/ollama-webui/ollama-webui">
  929. <img
  930. alt="Github Repo"
  931. src="https://img.shields.io/github/stars/ollama-webui/ollama-webui?style=social&label=Star us on Github"
  932. />
  933. </a>
  934. </div>
  935. </div>
  936. </div>
  937. {/if}
  938. </div>
  939. </div>
  940. </div>
  941. </Modal>
  942. <style>
  943. input::-webkit-outer-spin-button,
  944. input::-webkit-inner-spin-button {
  945. /* display: none; <- Crashes Chrome on hover */
  946. -webkit-appearance: none;
  947. margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
  948. }
  949. .tabs::-webkit-scrollbar {
  950. display: none; /* for Chrome, Safari and Opera */
  951. }
  952. .tabs {
  953. -ms-overflow-style: none; /* IE and Edge */
  954. scrollbar-width: none; /* Firefox */
  955. }
  956. input[type='number'] {
  957. -moz-appearance: textfield; /* Firefox */
  958. }
  959. </style>