SettingsModal.svelte 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049
  1. <script lang="ts">
  2. import sha256 from 'js-sha256';
  3. import Modal from '../common/Modal.svelte';
  4. import { WEB_UI_VERSION, OLLAMA_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. import { config, user } from '$lib/stores';
  8. export let show = false;
  9. export let saveSettings: Function;
  10. export let getModelTags: Function;
  11. let selectedTab = 'general';
  12. // General
  13. let API_BASE_URL = BUILD_TIME_API_BASE_URL;
  14. let theme = 'dark';
  15. let system = '';
  16. // Advanced
  17. let requestFormat = '';
  18. let seed = 0;
  19. let temperature = 0.8;
  20. let repeat_penalty = 1.1;
  21. let top_k = 40;
  22. let top_p = 0.9;
  23. // Models
  24. let modelTag = '';
  25. let deleteModelTag = '';
  26. let digest = '';
  27. let pullProgress = null;
  28. // Addons
  29. let speechAutoSend = false;
  30. let gravatarEmail = '';
  31. let OPENAI_API_KEY = '';
  32. // Auth
  33. let authEnabled = false;
  34. let authType = 'Basic';
  35. let authContent = '';
  36. function getGravatarURL(email) {
  37. // Trim leading and trailing whitespace from
  38. // an email address and force all characters
  39. // to lower case
  40. const address = String(email).trim().toLowerCase();
  41. // Create a SHA256 hash of the final string
  42. const hash = sha256(address);
  43. // Grab the actual image URL
  44. return `https://www.gravatar.com/avatar/${hash}`;
  45. }
  46. const splitStream = (splitOn) => {
  47. let buffer = '';
  48. return new TransformStream({
  49. transform(chunk, controller) {
  50. buffer += chunk;
  51. const parts = buffer.split(splitOn);
  52. parts.slice(0, -1).forEach((part) => controller.enqueue(part));
  53. buffer = parts[parts.length - 1];
  54. },
  55. flush(controller) {
  56. if (buffer) controller.enqueue(buffer);
  57. }
  58. });
  59. };
  60. const checkOllamaConnection = async () => {
  61. if (API_BASE_URL === '') {
  62. API_BASE_URL = BUILD_TIME_API_BASE_URL;
  63. }
  64. const res = await getModelTags(API_BASE_URL, 'ollama');
  65. if (res) {
  66. toast.success('Server connection verified');
  67. saveSettings({
  68. API_BASE_URL: API_BASE_URL
  69. });
  70. }
  71. };
  72. const toggleTheme = async () => {
  73. if (theme === 'dark') {
  74. theme = 'light';
  75. } else {
  76. theme = 'dark';
  77. }
  78. localStorage.theme = theme;
  79. document.documentElement.classList.remove(theme === 'dark' ? 'light' : 'dark');
  80. document.documentElement.classList.add(theme);
  81. };
  82. const toggleRequestFormat = async () => {
  83. if (requestFormat === '') {
  84. requestFormat = 'json';
  85. } else {
  86. requestFormat = '';
  87. }
  88. saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
  89. };
  90. const toggleSpeechAutoSend = async () => {
  91. speechAutoSend = !speechAutoSend;
  92. saveSettings({ speechAutoSend: speechAutoSend });
  93. };
  94. const toggleAuthHeader = async () => {
  95. authEnabled = !authEnabled;
  96. };
  97. const pullModelHandler = async () => {
  98. const res = await fetch(`${API_BASE_URL}/pull`, {
  99. method: 'POST',
  100. headers: {
  101. 'Content-Type': 'text/event-stream',
  102. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  103. },
  104. body: JSON.stringify({
  105. name: modelTag
  106. })
  107. });
  108. const reader = res.body
  109. .pipeThrough(new TextDecoderStream())
  110. .pipeThrough(splitStream('\n'))
  111. .getReader();
  112. while (true) {
  113. const { value, done } = await reader.read();
  114. if (done) break;
  115. try {
  116. let lines = value.split('\n');
  117. for (const line of lines) {
  118. if (line !== '') {
  119. console.log(line);
  120. let data = JSON.parse(line);
  121. console.log(data);
  122. if (data.error) {
  123. throw data.error;
  124. }
  125. if (data.status) {
  126. if (!data.status.includes('downloading')) {
  127. toast.success(data.status);
  128. } else {
  129. digest = data.digest;
  130. if (data.completed) {
  131. pullProgress = Math.round((data.completed / data.total) * 1000) / 10;
  132. } else {
  133. pullProgress = 100;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. } catch (error) {
  140. console.log(error);
  141. toast.error(error);
  142. }
  143. }
  144. modelTag = '';
  145. await getModelTags();
  146. };
  147. const deleteModelHandler = async () => {
  148. const res = await fetch(`${API_BASE_URL}/delete`, {
  149. method: 'DELETE',
  150. headers: {
  151. 'Content-Type': 'text/event-stream',
  152. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  153. },
  154. body: JSON.stringify({
  155. name: deleteModelTag
  156. })
  157. });
  158. const reader = res.body
  159. .pipeThrough(new TextDecoderStream())
  160. .pipeThrough(splitStream('\n'))
  161. .getReader();
  162. while (true) {
  163. const { value, done } = await reader.read();
  164. if (done) break;
  165. try {
  166. let lines = value.split('\n');
  167. for (const line of lines) {
  168. if (line !== '' && line !== 'null') {
  169. console.log(line);
  170. let data = JSON.parse(line);
  171. console.log(data);
  172. if (data.error) {
  173. throw data.error;
  174. }
  175. if (data.status) {
  176. }
  177. } else {
  178. toast.success(`Deleted ${deleteModelTag}`);
  179. }
  180. }
  181. } catch (error) {
  182. console.log(error);
  183. toast.error(error);
  184. }
  185. }
  186. deleteModelTag = '';
  187. await getModelTags();
  188. };
  189. $: if (show) {
  190. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  191. console.log(settings);
  192. theme = localStorage.theme ?? 'dark';
  193. API_BASE_URL = settings.API_BASE_URL ?? BUILD_TIME_API_BASE_URL;
  194. system = settings.system ?? '';
  195. requestFormat = settings.requestFormat ?? '';
  196. seed = settings.seed ?? 0;
  197. temperature = settings.temperature ?? 0.8;
  198. repeat_penalty = settings.repeat_penalty ?? 1.1;
  199. top_k = settings.top_k ?? 40;
  200. top_p = settings.top_p ?? 0.9;
  201. speechAutoSend = settings.speechAutoSend ?? false;
  202. gravatarEmail = settings.gravatarEmail ?? '';
  203. OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
  204. }
  205. onMount(() => {
  206. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  207. authEnabled = settings.authHeader !== undefined ? true : false;
  208. if (authEnabled) {
  209. authType = settings.authHeader.split(' ')[0];
  210. authContent = settings.authHeader.split(' ')[1];
  211. }
  212. });
  213. </script>
  214. <Modal bind:show>
  215. <div>
  216. <div class=" flex justify-between dark:text-gray-300 px-5 py-4">
  217. <div class=" text-lg font-medium self-center">Settings</div>
  218. <button
  219. class="self-center"
  220. on:click={() => {
  221. show = false;
  222. }}
  223. >
  224. <svg
  225. xmlns="http://www.w3.org/2000/svg"
  226. viewBox="0 0 20 20"
  227. fill="currentColor"
  228. class="w-5 h-5"
  229. >
  230. <path
  231. 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"
  232. />
  233. </svg>
  234. </button>
  235. </div>
  236. <hr class=" dark:border-gray-800" />
  237. <div class="flex flex-col md:flex-row w-full p-4 md:space-x-4">
  238. <div
  239. 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"
  240. >
  241. <button
  242. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  243. 'general'
  244. ? 'bg-gray-200 dark:bg-gray-700'
  245. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  246. on:click={() => {
  247. selectedTab = 'general';
  248. }}
  249. >
  250. <div class=" self-center mr-2">
  251. <svg
  252. xmlns="http://www.w3.org/2000/svg"
  253. viewBox="0 0 20 20"
  254. fill="currentColor"
  255. class="w-4 h-4"
  256. >
  257. <path
  258. fill-rule="evenodd"
  259. 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"
  260. clip-rule="evenodd"
  261. />
  262. </svg>
  263. </div>
  264. <div class=" self-center">General</div>
  265. </button>
  266. <button
  267. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  268. 'advanced'
  269. ? 'bg-gray-200 dark:bg-gray-700'
  270. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  271. on:click={() => {
  272. selectedTab = 'advanced';
  273. }}
  274. >
  275. <div class=" self-center mr-2">
  276. <svg
  277. xmlns="http://www.w3.org/2000/svg"
  278. viewBox="0 0 20 20"
  279. fill="currentColor"
  280. class="w-4 h-4"
  281. >
  282. <path
  283. 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"
  284. />
  285. </svg>
  286. </div>
  287. <div class=" self-center">Advanced</div>
  288. </button>
  289. <button
  290. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  291. 'models'
  292. ? 'bg-gray-200 dark:bg-gray-700'
  293. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  294. on:click={() => {
  295. selectedTab = 'models';
  296. }}
  297. >
  298. <div class=" self-center mr-2">
  299. <svg
  300. xmlns="http://www.w3.org/2000/svg"
  301. viewBox="0 0 20 20"
  302. fill="currentColor"
  303. class="w-4 h-4"
  304. >
  305. <path
  306. fill-rule="evenodd"
  307. 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"
  308. clip-rule="evenodd"
  309. />
  310. </svg>
  311. </div>
  312. <div class=" self-center">Models</div>
  313. </button>
  314. <button
  315. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  316. 'addons'
  317. ? 'bg-gray-200 dark:bg-gray-700'
  318. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  319. on:click={() => {
  320. selectedTab = 'addons';
  321. }}
  322. >
  323. <div class=" self-center mr-2">
  324. <svg
  325. xmlns="http://www.w3.org/2000/svg"
  326. viewBox="0 0 20 20"
  327. fill="currentColor"
  328. class="w-4 h-4"
  329. >
  330. <path
  331. 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"
  332. />
  333. </svg>
  334. </div>
  335. <div class=" self-center">Add-ons</div>
  336. </button>
  337. <button
  338. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  339. 'auth'
  340. ? 'bg-gray-200 dark:bg-gray-700'
  341. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  342. on:click={() => {
  343. selectedTab = 'auth';
  344. }}
  345. >
  346. <div class=" self-center mr-2">
  347. <svg
  348. xmlns="http://www.w3.org/2000/svg"
  349. viewBox="0 0 24 24"
  350. fill="currentColor"
  351. class="w-4 h-4"
  352. >
  353. <path
  354. fill-rule="evenodd"
  355. 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"
  356. clip-rule="evenodd"
  357. />
  358. </svg>
  359. </div>
  360. <div class=" self-center">Authentication</div>
  361. </button>
  362. <button
  363. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  364. 'about'
  365. ? 'bg-gray-200 dark:bg-gray-700'
  366. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  367. on:click={() => {
  368. selectedTab = 'about';
  369. }}
  370. >
  371. <div class=" self-center mr-2">
  372. <svg
  373. xmlns="http://www.w3.org/2000/svg"
  374. viewBox="0 0 20 20"
  375. fill="currentColor"
  376. class="w-4 h-4"
  377. >
  378. <path
  379. fill-rule="evenodd"
  380. 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"
  381. clip-rule="evenodd"
  382. />
  383. </svg>
  384. </div>
  385. <div class=" self-center">About</div>
  386. </button>
  387. </div>
  388. <div class="flex-1 md:min-h-[330px]">
  389. {#if selectedTab === 'general'}
  390. <div class="flex flex-col space-y-3">
  391. <div>
  392. <div class=" py-1 flex w-full justify-between">
  393. <div class=" self-center text-sm font-medium">Theme</div>
  394. <button
  395. class="p-1 px-3 text-xs flex rounded transition"
  396. on:click={() => {
  397. toggleTheme();
  398. }}
  399. >
  400. {#if theme === 'dark'}
  401. <svg
  402. xmlns="http://www.w3.org/2000/svg"
  403. viewBox="0 0 20 20"
  404. fill="currentColor"
  405. class="w-4 h-4"
  406. >
  407. <path
  408. fill-rule="evenodd"
  409. 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"
  410. clip-rule="evenodd"
  411. />
  412. </svg>
  413. <span class="ml-2 self-center"> Dark </span>
  414. {:else}
  415. <svg
  416. xmlns="http://www.w3.org/2000/svg"
  417. viewBox="0 0 20 20"
  418. fill="currentColor"
  419. class="w-4 h-4 self-center"
  420. >
  421. <path
  422. 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"
  423. />
  424. </svg>
  425. <span class="ml-2 self-center"> Light </span>
  426. {/if}
  427. </button>
  428. </div>
  429. </div>
  430. <hr class=" dark:border-gray-700" />
  431. <div>
  432. <div class=" mb-2.5 text-sm font-medium">Ollama Server URL</div>
  433. <div class="flex w-full">
  434. <div class="flex-1 mr-2">
  435. <input
  436. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  437. placeholder="Enter URL (e.g. http://localhost:11434/api)"
  438. bind:value={API_BASE_URL}
  439. />
  440. </div>
  441. <button
  442. class="px-3 bg-gray-200 hover:bg-gray-300 dark:bg-gray-600 dark:hover:bg-gray-700 rounded transition"
  443. on:click={() => {
  444. checkOllamaConnection();
  445. }}
  446. >
  447. <svg
  448. xmlns="http://www.w3.org/2000/svg"
  449. viewBox="0 0 20 20"
  450. fill="currentColor"
  451. class="w-4 h-4"
  452. >
  453. <path
  454. fill-rule="evenodd"
  455. 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"
  456. clip-rule="evenodd"
  457. />
  458. </svg>
  459. </button>
  460. </div>
  461. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  462. Trouble accessing Ollama? <a
  463. class=" text-gray-500 dark:text-gray-300 font-medium"
  464. href="https://github.com/ollama-webui/ollama-webui#troubleshooting"
  465. target="_blank"
  466. >
  467. Click here for help.
  468. </a>
  469. </div>
  470. </div>
  471. <hr class=" dark:border-gray-700" />
  472. <div>
  473. <div class=" mb-2.5 text-sm font-medium">System Prompt</div>
  474. <textarea
  475. bind:value={system}
  476. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  477. rows="4"
  478. />
  479. </div>
  480. <div class="flex justify-end pt-3 text-sm font-medium">
  481. <button
  482. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  483. on:click={() => {
  484. saveSettings({
  485. API_BASE_URL: API_BASE_URL === '' ? BUILD_TIME_API_BASE_URL : API_BASE_URL,
  486. system: system !== '' ? system : undefined
  487. });
  488. show = false;
  489. }}
  490. >
  491. Save
  492. </button>
  493. </div>
  494. </div>
  495. {:else if selectedTab === 'advanced'}
  496. <div class="flex flex-col h-full justify-between space-y-3 text-sm">
  497. <div class=" space-y-3">
  498. <div>
  499. <div class=" py-1 flex w-full justify-between">
  500. <div class=" self-center text-sm font-medium">Request Mode</div>
  501. <button
  502. class="p-1 px-3 text-xs flex rounded transition"
  503. on:click={() => {
  504. toggleRequestFormat();
  505. }}
  506. >
  507. {#if requestFormat === ''}
  508. <span class="ml-2 self-center"> Default </span>
  509. {:else if requestFormat === 'json'}
  510. <!-- <svg
  511. xmlns="http://www.w3.org/2000/svg"
  512. viewBox="0 0 20 20"
  513. fill="currentColor"
  514. class="w-4 h-4 self-center"
  515. >
  516. <path
  517. 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"
  518. />
  519. </svg> -->
  520. <span class="ml-2 self-center"> JSON </span>
  521. {/if}
  522. </button>
  523. </div>
  524. </div>
  525. <hr class=" dark:border-gray-700" />
  526. <div>
  527. <div class=" py-1 flex w-full justify-between">
  528. <div class=" w-20 text-sm font-medium self-center">Seed</div>
  529. <div class=" flex-1 self-center">
  530. <input
  531. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  532. type="number"
  533. placeholder="Enter Seed"
  534. bind:value={seed}
  535. autocomplete="off"
  536. min="0"
  537. />
  538. </div>
  539. </div>
  540. </div>
  541. <hr class=" dark:border-gray-700" />
  542. <div>
  543. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  544. <div>Temperature</div>
  545. <div>
  546. {temperature}
  547. </div></label
  548. >
  549. <input
  550. id="steps-range"
  551. type="range"
  552. min="0"
  553. max="1"
  554. bind:value={temperature}
  555. step="0.05"
  556. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  557. />
  558. </div>
  559. <div>
  560. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  561. <div>Repeat Penalty</div>
  562. <div>
  563. {repeat_penalty}
  564. </div></label
  565. >
  566. <input
  567. id="steps-range"
  568. type="range"
  569. min="0"
  570. max="2"
  571. bind:value={repeat_penalty}
  572. step="0.05"
  573. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  574. />
  575. </div>
  576. <div>
  577. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  578. <div>Top K</div>
  579. <div>
  580. {top_k}
  581. </div></label
  582. >
  583. <input
  584. id="steps-range"
  585. type="range"
  586. min="0"
  587. max="100"
  588. bind:value={top_k}
  589. step="0.5"
  590. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  591. />
  592. </div>
  593. <div>
  594. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  595. <div>Top P</div>
  596. <div>
  597. {top_p}
  598. </div></label
  599. >
  600. <input
  601. id="steps-range"
  602. type="range"
  603. min="0"
  604. max="1"
  605. bind:value={top_p}
  606. step="0.05"
  607. class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
  608. />
  609. </div>
  610. </div>
  611. <div class="flex justify-end pt-3 text-sm font-medium">
  612. <button
  613. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  614. on:click={() => {
  615. saveSettings({
  616. seed: (seed !== 0 ? seed : undefined) ?? undefined,
  617. temperature: temperature !== 0.8 ? temperature : undefined,
  618. repeat_penalty: repeat_penalty !== 1.1 ? repeat_penalty : undefined,
  619. top_k: top_k !== 40 ? top_k : undefined,
  620. top_p: top_p !== 0.9 ? top_p : undefined
  621. });
  622. show = false;
  623. }}
  624. >
  625. Save
  626. </button>
  627. </div>
  628. </div>
  629. {:else if selectedTab === 'models'}
  630. <div class="flex flex-col space-y-3 text-sm mb-10">
  631. <div>
  632. <div class=" mb-2.5 text-sm font-medium">Pull a model</div>
  633. <div class="flex w-full">
  634. <div class="flex-1 mr-2">
  635. <input
  636. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  637. placeholder="Enter model tag (e.g. mistral:7b)"
  638. bind:value={modelTag}
  639. />
  640. </div>
  641. <button
  642. class="px-3 text-gray-100 bg-emerald-600 hover:bg-emerald-700 rounded transition"
  643. on:click={() => {
  644. pullModelHandler();
  645. }}
  646. >
  647. <svg
  648. xmlns="http://www.w3.org/2000/svg"
  649. viewBox="0 0 20 20"
  650. fill="currentColor"
  651. class="w-4 h-4"
  652. >
  653. <path
  654. 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"
  655. />
  656. <path
  657. 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"
  658. />
  659. </svg>
  660. </button>
  661. </div>
  662. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  663. To access the available model names for downloading, <a
  664. class=" text-gray-500 dark:text-gray-300 font-medium"
  665. href="https://ollama.ai/library"
  666. target="_blank">click here.</a
  667. >
  668. </div>
  669. {#if pullProgress !== null}
  670. <div class="mt-2">
  671. <div class=" mb-2 text-xs">Pull Progress</div>
  672. <div class="w-full rounded-full dark:bg-gray-800">
  673. <div
  674. class="dark:bg-gray-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full"
  675. style="width: {Math.max(15, pullProgress ?? 0)}%"
  676. >
  677. {pullProgress ?? 0}%
  678. </div>
  679. </div>
  680. <div class="mt-1 text-xs dark:text-gray-700" style="font-size: 0.5rem;">
  681. {digest}
  682. </div>
  683. </div>
  684. {/if}
  685. </div>
  686. <hr class=" dark:border-gray-700" />
  687. <div>
  688. <div class=" mb-2.5 text-sm font-medium">Delete a model</div>
  689. <div class="flex w-full">
  690. <div class="flex-1 mr-2">
  691. <input
  692. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  693. placeholder="Enter model tag (e.g. mistral:7b)"
  694. bind:value={deleteModelTag}
  695. />
  696. </div>
  697. <button
  698. class="px-3 bg-red-700 hover:bg-red-800 text-gray-100 rounded transition"
  699. on:click={() => {
  700. deleteModelHandler();
  701. }}
  702. >
  703. <svg
  704. xmlns="http://www.w3.org/2000/svg"
  705. viewBox="0 0 20 20"
  706. fill="currentColor"
  707. class="w-4 h-4"
  708. >
  709. <path
  710. fill-rule="evenodd"
  711. 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"
  712. clip-rule="evenodd"
  713. />
  714. </svg>
  715. </button>
  716. </div>
  717. </div>
  718. </div>
  719. {:else if selectedTab === 'addons'}
  720. <form
  721. class="flex flex-col h-full justify-between space-y-3 text-sm"
  722. on:submit|preventDefault={() => {
  723. saveSettings({
  724. gravatarEmail: gravatarEmail !== '' ? gravatarEmail : undefined,
  725. gravatarUrl: gravatarEmail !== '' ? getGravatarURL(gravatarEmail) : undefined,
  726. OPENAI_API_KEY: OPENAI_API_KEY !== '' ? OPENAI_API_KEY : undefined
  727. });
  728. show = false;
  729. }}
  730. >
  731. <div class=" space-y-3">
  732. <div>
  733. <div class=" py-1 flex w-full justify-between">
  734. <div class=" self-center text-sm font-medium">Voice Input Auto-Send</div>
  735. <button
  736. class="p-1 px-3 text-xs flex rounded transition"
  737. on:click={() => {
  738. toggleSpeechAutoSend();
  739. }}
  740. type="button"
  741. >
  742. {#if speechAutoSend === true}
  743. <span class="ml-2 self-center">On</span>
  744. {:else}
  745. <span class="ml-2 self-center">Off</span>
  746. {/if}
  747. </button>
  748. </div>
  749. </div>
  750. <hr class=" dark:border-gray-700" />
  751. <div>
  752. <div class=" mb-2.5 text-sm font-medium">
  753. Gravatar Email <span class=" text-gray-400 text-sm">(optional)</span>
  754. </div>
  755. <div class="flex w-full">
  756. <div class="flex-1">
  757. <input
  758. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  759. placeholder="Enter Your Email"
  760. bind:value={gravatarEmail}
  761. autocomplete="off"
  762. type="email"
  763. />
  764. </div>
  765. </div>
  766. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  767. Changes user profile image to match your <a
  768. class=" text-gray-500 dark:text-gray-300 font-medium"
  769. href="https://gravatar.com/"
  770. target="_blank">Gravatar.</a
  771. >
  772. </div>
  773. </div>
  774. <hr class=" dark:border-gray-700" />
  775. <div>
  776. <div class=" mb-2.5 text-sm font-medium">
  777. OpenAI API Key <span class=" text-gray-400 text-sm">(optional)</span>
  778. </div>
  779. <div class="flex w-full">
  780. <div class="flex-1">
  781. <input
  782. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  783. placeholder="Enter OpenAI API Key"
  784. bind:value={OPENAI_API_KEY}
  785. autocomplete="off"
  786. />
  787. </div>
  788. </div>
  789. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  790. Adds optional support for 'gpt-*' models available.
  791. </div>
  792. </div>
  793. </div>
  794. <div class="flex justify-end pt-3 text-sm font-medium">
  795. <button
  796. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  797. type="submit"
  798. >
  799. Save
  800. </button>
  801. </div>
  802. </form>
  803. {:else if selectedTab === 'auth'}
  804. <form
  805. class="flex flex-col h-full justify-between space-y-3 text-sm"
  806. on:submit|preventDefault={() => {
  807. console.log('auth save');
  808. saveSettings({
  809. authHeader: authEnabled ? `${authType} ${authContent}` : undefined
  810. });
  811. show = false;
  812. }}
  813. >
  814. <div class=" space-y-3">
  815. <div>
  816. <div class=" py-1 flex w-full justify-between">
  817. <div class=" self-center text-sm font-medium">Authorization Header</div>
  818. <button
  819. class="p-1 px-3 text-xs flex rounded transition"
  820. type="button"
  821. on:click={() => {
  822. toggleAuthHeader();
  823. }}
  824. >
  825. {#if authEnabled === true}
  826. <svg
  827. xmlns="http://www.w3.org/2000/svg"
  828. viewBox="0 0 24 24"
  829. fill="currentColor"
  830. class="w-4 h-4"
  831. >
  832. <path
  833. fill-rule="evenodd"
  834. 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"
  835. clip-rule="evenodd"
  836. />
  837. </svg>
  838. <span class="ml-2 self-center"> On </span>
  839. {:else}
  840. <svg
  841. xmlns="http://www.w3.org/2000/svg"
  842. viewBox="0 0 24 24"
  843. fill="currentColor"
  844. class="w-4 h-4"
  845. >
  846. <path
  847. 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"
  848. />
  849. </svg>
  850. <span class="ml-2 self-center">Off</span>
  851. {/if}
  852. </button>
  853. </div>
  854. </div>
  855. {#if authEnabled}
  856. <hr class=" dark:border-gray-700" />
  857. <div class="mt-2">
  858. <div class=" py-1 flex w-full space-x-2">
  859. <button
  860. class=" py-1 font-semibold flex rounded transition"
  861. on:click={() => {
  862. authType = authType === 'Basic' ? 'Bearer' : 'Basic';
  863. }}
  864. type="button"
  865. >
  866. {#if authType === 'Basic'}
  867. <span class="self-center mr-2">Basic</span>
  868. {:else if authType === 'Bearer'}
  869. <span class="self-center mr-2">Bearer</span>
  870. {/if}
  871. </button>
  872. <div class="flex-1">
  873. <input
  874. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  875. placeholder="Enter Authorization Header Content"
  876. bind:value={authContent}
  877. />
  878. </div>
  879. </div>
  880. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  881. Toggle between <span class=" text-gray-500 dark:text-gray-300 font-medium"
  882. >'Basic'</span
  883. >
  884. and <span class=" text-gray-500 dark:text-gray-300 font-medium">'Bearer'</span> by
  885. clicking on the label next to the input.
  886. </div>
  887. </div>
  888. <hr class=" dark:border-gray-700" />
  889. <div>
  890. <div class=" mb-2.5 text-sm font-medium">Preview Authorization Header</div>
  891. <textarea
  892. value={JSON.stringify({
  893. Authorization: `${authType} ${authContent}`
  894. })}
  895. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  896. rows="2"
  897. disabled
  898. />
  899. </div>
  900. {/if}
  901. </div>
  902. <div class="flex justify-end pt-3 text-sm font-medium">
  903. <button
  904. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  905. type="submit"
  906. >
  907. Save
  908. </button>
  909. </div>
  910. </form>
  911. {:else if selectedTab === 'about'}
  912. <div class="flex flex-col h-full justify-between space-y-3 text-sm mb-6">
  913. <div class=" space-y-3">
  914. <div>
  915. <div class=" mb-2.5 text-sm font-medium">Ollama Web UI Version</div>
  916. <div class="flex w-full">
  917. <div class="flex-1 text-xs text-gray-700 dark:text-gray-200">
  918. {$config && $config.version ? $config.version : WEB_UI_VERSION}
  919. </div>
  920. </div>
  921. </div>
  922. <hr class=" dark:border-gray-700" />
  923. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  924. Created by <a
  925. class=" text-gray-500 dark:text-gray-300 font-medium"
  926. href="https://github.com/tjbck"
  927. target="_blank">Timothy J. Baek</a
  928. >
  929. </div>
  930. <div>
  931. <a href="https://github.com/ollama-webui/ollama-webui">
  932. <img
  933. alt="Github Repo"
  934. src="https://img.shields.io/github/stars/ollama-webui/ollama-webui?style=social&label=Star us on Github"
  935. />
  936. </a>
  937. </div>
  938. </div>
  939. </div>
  940. {/if}
  941. </div>
  942. </div>
  943. </div>
  944. </Modal>
  945. <style>
  946. input::-webkit-outer-spin-button,
  947. input::-webkit-inner-spin-button {
  948. /* display: none; <- Crashes Chrome on hover */
  949. -webkit-appearance: none;
  950. margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
  951. }
  952. .tabs::-webkit-scrollbar {
  953. display: none; /* for Chrome, Safari and Opera */
  954. }
  955. .tabs {
  956. -ms-overflow-style: none; /* IE and Edge */
  957. scrollbar-width: none; /* Firefox */
  958. }
  959. input[type='number'] {
  960. -moz-appearance: textfield; /* Firefox */
  961. }
  962. </style>