SettingsModal.svelte 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <script lang="ts">
  2. import sha256 from 'js-sha256';
  3. import Modal from '../common/Modal.svelte';
  4. import { API_BASE_URL as BUILD_TIME_API_BASE_URL } from '$lib/constants';
  5. import toast from 'svelte-french-toast';
  6. export let show = false;
  7. export let saveSettings: Function;
  8. export let getModelTags: Function;
  9. let selectedTab = 'general';
  10. // General
  11. let API_BASE_URL = BUILD_TIME_API_BASE_URL;
  12. let system = '';
  13. // Models
  14. let modelTag = '';
  15. let deleteModelTag = '';
  16. let digest = '';
  17. let pullProgress = null;
  18. // Advanced
  19. let seed = 0;
  20. let temperature = 0.8;
  21. let repeat_penalty = 1.1;
  22. let top_k = 40;
  23. let top_p = 0.9;
  24. // Addons
  25. let gravatarEmail = '';
  26. let OPENAI_API_KEY = '';
  27. function getGravatarURL(email) {
  28. // Trim leading and trailing whitespace from
  29. // an email address and force all characters
  30. // to lower case
  31. const address = String(email).trim().toLowerCase();
  32. // Create a SHA256 hash of the final string
  33. const hash = sha256(address);
  34. // Grab the actual image URL
  35. return `https://www.gravatar.com/avatar/${hash}`;
  36. }
  37. const splitStream = (splitOn) => {
  38. let buffer = '';
  39. return new TransformStream({
  40. transform(chunk, controller) {
  41. buffer += chunk;
  42. const parts = buffer.split(splitOn);
  43. parts.slice(0, -1).forEach((part) => controller.enqueue(part));
  44. buffer = parts[parts.length - 1];
  45. },
  46. flush(controller) {
  47. if (buffer) controller.enqueue(buffer);
  48. }
  49. });
  50. };
  51. const checkOllamaConnection = async () => {
  52. if (API_BASE_URL === '') {
  53. API_BASE_URL = BUILD_TIME_API_BASE_URL;
  54. }
  55. const res = await getModelTags(API_BASE_URL);
  56. if (res) {
  57. toast.success('Server connection verified');
  58. saveSettings({
  59. API_BASE_URL: API_BASE_URL
  60. });
  61. }
  62. };
  63. const pullModelHandler = async () => {
  64. const res = await fetch(`${API_BASE_URL}/pull`, {
  65. method: 'POST',
  66. headers: {
  67. 'Content-Type': 'text/event-stream'
  68. },
  69. body: JSON.stringify({
  70. name: modelTag
  71. })
  72. });
  73. const reader = res.body
  74. .pipeThrough(new TextDecoderStream())
  75. .pipeThrough(splitStream('\n'))
  76. .getReader();
  77. while (true) {
  78. const { value, done } = await reader.read();
  79. if (done) break;
  80. try {
  81. let lines = value.split('\n');
  82. for (const line of lines) {
  83. if (line !== '') {
  84. console.log(line);
  85. let data = JSON.parse(line);
  86. console.log(data);
  87. if (data.error) {
  88. throw data.error;
  89. }
  90. if (data.status) {
  91. if (!data.status.includes('downloading')) {
  92. toast.success(data.status);
  93. } else {
  94. digest = data.digest;
  95. if (data.completed) {
  96. pullProgress = Math.round((data.completed / data.total) * 1000) / 10;
  97. } else {
  98. pullProgress = 100;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. } catch (error) {
  105. console.log(error);
  106. toast.error(error);
  107. }
  108. }
  109. modelTag = '';
  110. await getModelTags();
  111. };
  112. const deleteModelHandler = async () => {
  113. const res = await fetch(`${API_BASE_URL}/delete`, {
  114. method: 'DELETE',
  115. headers: {
  116. 'Content-Type': 'text/event-stream'
  117. },
  118. body: JSON.stringify({
  119. name: deleteModelTag
  120. })
  121. });
  122. const reader = res.body
  123. .pipeThrough(new TextDecoderStream())
  124. .pipeThrough(splitStream('\n'))
  125. .getReader();
  126. while (true) {
  127. const { value, done } = await reader.read();
  128. if (done) break;
  129. try {
  130. let lines = value.split('\n');
  131. for (const line of lines) {
  132. if (line !== '' && line !== 'null') {
  133. console.log(line);
  134. let data = JSON.parse(line);
  135. console.log(data);
  136. if (data.error) {
  137. throw data.error;
  138. }
  139. if (data.status) {
  140. }
  141. } else {
  142. toast.success(`Deleted ${deleteModelTag}`);
  143. }
  144. }
  145. } catch (error) {
  146. console.log(error);
  147. toast.error(error);
  148. }
  149. }
  150. deleteModelTag = '';
  151. await getModelTags();
  152. };
  153. $: if (show) {
  154. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  155. console.log(settings);
  156. API_BASE_URL = settings.API_BASE_URL ?? BUILD_TIME_API_BASE_URL;
  157. system = settings.system ?? '';
  158. seed = settings.seed ?? 0;
  159. temperature = settings.temperature ?? 0.8;
  160. repeat_penalty = settings.repeat_penalty ?? 1.1;
  161. top_k = settings.top_k ?? 40;
  162. top_p = settings.top_p ?? 0.9;
  163. OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
  164. gravatarEmail = settings.gravatarEmail ?? '';
  165. }
  166. </script>
  167. <Modal bind:show>
  168. <div class="rounded-lg bg-gray-900">
  169. <div class=" flex justify-between text-gray-300 px-5 py-4">
  170. <div class=" text-lg font-medium self-center">Settings</div>
  171. <button
  172. class="self-center"
  173. on:click={() => {
  174. show = false;
  175. }}
  176. >
  177. <svg
  178. xmlns="http://www.w3.org/2000/svg"
  179. viewBox="0 0 20 20"
  180. fill="currentColor"
  181. class="w-5 h-5"
  182. >
  183. <path
  184. 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"
  185. />
  186. </svg>
  187. </button>
  188. </div>
  189. <hr class=" border-gray-800" />
  190. <div class="flex flex-col md:flex-row w-full p-4 md:space-x-4">
  191. <div
  192. 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 text-gray-200 text-xs text-left mb-3 md:mb-0"
  193. >
  194. <button
  195. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  196. 'general'
  197. ? 'bg-gray-700'
  198. : 'hover:bg-gray-800'}"
  199. on:click={() => {
  200. selectedTab = 'general';
  201. }}
  202. >
  203. <div class=" self-center mr-2">
  204. <svg
  205. xmlns="http://www.w3.org/2000/svg"
  206. viewBox="0 0 20 20"
  207. fill="currentColor"
  208. class="w-4 h-4"
  209. >
  210. <path
  211. fill-rule="evenodd"
  212. 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"
  213. clip-rule="evenodd"
  214. />
  215. </svg>
  216. </div>
  217. <div class=" self-center">General</div>
  218. </button>
  219. <button
  220. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  221. 'advanced'
  222. ? 'bg-gray-700'
  223. : 'hover:bg-gray-800'}"
  224. on:click={() => {
  225. selectedTab = 'advanced';
  226. }}
  227. >
  228. <div class=" self-center mr-2">
  229. <svg
  230. xmlns="http://www.w3.org/2000/svg"
  231. viewBox="0 0 20 20"
  232. fill="currentColor"
  233. class="w-4 h-4"
  234. >
  235. <path
  236. 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"
  237. />
  238. </svg>
  239. </div>
  240. <div class=" self-center">Advanced</div>
  241. </button>
  242. <button
  243. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  244. 'models'
  245. ? 'bg-gray-700'
  246. : 'hover:bg-gray-800'}"
  247. on:click={() => {
  248. selectedTab = 'models';
  249. }}
  250. >
  251. <div class=" self-center mr-2">
  252. <svg
  253. xmlns="http://www.w3.org/2000/svg"
  254. viewBox="0 0 20 20"
  255. fill="currentColor"
  256. class="w-4 h-4"
  257. >
  258. <path
  259. fill-rule="evenodd"
  260. 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"
  261. clip-rule="evenodd"
  262. />
  263. </svg>
  264. </div>
  265. <div class=" self-center">Models</div>
  266. </button>
  267. <button
  268. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  269. 'addons'
  270. ? 'bg-gray-700'
  271. : 'hover:bg-gray-800'}"
  272. on:click={() => {
  273. selectedTab = 'addons';
  274. }}
  275. >
  276. <div class=" self-center mr-2">
  277. <svg
  278. xmlns="http://www.w3.org/2000/svg"
  279. viewBox="0 0 20 20"
  280. fill="currentColor"
  281. class="w-4 h-4"
  282. >
  283. <path
  284. 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"
  285. />
  286. </svg>
  287. </div>
  288. <div class=" self-center">Add-ons</div>
  289. </button>
  290. </div>
  291. <div class="flex-1 md:min-h-[300px]">
  292. {#if selectedTab === 'general'}
  293. <div class="flex flex-col space-y-3">
  294. <div>
  295. <div class=" mb-2.5 text-sm font-medium">Ollama Server URL</div>
  296. <div class="flex w-full">
  297. <div class="flex-1 mr-2">
  298. <input
  299. class="w-full rounded py-2 px-4 text-sm text-gray-300 bg-gray-800 outline-none"
  300. placeholder="Enter URL (e.g. http://localhost:11434/api)"
  301. bind:value={API_BASE_URL}
  302. />
  303. </div>
  304. <button
  305. class="px-3 bg-gray-600 hover:bg-gray-700 rounded transition"
  306. on:click={() => {
  307. checkOllamaConnection();
  308. }}
  309. >
  310. <svg
  311. xmlns="http://www.w3.org/2000/svg"
  312. viewBox="0 0 20 20"
  313. fill="currentColor"
  314. class="w-4 h-4"
  315. >
  316. <path
  317. fill-rule="evenodd"
  318. 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"
  319. clip-rule="evenodd"
  320. />
  321. </svg>
  322. </button>
  323. </div>
  324. <div class="mt-2 text-xs text-gray-500">
  325. Trouble accessing Ollama? <a
  326. class=" text-gray-300 font-medium"
  327. href="https://github.com/ollama-webui/ollama-webui#troubleshooting"
  328. target="_blank"
  329. >
  330. Click here for help.
  331. </a>
  332. </div>
  333. </div>
  334. <hr class=" border-gray-700" />
  335. <div>
  336. <div class=" mb-2.5 text-sm font-medium">System Prompt</div>
  337. <textarea
  338. bind:value={system}
  339. class="w-full rounded p-4 text-sm text-gray-300 bg-gray-800 outline-none resize-none"
  340. rows="4"
  341. />
  342. </div>
  343. <div class="flex justify-end pt-3 text-sm font-medium">
  344. <button
  345. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 transition rounded"
  346. on:click={() => {
  347. saveSettings({
  348. API_BASE_URL: API_BASE_URL === '' ? BUILD_TIME_API_BASE_URL : API_BASE_URL,
  349. system: system !== '' ? system : undefined
  350. });
  351. show = false;
  352. }}
  353. >
  354. Save
  355. </button>
  356. </div>
  357. </div>
  358. {:else if selectedTab === 'models'}
  359. <div class="flex flex-col space-y-3 text-sm mb-10">
  360. <div>
  361. <div class=" mb-2.5 text-sm font-medium">Pull a model</div>
  362. <div class="flex w-full">
  363. <div class="flex-1 mr-2">
  364. <input
  365. class="w-full rounded py-2 px-4 text-sm text-gray-300 bg-gray-800 outline-none"
  366. placeholder="Enter model tag (e.g. mistral:7b)"
  367. bind:value={modelTag}
  368. />
  369. </div>
  370. <button
  371. class="px-3 bg-emerald-600 hover:bg-emerald-700 rounded transition"
  372. on:click={() => {
  373. pullModelHandler();
  374. }}
  375. >
  376. <svg
  377. xmlns="http://www.w3.org/2000/svg"
  378. viewBox="0 0 20 20"
  379. fill="currentColor"
  380. class="w-4 h-4"
  381. >
  382. <path
  383. 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"
  384. />
  385. <path
  386. 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"
  387. />
  388. </svg>
  389. </button>
  390. </div>
  391. <div class="mt-2 text-xs text-gray-500">
  392. To access the available model names for downloading, <a
  393. class=" text-gray-300 font-medium"
  394. href="https://ollama.ai/library"
  395. target="_blank">click here.</a
  396. >
  397. </div>
  398. {#if pullProgress !== null}
  399. <div class="mt-2">
  400. <div class=" mb-2 text-xs">Pull Progress</div>
  401. <div class="w-full rounded-full bg-gray-800">
  402. <div
  403. class="bg-gray-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full"
  404. style="width: {Math.max(15, pullProgress ?? 0)}%"
  405. >
  406. {pullProgress ?? 0}%
  407. </div>
  408. </div>
  409. <div class="mt-1 text-xs text-gray-700" style="font-size: 0.5rem;">
  410. {digest}
  411. </div>
  412. </div>
  413. {/if}
  414. </div>
  415. <hr class=" border-gray-700" />
  416. <div>
  417. <div class=" mb-2.5 text-sm font-medium">Delete a model</div>
  418. <div class="flex w-full">
  419. <div class="flex-1 mr-2">
  420. <input
  421. class="w-full rounded py-2 px-4 text-sm text-gray-300 bg-gray-800 outline-none"
  422. placeholder="Enter model tag (e.g. mistral:7b)"
  423. bind:value={deleteModelTag}
  424. />
  425. </div>
  426. <button
  427. class="px-3 bg-red-700 hover:bg-red-800 rounded transition"
  428. on:click={() => {
  429. deleteModelHandler();
  430. }}
  431. >
  432. <svg
  433. xmlns="http://www.w3.org/2000/svg"
  434. viewBox="0 0 20 20"
  435. fill="currentColor"
  436. class="w-4 h-4"
  437. >
  438. <path
  439. fill-rule="evenodd"
  440. 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"
  441. clip-rule="evenodd"
  442. />
  443. </svg>
  444. </button>
  445. </div>
  446. </div>
  447. </div>
  448. {:else if selectedTab === 'advanced'}
  449. <div class="flex flex-col h-full justify-between space-y-3 text-sm">
  450. <div class=" space-y-3">
  451. <div>
  452. <div class=" mb-2.5 text-sm font-medium">Seed</div>
  453. <div class="flex w-full">
  454. <div class="flex-1">
  455. <input
  456. class="w-full rounded py-2 px-4 text-sm text-gray-300 bg-gray-800 outline-none"
  457. type="number"
  458. placeholder="Enter Seed"
  459. bind:value={seed}
  460. autocomplete="off"
  461. min="0"
  462. />
  463. </div>
  464. </div>
  465. </div>
  466. <hr class=" border-gray-700" />
  467. <div>
  468. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  469. <div>Temperature</div>
  470. <div>
  471. {temperature}
  472. </div></label
  473. >
  474. <input
  475. id="steps-range"
  476. type="range"
  477. min="0"
  478. max="1"
  479. bind:value={temperature}
  480. step="0.05"
  481. class="w-full h-2 rounded-lg appearance-none cursor-pointer bg-gray-700"
  482. />
  483. </div>
  484. <div>
  485. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  486. <div>Repeat Penalty</div>
  487. <div>
  488. {repeat_penalty}
  489. </div></label
  490. >
  491. <input
  492. id="steps-range"
  493. type="range"
  494. min="0"
  495. max="2"
  496. bind:value={repeat_penalty}
  497. step="0.05"
  498. class="w-full h-2 rounded-lg appearance-none cursor-pointer bg-gray-700"
  499. />
  500. </div>
  501. <div>
  502. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  503. <div>Top K</div>
  504. <div>
  505. {top_k}
  506. </div></label
  507. >
  508. <input
  509. id="steps-range"
  510. type="range"
  511. min="0"
  512. max="100"
  513. bind:value={top_k}
  514. step="0.5"
  515. class="w-full h-2 rounded-lg appearance-none cursor-pointer bg-gray-700"
  516. />
  517. </div>
  518. <div>
  519. <label for="steps-range" class=" mb-2 text-sm font-medium flex justify-between">
  520. <div>Top P</div>
  521. <div>
  522. {top_p}
  523. </div></label
  524. >
  525. <input
  526. id="steps-range"
  527. type="range"
  528. min="0"
  529. max="1"
  530. bind:value={top_p}
  531. step="0.05"
  532. class="w-full h-2 rounded-lg appearance-none cursor-pointer bg-gray-700"
  533. />
  534. </div>
  535. </div>
  536. <div class="flex justify-end pt-3 text-sm font-medium">
  537. <button
  538. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 transition rounded"
  539. on:click={() => {
  540. saveSettings({
  541. seed: (seed !== 0 ? seed : undefined) ?? undefined,
  542. temperature: temperature !== 0.8 ? temperature : undefined,
  543. repeat_penalty: repeat_penalty !== 1.1 ? repeat_penalty : undefined,
  544. top_k: top_k !== 40 ? top_k : undefined,
  545. top_p: top_p !== 0.9 ? top_p : undefined
  546. });
  547. show = false;
  548. }}
  549. >
  550. Save
  551. </button>
  552. </div>
  553. </div>
  554. {:else if selectedTab === 'addons'}
  555. <form
  556. class="flex flex-col h-full justify-between space-y-3 text-sm"
  557. on:submit|preventDefault={() => {
  558. saveSettings({
  559. gravatarEmail: gravatarEmail !== '' ? gravatarEmail : undefined,
  560. gravatarUrl: gravatarEmail !== '' ? getGravatarURL(gravatarEmail) : undefined,
  561. OPENAI_API_KEY: OPENAI_API_KEY !== '' ? OPENAI_API_KEY : undefined
  562. });
  563. show = false;
  564. }}
  565. >
  566. <div class=" space-y-3">
  567. <div>
  568. <div class=" mb-2.5 text-sm font-medium">
  569. Gravatar Email <span class=" text-gray-400 text-sm">(optional)</span>
  570. </div>
  571. <div class="flex w-full">
  572. <div class="flex-1">
  573. <input
  574. class="w-full rounded py-2 px-4 text-sm text-gray-300 bg-gray-800 outline-none"
  575. placeholder="Enter Your Email"
  576. bind:value={gravatarEmail}
  577. autocomplete="off"
  578. type="email"
  579. />
  580. </div>
  581. </div>
  582. <div class="mt-2 text-xs text-gray-500">
  583. Changes user profile image to match your <a
  584. class=" text-gray-300 font-medium"
  585. href="https://gravatar.com/"
  586. target="_blank">Gravatar.</a
  587. >
  588. </div>
  589. </div>
  590. <hr class=" border-gray-700" />
  591. <div>
  592. <div class=" mb-2.5 text-sm font-medium">
  593. OpenAI API Key <span class=" text-gray-400 text-sm">(optional)</span>
  594. </div>
  595. <div class="flex w-full">
  596. <div class="flex-1">
  597. <input
  598. class="w-full rounded py-2 px-4 text-sm text-gray-300 bg-gray-800 outline-none"
  599. placeholder="Enter OpenAI API Key"
  600. bind:value={OPENAI_API_KEY}
  601. autocomplete="off"
  602. />
  603. </div>
  604. </div>
  605. <div class="mt-2 text-xs text-gray-500">
  606. Adds optional support for 'gpt-*' models available.
  607. </div>
  608. </div>
  609. </div>
  610. <div class="flex justify-end pt-3 text-sm font-medium">
  611. <button
  612. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 transition rounded"
  613. type="submit"
  614. >
  615. Save
  616. </button>
  617. </div>
  618. </form>
  619. {/if}
  620. </div>
  621. </div>
  622. </div>
  623. </Modal>
  624. <style>
  625. input::-webkit-outer-spin-button,
  626. input::-webkit-inner-spin-button {
  627. /* display: none; <- Crashes Chrome on hover */
  628. -webkit-appearance: none;
  629. margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
  630. }
  631. .tabs::-webkit-scrollbar {
  632. display: none; /* for Chrome, Safari and Opera */
  633. }
  634. .tabs {
  635. -ms-overflow-style: none; /* IE and Edge */
  636. scrollbar-width: none; /* Firefox */
  637. }
  638. input[type='number'] {
  639. -moz-appearance: textfield; /* Firefox */
  640. }
  641. </style>