SettingsModal.svelte 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  1. <script lang="ts">
  2. import toast from 'svelte-french-toast';
  3. import fileSaver from 'file-saver';
  4. const { saveAs } = fileSaver;
  5. import { onMount } from 'svelte';
  6. import { config, models, settings, user, chats } from '$lib/stores';
  7. import { splitStream, getGravatarURL } from '$lib/utils';
  8. import { getOllamaVersion } from '$lib/apis/ollama';
  9. import { createNewChat, deleteAllChats, getAllChats, getChatList } from '$lib/apis/chats';
  10. import {
  11. WEB_UI_VERSION,
  12. OLLAMA_API_BASE_URL,
  13. WEBUI_API_BASE_URL,
  14. WEBUI_BASE_URL
  15. } from '$lib/constants';
  16. import Advanced from './Settings/Advanced.svelte';
  17. import Modal from '../common/Modal.svelte';
  18. import { updateUserPassword } from '$lib/apis/auths';
  19. import { goto } from '$app/navigation';
  20. export let show = false;
  21. const saveSettings = async (updated) => {
  22. console.log(updated);
  23. await settings.set({ ...$settings, ...updated });
  24. await models.set(await getModels());
  25. localStorage.setItem('settings', JSON.stringify($settings));
  26. };
  27. let selectedTab = 'general';
  28. // General
  29. let API_BASE_URL = OLLAMA_API_BASE_URL;
  30. let themes = ['dark', 'light', 'rose-pine dark', 'rose-pine-dawn light'];
  31. let theme = 'dark';
  32. let notificationEnabled = false;
  33. let system = '';
  34. // Advanced
  35. let requestFormat = '';
  36. let options = {
  37. // Advanced
  38. seed: 0,
  39. temperature: '',
  40. repeat_penalty: '',
  41. repeat_last_n: '',
  42. mirostat: '',
  43. mirostat_eta: '',
  44. mirostat_tau: '',
  45. top_k: '',
  46. top_p: '',
  47. stop: '',
  48. tfs_z: '',
  49. num_ctx: '',
  50. num_predict: ''
  51. };
  52. // Models
  53. let modelTransferring = false;
  54. let modelTag = '';
  55. let digest = '';
  56. let pullProgress = null;
  57. let modelUploadMode = 'file';
  58. let modelInputFile = '';
  59. let modelFileUrl = '';
  60. let modelFileContent = `TEMPLATE """{{ .System }}\nUSER: {{ .Prompt }}\nASSSISTANT: """\nPARAMETER num_ctx 4096\nPARAMETER stop "</s>"\nPARAMETER stop "USER:"\nPARAMETER stop "ASSSISTANT:"`;
  61. let modelFileDigest = '';
  62. let uploadProgress = null;
  63. let deleteModelTag = '';
  64. // Addons
  65. let titleAutoGenerate = true;
  66. let speechAutoSend = false;
  67. let responseAutoCopy = false;
  68. let gravatarEmail = '';
  69. let OPENAI_API_KEY = '';
  70. let OPENAI_API_BASE_URL = '';
  71. // Chats
  72. let importFiles;
  73. let showDeleteConfirm = false;
  74. const importChats = async (_chats) => {
  75. for (const chat of _chats) {
  76. console.log(chat);
  77. await createNewChat(localStorage.token, chat);
  78. }
  79. await chats.set(await getChatList(localStorage.token));
  80. };
  81. const exportChats = async () => {
  82. let blob = new Blob([JSON.stringify(await getAllChats(localStorage.token))], {
  83. type: 'application/json'
  84. });
  85. saveAs(blob, `chat-export-${Date.now()}.json`);
  86. };
  87. $: if (importFiles) {
  88. console.log(importFiles);
  89. let reader = new FileReader();
  90. reader.onload = (event) => {
  91. let chats = JSON.parse(event.target.result);
  92. console.log(chats);
  93. importChats(chats);
  94. };
  95. reader.readAsText(importFiles[0]);
  96. }
  97. const deleteChats = async () => {
  98. await goto('/');
  99. await deleteAllChats(localStorage.token);
  100. await chats.set(await getChatList(localStorage.token));
  101. };
  102. // Auth
  103. let authEnabled = false;
  104. let authType = 'Basic';
  105. let authContent = '';
  106. // Account
  107. let currentPassword = '';
  108. let newPassword = '';
  109. let newPasswordConfirm = '';
  110. // About
  111. let ollamaVersion = '';
  112. const checkOllamaConnection = async () => {
  113. if (API_BASE_URL === '') {
  114. API_BASE_URL = OLLAMA_API_BASE_URL;
  115. }
  116. const _models = await getModels(API_BASE_URL, 'ollama');
  117. if (_models.length > 0) {
  118. toast.success('Server connection verified');
  119. await models.set(_models);
  120. saveSettings({
  121. API_BASE_URL: API_BASE_URL
  122. });
  123. }
  124. };
  125. const toggleTheme = async () => {
  126. if (theme === 'dark') {
  127. theme = 'light';
  128. } else {
  129. theme = 'dark';
  130. }
  131. localStorage.theme = theme;
  132. document.documentElement.classList.remove(theme === 'dark' ? 'light' : 'dark');
  133. document.documentElement.classList.add(theme);
  134. };
  135. const toggleRequestFormat = async () => {
  136. if (requestFormat === '') {
  137. requestFormat = 'json';
  138. } else {
  139. requestFormat = '';
  140. }
  141. saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
  142. };
  143. const toggleSpeechAutoSend = async () => {
  144. speechAutoSend = !speechAutoSend;
  145. saveSettings({ speechAutoSend: speechAutoSend });
  146. };
  147. const toggleTitleAutoGenerate = async () => {
  148. titleAutoGenerate = !titleAutoGenerate;
  149. saveSettings({ titleAutoGenerate: titleAutoGenerate });
  150. };
  151. const toggleNotification = async () => {
  152. const permission = await Notification.requestPermission();
  153. if (permission === 'granted') {
  154. notificationEnabled = !notificationEnabled;
  155. saveSettings({ notificationEnabled: notificationEnabled });
  156. } else {
  157. toast.error(
  158. 'Response notifications cannot be activated as the website permissions have been denied. Please visit your browser settings to grant the necessary access.'
  159. );
  160. }
  161. };
  162. const toggleResponseAutoCopy = async () => {
  163. const permission = await navigator.clipboard
  164. .readText()
  165. .then(() => {
  166. return 'granted';
  167. })
  168. .catch(() => {
  169. return '';
  170. });
  171. console.log(permission);
  172. if (permission === 'granted') {
  173. responseAutoCopy = !responseAutoCopy;
  174. saveSettings({ responseAutoCopy: responseAutoCopy });
  175. } else {
  176. toast.error(
  177. 'Clipboard write permission denied. Please check your browser settings to grant the necessary access.'
  178. );
  179. }
  180. };
  181. const toggleAuthHeader = async () => {
  182. authEnabled = !authEnabled;
  183. };
  184. const pullModelHandler = async () => {
  185. modelTransferring = true;
  186. const res = await fetch(`${API_BASE_URL}/pull`, {
  187. method: 'POST',
  188. headers: {
  189. 'Content-Type': 'text/event-stream',
  190. ...($settings.authHeader && { Authorization: $settings.authHeader }),
  191. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  192. },
  193. body: JSON.stringify({
  194. name: modelTag
  195. })
  196. });
  197. const reader = res.body
  198. .pipeThrough(new TextDecoderStream())
  199. .pipeThrough(splitStream('\n'))
  200. .getReader();
  201. while (true) {
  202. const { value, done } = await reader.read();
  203. if (done) break;
  204. try {
  205. let lines = value.split('\n');
  206. for (const line of lines) {
  207. if (line !== '') {
  208. console.log(line);
  209. let data = JSON.parse(line);
  210. console.log(data);
  211. if (data.error) {
  212. throw data.error;
  213. }
  214. if (data.detail) {
  215. throw data.detail;
  216. }
  217. if (data.status) {
  218. if (!data.digest) {
  219. toast.success(data.status);
  220. if (data.status === 'success') {
  221. const notification = new Notification(`Ollama`, {
  222. body: `Model '${modelTag}' has been successfully downloaded.`,
  223. icon: '/favicon.png'
  224. });
  225. }
  226. } else {
  227. digest = data.digest;
  228. if (data.completed) {
  229. pullProgress = Math.round((data.completed / data.total) * 1000) / 10;
  230. } else {
  231. pullProgress = 100;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. } catch (error) {
  238. console.log(error);
  239. toast.error(error);
  240. }
  241. }
  242. modelTag = '';
  243. modelTransferring = false;
  244. models.set(await getModels());
  245. };
  246. const calculateSHA256 = async (file) => {
  247. console.log(file);
  248. // Create a FileReader to read the file asynchronously
  249. const reader = new FileReader();
  250. // Define a promise to handle the file reading
  251. const readFile = new Promise((resolve, reject) => {
  252. reader.onload = () => resolve(reader.result);
  253. reader.onerror = reject;
  254. });
  255. // Read the file as an ArrayBuffer
  256. reader.readAsArrayBuffer(file);
  257. try {
  258. // Wait for the FileReader to finish reading the file
  259. const buffer = await readFile;
  260. // Convert the ArrayBuffer to a Uint8Array
  261. const uint8Array = new Uint8Array(buffer);
  262. // Calculate the SHA-256 hash using Web Crypto API
  263. const hashBuffer = await crypto.subtle.digest('SHA-256', uint8Array);
  264. // Convert the hash to a hexadecimal string
  265. const hashArray = Array.from(new Uint8Array(hashBuffer));
  266. const hashHex = hashArray.map((byte) => byte.toString(16).padStart(2, '0')).join('');
  267. return `sha256:${hashHex}`;
  268. } catch (error) {
  269. console.error('Error calculating SHA-256 hash:', error);
  270. throw error;
  271. }
  272. };
  273. const uploadModelHandler = async () => {
  274. modelTransferring = true;
  275. uploadProgress = 0;
  276. let uploaded = false;
  277. let fileResponse = null;
  278. let name = '';
  279. if (modelUploadMode === 'file') {
  280. const file = modelInputFile[0];
  281. const formData = new FormData();
  282. formData.append('file', file);
  283. fileResponse = await fetch(`${WEBUI_API_BASE_URL}/utils/upload`, {
  284. method: 'POST',
  285. headers: {
  286. ...($settings.authHeader && { Authorization: $settings.authHeader }),
  287. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  288. },
  289. body: formData
  290. }).catch((error) => {
  291. console.log(error);
  292. return null;
  293. });
  294. } else {
  295. fileResponse = await fetch(`${WEBUI_API_BASE_URL}/utils/download?url=${modelFileUrl}`, {
  296. method: 'GET',
  297. headers: {
  298. ...($settings.authHeader && { Authorization: $settings.authHeader }),
  299. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  300. }
  301. }).catch((error) => {
  302. console.log(error);
  303. return null;
  304. });
  305. }
  306. if (fileResponse && fileResponse.ok) {
  307. const reader = fileResponse.body
  308. .pipeThrough(new TextDecoderStream())
  309. .pipeThrough(splitStream('\n'))
  310. .getReader();
  311. while (true) {
  312. const { value, done } = await reader.read();
  313. if (done) break;
  314. try {
  315. let lines = value.split('\n');
  316. for (const line of lines) {
  317. if (line !== '') {
  318. let data = JSON.parse(line.replace(/^data: /, ''));
  319. if (data.progress) {
  320. uploadProgress = data.progress;
  321. }
  322. if (data.error) {
  323. throw data.error;
  324. }
  325. if (data.done) {
  326. modelFileDigest = data.blob;
  327. name = data.name;
  328. uploaded = true;
  329. }
  330. }
  331. }
  332. } catch (error) {
  333. console.log(error);
  334. }
  335. }
  336. }
  337. if (uploaded) {
  338. const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/create`, {
  339. method: 'POST',
  340. headers: {
  341. 'Content-Type': 'text/event-stream',
  342. ...($settings.authHeader && { Authorization: $settings.authHeader }),
  343. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  344. },
  345. body: JSON.stringify({
  346. name: `${name}:latest`,
  347. modelfile: `FROM @${modelFileDigest}\n${modelFileContent}`
  348. })
  349. }).catch((err) => {
  350. console.log(err);
  351. return null;
  352. });
  353. if (res && res.ok) {
  354. const reader = res.body
  355. .pipeThrough(new TextDecoderStream())
  356. .pipeThrough(splitStream('\n'))
  357. .getReader();
  358. while (true) {
  359. const { value, done } = await reader.read();
  360. if (done) break;
  361. try {
  362. let lines = value.split('\n');
  363. for (const line of lines) {
  364. if (line !== '') {
  365. console.log(line);
  366. let data = JSON.parse(line);
  367. console.log(data);
  368. if (data.error) {
  369. throw data.error;
  370. }
  371. if (data.detail) {
  372. throw data.detail;
  373. }
  374. if (data.status) {
  375. if (
  376. !data.digest &&
  377. !data.status.includes('writing') &&
  378. !data.status.includes('sha256')
  379. ) {
  380. toast.success(data.status);
  381. } else {
  382. if (data.digest) {
  383. digest = data.digest;
  384. if (data.completed) {
  385. pullProgress = Math.round((data.completed / data.total) * 1000) / 10;
  386. } else {
  387. pullProgress = 100;
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. } catch (error) {
  395. console.log(error);
  396. toast.error(error);
  397. }
  398. }
  399. }
  400. }
  401. modelFileUrl = '';
  402. modelInputFile = '';
  403. modelTransferring = false;
  404. uploadProgress = null;
  405. models.set(await getModels());
  406. };
  407. const deleteModelHandler = async () => {
  408. const res = await fetch(`${API_BASE_URL}/delete`, {
  409. method: 'DELETE',
  410. headers: {
  411. 'Content-Type': 'text/event-stream',
  412. ...($settings.authHeader && { Authorization: $settings.authHeader }),
  413. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  414. },
  415. body: JSON.stringify({
  416. name: deleteModelTag
  417. })
  418. });
  419. const reader = res.body
  420. .pipeThrough(new TextDecoderStream())
  421. .pipeThrough(splitStream('\n'))
  422. .getReader();
  423. while (true) {
  424. const { value, done } = await reader.read();
  425. if (done) break;
  426. try {
  427. let lines = value.split('\n');
  428. for (const line of lines) {
  429. if (line !== '' && line !== 'null') {
  430. console.log(line);
  431. let data = JSON.parse(line);
  432. console.log(data);
  433. if (data.error) {
  434. throw data.error;
  435. }
  436. if (data.detail) {
  437. throw data.detail;
  438. }
  439. if (data.status) {
  440. }
  441. } else {
  442. toast.success(`Deleted ${deleteModelTag}`);
  443. }
  444. }
  445. } catch (error) {
  446. console.log(error);
  447. toast.error(error);
  448. }
  449. }
  450. deleteModelTag = '';
  451. models.set(await getModels());
  452. };
  453. const getModels = async (url = '', type = 'all') => {
  454. let models = [];
  455. const res = await fetch(`${url ? url : $settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/tags`, {
  456. method: 'GET',
  457. headers: {
  458. Accept: 'application/json',
  459. 'Content-Type': 'application/json',
  460. ...($settings.authHeader && { Authorization: $settings.authHeader }),
  461. ...($user && { Authorization: `Bearer ${localStorage.token}` })
  462. }
  463. })
  464. .then(async (res) => {
  465. if (!res.ok) throw await res.json();
  466. return res.json();
  467. })
  468. .catch((error) => {
  469. console.log(error);
  470. if ('detail' in error) {
  471. toast.error(error.detail);
  472. } else {
  473. toast.error('Server connection failed');
  474. }
  475. return null;
  476. });
  477. console.log(res);
  478. models.push(...(res?.models ?? []));
  479. // If OpenAI API Key exists
  480. if (type === 'all' && $settings.OPENAI_API_KEY) {
  481. const API_BASE_URL = $settings.OPENAI_API_BASE_URL ?? 'https://api.openai.com/v1';
  482. // Validate OPENAI_API_KEY
  483. const openaiModelRes = await fetch(`${API_BASE_URL}/models`, {
  484. method: 'GET',
  485. headers: {
  486. 'Content-Type': 'application/json',
  487. Authorization: `Bearer ${$settings.OPENAI_API_KEY}`
  488. }
  489. })
  490. .then(async (res) => {
  491. if (!res.ok) throw await res.json();
  492. return res.json();
  493. })
  494. .catch((error) => {
  495. console.log(error);
  496. toast.error(`OpenAI: ${error?.error?.message ?? 'Network Problem'}`);
  497. return null;
  498. });
  499. const openAIModels = Array.isArray(openaiModelRes)
  500. ? openaiModelRes
  501. : openaiModelRes?.data ?? null;
  502. models.push(
  503. ...(openAIModels
  504. ? [
  505. { name: 'hr' },
  506. ...openAIModels
  507. .map((model) => ({ name: model.id, external: true }))
  508. .filter((model) =>
  509. API_BASE_URL.includes('openai') ? model.name.includes('gpt') : true
  510. )
  511. ]
  512. : [])
  513. );
  514. }
  515. return models;
  516. };
  517. const updatePasswordHandler = async () => {
  518. if (newPassword === newPasswordConfirm) {
  519. const res = await updateUserPassword(localStorage.token, currentPassword, newPassword).catch(
  520. (error) => {
  521. toast.error(error);
  522. return null;
  523. }
  524. );
  525. if (res) {
  526. toast.success('Successfully updated.');
  527. }
  528. currentPassword = '';
  529. newPassword = '';
  530. newPasswordConfirm = '';
  531. } else {
  532. toast.error(
  533. `The passwords you entered don't quite match. Please double-check and try again.`
  534. );
  535. newPassword = '';
  536. newPasswordConfirm = '';
  537. }
  538. };
  539. onMount(async () => {
  540. let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
  541. console.log(settings);
  542. theme = localStorage.theme ?? 'dark';
  543. notificationEnabled = settings.notificationEnabled ?? false;
  544. API_BASE_URL = settings.API_BASE_URL ?? OLLAMA_API_BASE_URL;
  545. system = settings.system ?? '';
  546. requestFormat = settings.requestFormat ?? '';
  547. options.seed = settings.seed ?? 0;
  548. options.temperature = settings.temperature ?? '';
  549. options.repeat_penalty = settings.repeat_penalty ?? '';
  550. options.top_k = settings.top_k ?? '';
  551. options.top_p = settings.top_p ?? '';
  552. options.num_ctx = settings.num_ctx ?? '';
  553. options = { ...options, ...settings.options };
  554. options.stop = (settings?.options?.stop ?? []).join(',');
  555. titleAutoGenerate = settings.titleAutoGenerate ?? true;
  556. speechAutoSend = settings.speechAutoSend ?? false;
  557. responseAutoCopy = settings.responseAutoCopy ?? false;
  558. gravatarEmail = settings.gravatarEmail ?? '';
  559. OPENAI_API_KEY = settings.OPENAI_API_KEY ?? '';
  560. OPENAI_API_BASE_URL = settings.OPENAI_API_BASE_URL ?? 'https://api.openai.com/v1';
  561. authEnabled = settings.authHeader !== undefined ? true : false;
  562. if (authEnabled) {
  563. authType = settings.authHeader.split(' ')[0];
  564. authContent = settings.authHeader.split(' ')[1];
  565. }
  566. ollamaVersion = await getOllamaVersion(
  567. API_BASE_URL ?? OLLAMA_API_BASE_URL,
  568. localStorage.token
  569. ).catch((error) => {
  570. return '';
  571. });
  572. });
  573. </script>
  574. <Modal bind:show>
  575. <div>
  576. <div class=" flex justify-between dark:text-gray-300 px-5 py-4">
  577. <div class=" text-lg font-medium self-center">Settings</div>
  578. <button
  579. class="self-center"
  580. on:click={() => {
  581. show = false;
  582. }}
  583. >
  584. <svg
  585. xmlns="http://www.w3.org/2000/svg"
  586. viewBox="0 0 20 20"
  587. fill="currentColor"
  588. class="w-5 h-5"
  589. >
  590. <path
  591. 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"
  592. />
  593. </svg>
  594. </button>
  595. </div>
  596. <hr class=" dark:border-gray-800" />
  597. <div class="flex flex-col md:flex-row w-full p-4 md:space-x-4">
  598. <div
  599. 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"
  600. >
  601. <button
  602. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  603. 'general'
  604. ? 'bg-gray-200 dark:bg-gray-700'
  605. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  606. on:click={() => {
  607. selectedTab = 'general';
  608. }}
  609. >
  610. <div class=" self-center mr-2">
  611. <svg
  612. xmlns="http://www.w3.org/2000/svg"
  613. viewBox="0 0 20 20"
  614. fill="currentColor"
  615. class="w-4 h-4"
  616. >
  617. <path
  618. fill-rule="evenodd"
  619. 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"
  620. clip-rule="evenodd"
  621. />
  622. </svg>
  623. </div>
  624. <div class=" self-center">General</div>
  625. </button>
  626. <button
  627. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  628. 'advanced'
  629. ? 'bg-gray-200 dark:bg-gray-700'
  630. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  631. on:click={() => {
  632. selectedTab = 'advanced';
  633. }}
  634. >
  635. <div class=" self-center mr-2">
  636. <svg
  637. xmlns="http://www.w3.org/2000/svg"
  638. viewBox="0 0 20 20"
  639. fill="currentColor"
  640. class="w-4 h-4"
  641. >
  642. <path
  643. 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"
  644. />
  645. </svg>
  646. </div>
  647. <div class=" self-center">Advanced</div>
  648. </button>
  649. <button
  650. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  651. 'models'
  652. ? 'bg-gray-200 dark:bg-gray-700'
  653. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  654. on:click={() => {
  655. selectedTab = 'models';
  656. }}
  657. >
  658. <div class=" self-center mr-2">
  659. <svg
  660. xmlns="http://www.w3.org/2000/svg"
  661. viewBox="0 0 20 20"
  662. fill="currentColor"
  663. class="w-4 h-4"
  664. >
  665. <path
  666. fill-rule="evenodd"
  667. 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"
  668. clip-rule="evenodd"
  669. />
  670. </svg>
  671. </div>
  672. <div class=" self-center">Models</div>
  673. </button>
  674. <button
  675. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  676. 'external'
  677. ? 'bg-gray-200 dark:bg-gray-700'
  678. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  679. on:click={() => {
  680. selectedTab = 'external';
  681. }}
  682. >
  683. <div class=" self-center mr-2">
  684. <svg
  685. xmlns="http://www.w3.org/2000/svg"
  686. viewBox="0 0 16 16"
  687. fill="currentColor"
  688. class="w-4 h-4"
  689. >
  690. <path
  691. d="M1 9.5A3.5 3.5 0 0 0 4.5 13H12a3 3 0 0 0 .917-5.857 2.503 2.503 0 0 0-3.198-3.019 3.5 3.5 0 0 0-6.628 2.171A3.5 3.5 0 0 0 1 9.5Z"
  692. />
  693. </svg>
  694. </div>
  695. <div class=" self-center">External</div>
  696. </button>
  697. <button
  698. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  699. 'addons'
  700. ? 'bg-gray-200 dark:bg-gray-700'
  701. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  702. on:click={() => {
  703. selectedTab = 'addons';
  704. }}
  705. >
  706. <div class=" self-center mr-2">
  707. <svg
  708. xmlns="http://www.w3.org/2000/svg"
  709. viewBox="0 0 20 20"
  710. fill="currentColor"
  711. class="w-4 h-4"
  712. >
  713. <path
  714. 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"
  715. />
  716. </svg>
  717. </div>
  718. <div class=" self-center">Add-ons</div>
  719. </button>
  720. <button
  721. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  722. 'chats'
  723. ? 'bg-gray-200 dark:bg-gray-700'
  724. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  725. on:click={() => {
  726. selectedTab = 'chats';
  727. }}
  728. >
  729. <div class=" self-center mr-2">
  730. <svg
  731. xmlns="http://www.w3.org/2000/svg"
  732. viewBox="0 0 16 16"
  733. fill="currentColor"
  734. class="w-4 h-4"
  735. >
  736. <path
  737. fill-rule="evenodd"
  738. d="M8 2C4.262 2 1 4.57 1 8c0 1.86.98 3.486 2.455 4.566a3.472 3.472 0 0 1-.469 1.26.75.75 0 0 0 .713 1.14 6.961 6.961 0 0 0 3.06-1.06c.403.062.818.094 1.241.094 3.738 0 7-2.57 7-6s-3.262-6-7-6ZM5 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Zm7-1a1 1 0 1 1-2 0 1 1 0 0 1 2 0ZM8 9a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
  739. clip-rule="evenodd"
  740. />
  741. </svg>
  742. </div>
  743. <div class=" self-center">Chats</div>
  744. </button>
  745. {#if !$config || ($config && !$config.auth)}
  746. <button
  747. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  748. 'auth'
  749. ? 'bg-gray-200 dark:bg-gray-700'
  750. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  751. on:click={() => {
  752. selectedTab = 'auth';
  753. }}
  754. >
  755. <div class=" self-center mr-2">
  756. <svg
  757. xmlns="http://www.w3.org/2000/svg"
  758. viewBox="0 0 24 24"
  759. fill="currentColor"
  760. class="w-4 h-4"
  761. >
  762. <path
  763. fill-rule="evenodd"
  764. 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"
  765. clip-rule="evenodd"
  766. />
  767. </svg>
  768. </div>
  769. <div class=" self-center">Authentication</div>
  770. </button>
  771. {/if}
  772. <button
  773. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  774. 'account'
  775. ? 'bg-gray-200 dark:bg-gray-700'
  776. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  777. on:click={() => {
  778. selectedTab = 'account';
  779. }}
  780. >
  781. <div class=" self-center mr-2">
  782. <svg
  783. xmlns="http://www.w3.org/2000/svg"
  784. viewBox="0 0 16 16"
  785. fill="currentColor"
  786. class="w-4 h-4"
  787. >
  788. <path
  789. fill-rule="evenodd"
  790. d="M15 8A7 7 0 1 1 1 8a7 7 0 0 1 14 0Zm-5-2a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM8 9c-1.825 0-3.422.977-4.295 2.437A5.49 5.49 0 0 0 8 13.5a5.49 5.49 0 0 0 4.294-2.063A4.997 4.997 0 0 0 8 9Z"
  791. clip-rule="evenodd"
  792. />
  793. </svg>
  794. </div>
  795. <div class=" self-center">Account</div>
  796. </button>
  797. <button
  798. class="px-2.5 py-2.5 min-w-fit rounded-lg flex-1 md:flex-none flex text-right transition {selectedTab ===
  799. 'about'
  800. ? 'bg-gray-200 dark:bg-gray-700'
  801. : ' hover:bg-gray-300 dark:hover:bg-gray-800'}"
  802. on:click={() => {
  803. selectedTab = 'about';
  804. }}
  805. >
  806. <div class=" self-center mr-2">
  807. <svg
  808. xmlns="http://www.w3.org/2000/svg"
  809. viewBox="0 0 20 20"
  810. fill="currentColor"
  811. class="w-4 h-4"
  812. >
  813. <path
  814. fill-rule="evenodd"
  815. 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"
  816. clip-rule="evenodd"
  817. />
  818. </svg>
  819. </div>
  820. <div class=" self-center">About</div>
  821. </button>
  822. </div>
  823. <div class="flex-1 md:min-h-[340px]">
  824. {#if selectedTab === 'general'}
  825. <div class="flex flex-col space-y-3">
  826. <div>
  827. <div class=" mb-1 text-sm font-medium">WebUI Settings</div>
  828. <div class=" py-0.5 flex w-full justify-between">
  829. <div class=" self-center text-xs font-medium">Theme</div>
  830. <!-- <button
  831. class="p-1 px-3 text-xs flex rounded transition"
  832. on:click={() => {
  833. toggleTheme();
  834. }}
  835. >
  836. </button> -->
  837. <div class="flex items-center relative">
  838. <div class=" absolute right-16">
  839. {#if theme === 'dark'}
  840. <svg
  841. xmlns="http://www.w3.org/2000/svg"
  842. viewBox="0 0 20 20"
  843. fill="currentColor"
  844. class="w-4 h-4"
  845. >
  846. <path
  847. fill-rule="evenodd"
  848. 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"
  849. clip-rule="evenodd"
  850. />
  851. </svg>
  852. {:else if theme === 'light'}
  853. <svg
  854. xmlns="http://www.w3.org/2000/svg"
  855. viewBox="0 0 20 20"
  856. fill="currentColor"
  857. class="w-4 h-4 self-center"
  858. >
  859. <path
  860. 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"
  861. />
  862. </svg>
  863. {/if}
  864. </div>
  865. <select
  866. class="w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
  867. bind:value={theme}
  868. placeholder="Select a theme"
  869. on:change={(e) => {
  870. localStorage.theme = theme;
  871. themes
  872. .filter((e) => e !== theme)
  873. .forEach((e) => {
  874. e.split(' ').forEach((e) => {
  875. document.documentElement.classList.remove(e);
  876. });
  877. });
  878. theme.split(' ').forEach((e) => {
  879. document.documentElement.classList.add(e);
  880. });
  881. console.log(theme);
  882. }}
  883. >
  884. <option value="dark">Dark</option>
  885. <option value="light">Light</option>
  886. <option value="rose-pine dark">Rosé Pine</option>
  887. <option value="rose-pine-dawn light">Rosé Pine Dawn</option>
  888. </select>
  889. </div>
  890. </div>
  891. <div>
  892. <div class=" py-0.5 flex w-full justify-between">
  893. <div class=" self-center text-xs font-medium">Notification</div>
  894. <button
  895. class="p-1 px-3 text-xs flex rounded transition"
  896. on:click={() => {
  897. toggleNotification();
  898. }}
  899. type="button"
  900. >
  901. {#if notificationEnabled === true}
  902. <span class="ml-2 self-center">On</span>
  903. {:else}
  904. <span class="ml-2 self-center">Off</span>
  905. {/if}
  906. </button>
  907. </div>
  908. </div>
  909. </div>
  910. <hr class=" dark:border-gray-700" />
  911. <div>
  912. <div class=" mb-2.5 text-sm font-medium">Ollama API URL</div>
  913. <div class="flex w-full">
  914. <div class="flex-1 mr-2">
  915. <input
  916. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  917. placeholder="Enter URL (e.g. http://localhost:8080/ollama/api)"
  918. bind:value={API_BASE_URL}
  919. />
  920. </div>
  921. <button
  922. class="px-3 bg-gray-200 hover:bg-gray-300 dark:bg-gray-600 dark:hover:bg-gray-700 rounded transition"
  923. on:click={() => {
  924. checkOllamaConnection();
  925. }}
  926. >
  927. <svg
  928. xmlns="http://www.w3.org/2000/svg"
  929. viewBox="0 0 20 20"
  930. fill="currentColor"
  931. class="w-4 h-4"
  932. >
  933. <path
  934. fill-rule="evenodd"
  935. 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"
  936. clip-rule="evenodd"
  937. />
  938. </svg>
  939. </button>
  940. </div>
  941. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  942. The field above should be set to <span
  943. class=" text-gray-500 dark:text-gray-300 font-medium">'/ollama/api'</span
  944. >;
  945. <a
  946. class=" text-gray-500 dark:text-gray-300 font-medium"
  947. href="https://github.com/ollama-webui/ollama-webui#troubleshooting"
  948. target="_blank"
  949. >
  950. Click here for help.
  951. </a>
  952. </div>
  953. </div>
  954. <hr class=" dark:border-gray-700" />
  955. <div>
  956. <div class=" mb-2.5 text-sm font-medium">System Prompt</div>
  957. <textarea
  958. bind:value={system}
  959. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  960. rows="4"
  961. />
  962. </div>
  963. <div class="flex justify-end pt-3 text-sm font-medium">
  964. <button
  965. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  966. on:click={() => {
  967. saveSettings({
  968. API_BASE_URL: API_BASE_URL === '' ? OLLAMA_API_BASE_URL : API_BASE_URL,
  969. system: system !== '' ? system : undefined
  970. });
  971. show = false;
  972. }}
  973. >
  974. Save
  975. </button>
  976. </div>
  977. </div>
  978. {:else if selectedTab === 'advanced'}
  979. <div class="flex flex-col h-full justify-between text-sm">
  980. <div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-72">
  981. <div class=" text-sm font-medium">Parameters</div>
  982. <Advanced bind:options />
  983. <hr class=" dark:border-gray-700" />
  984. <div>
  985. <div class=" py-1 flex w-full justify-between">
  986. <div class=" self-center text-sm font-medium">Request Mode</div>
  987. <button
  988. class="p-1 px-3 text-xs flex rounded transition"
  989. on:click={() => {
  990. toggleRequestFormat();
  991. }}
  992. >
  993. {#if requestFormat === ''}
  994. <span class="ml-2 self-center"> Default </span>
  995. {:else if requestFormat === 'json'}
  996. <!-- <svg
  997. xmlns="http://www.w3.org/2000/svg"
  998. viewBox="0 0 20 20"
  999. fill="currentColor"
  1000. class="w-4 h-4 self-center"
  1001. >
  1002. <path
  1003. 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"
  1004. />
  1005. </svg> -->
  1006. <span class="ml-2 self-center"> JSON </span>
  1007. {/if}
  1008. </button>
  1009. </div>
  1010. </div>
  1011. </div>
  1012. <div class="flex justify-end pt-3 text-sm font-medium">
  1013. <button
  1014. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  1015. on:click={() => {
  1016. saveSettings({
  1017. options: {
  1018. seed: (options.seed !== 0 ? options.seed : undefined) ?? undefined,
  1019. stop:
  1020. options.stop !== '' ? options.stop.split(',').filter((e) => e) : undefined,
  1021. temperature: options.temperature !== '' ? options.temperature : undefined,
  1022. repeat_penalty:
  1023. options.repeat_penalty !== '' ? options.repeat_penalty : undefined,
  1024. repeat_last_n:
  1025. options.repeat_last_n !== '' ? options.repeat_last_n : undefined,
  1026. mirostat: options.mirostat !== '' ? options.mirostat : undefined,
  1027. mirostat_eta: options.mirostat_eta !== '' ? options.mirostat_eta : undefined,
  1028. mirostat_tau: options.mirostat_tau !== '' ? options.mirostat_tau : undefined,
  1029. top_k: options.top_k !== '' ? options.top_k : undefined,
  1030. top_p: options.top_p !== '' ? options.top_p : undefined,
  1031. tfs_z: options.tfs_z !== '' ? options.tfs_z : undefined,
  1032. num_ctx: options.num_ctx !== '' ? options.num_ctx : undefined,
  1033. num_predict: options.num_predict !== '' ? options.num_predict : undefined
  1034. }
  1035. });
  1036. show = false;
  1037. }}
  1038. >
  1039. Save
  1040. </button>
  1041. </div>
  1042. </div>
  1043. {:else if selectedTab === 'models'}
  1044. <div class="flex flex-col h-full justify-between text-sm">
  1045. <div class=" space-y-3 pr-1.5 overflow-y-scroll h-80">
  1046. <div>
  1047. <div class=" mb-2.5 text-sm font-medium">Pull a model from Ollama.ai</div>
  1048. <div class="flex w-full">
  1049. <div class="flex-1 mr-2">
  1050. <input
  1051. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1052. placeholder="Enter model tag (e.g. mistral:7b)"
  1053. bind:value={modelTag}
  1054. />
  1055. </div>
  1056. <button
  1057. class="px-3 text-gray-100 bg-emerald-600 hover:bg-emerald-700 disabled:bg-gray-700 disabled:cursor-not-allowed rounded transition"
  1058. on:click={() => {
  1059. pullModelHandler();
  1060. }}
  1061. disabled={modelTransferring}
  1062. >
  1063. {#if modelTransferring}
  1064. <div class="self-center">
  1065. <svg
  1066. class=" w-4 h-4"
  1067. viewBox="0 0 24 24"
  1068. fill="currentColor"
  1069. xmlns="http://www.w3.org/2000/svg"
  1070. ><style>
  1071. .spinner_ajPY {
  1072. transform-origin: center;
  1073. animation: spinner_AtaB 0.75s infinite linear;
  1074. }
  1075. @keyframes spinner_AtaB {
  1076. 100% {
  1077. transform: rotate(360deg);
  1078. }
  1079. }
  1080. </style><path
  1081. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  1082. opacity=".25"
  1083. /><path
  1084. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  1085. class="spinner_ajPY"
  1086. /></svg
  1087. >
  1088. </div>
  1089. {:else}
  1090. <svg
  1091. xmlns="http://www.w3.org/2000/svg"
  1092. viewBox="0 0 16 16"
  1093. fill="currentColor"
  1094. class="w-4 h-4"
  1095. >
  1096. <path
  1097. d="M8.75 2.75a.75.75 0 0 0-1.5 0v5.69L5.03 6.22a.75.75 0 0 0-1.06 1.06l3.5 3.5a.75.75 0 0 0 1.06 0l3.5-3.5a.75.75 0 0 0-1.06-1.06L8.75 8.44V2.75Z"
  1098. />
  1099. <path
  1100. d="M3.5 9.75a.75.75 0 0 0-1.5 0v1.5A2.75 2.75 0 0 0 4.75 14h6.5A2.75 2.75 0 0 0 14 11.25v-1.5a.75.75 0 0 0-1.5 0v1.5c0 .69-.56 1.25-1.25 1.25h-6.5c-.69 0-1.25-.56-1.25-1.25v-1.5Z"
  1101. />
  1102. </svg>
  1103. {/if}
  1104. </button>
  1105. </div>
  1106. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  1107. To access the available model names for downloading, <a
  1108. class=" text-gray-500 dark:text-gray-300 font-medium"
  1109. href="https://ollama.ai/library"
  1110. target="_blank">click here.</a
  1111. >
  1112. </div>
  1113. {#if pullProgress !== null}
  1114. <div class="mt-2">
  1115. <div class=" mb-2 text-xs">Pull Progress</div>
  1116. <div class="w-full rounded-full dark:bg-gray-800">
  1117. <div
  1118. class="dark:bg-gray-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full"
  1119. style="width: {Math.max(15, pullProgress ?? 0)}%"
  1120. >
  1121. {pullProgress ?? 0}%
  1122. </div>
  1123. </div>
  1124. <div class="mt-1 text-xs dark:text-gray-500" style="font-size: 0.5rem;">
  1125. {digest}
  1126. </div>
  1127. </div>
  1128. {/if}
  1129. </div>
  1130. <hr class=" dark:border-gray-700" />
  1131. <div>
  1132. <div class=" mb-2.5 text-sm font-medium">Delete a model</div>
  1133. <div class="flex w-full">
  1134. <div class="flex-1 mr-2">
  1135. <select
  1136. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1137. bind:value={deleteModelTag}
  1138. placeholder="Select a model"
  1139. >
  1140. {#if !deleteModelTag}
  1141. <option value="" disabled selected>Select a model</option>
  1142. {/if}
  1143. {#each $models.filter((m) => m.size != null) as model}
  1144. <option value={model.name} class="bg-gray-100 dark:bg-gray-700"
  1145. >{model.name +
  1146. ' (' +
  1147. (model.size / 1024 ** 3).toFixed(1) +
  1148. ' GB)'}</option
  1149. >
  1150. {/each}
  1151. </select>
  1152. </div>
  1153. <button
  1154. class="px-3 bg-red-700 hover:bg-red-800 text-gray-100 rounded transition"
  1155. on:click={() => {
  1156. deleteModelHandler();
  1157. }}
  1158. >
  1159. <svg
  1160. xmlns="http://www.w3.org/2000/svg"
  1161. viewBox="0 0 16 16"
  1162. fill="currentColor"
  1163. class="w-4 h-4"
  1164. >
  1165. <path
  1166. fill-rule="evenodd"
  1167. d="M5 3.25V4H2.75a.75.75 0 0 0 0 1.5h.3l.815 8.15A1.5 1.5 0 0 0 5.357 15h5.285a1.5 1.5 0 0 0 1.493-1.35l.815-8.15h.3a.75.75 0 0 0 0-1.5H11v-.75A2.25 2.25 0 0 0 8.75 1h-1.5A2.25 2.25 0 0 0 5 3.25Zm2.25-.75a.75.75 0 0 0-.75.75V4h3v-.75a.75.75 0 0 0-.75-.75h-1.5ZM6.05 6a.75.75 0 0 1 .787.713l.275 5.5a.75.75 0 0 1-1.498.075l-.275-5.5A.75.75 0 0 1 6.05 6Zm3.9 0a.75.75 0 0 1 .712.787l-.275 5.5a.75.75 0 0 1-1.498-.075l.275-5.5a.75.75 0 0 1 .786-.711Z"
  1168. clip-rule="evenodd"
  1169. />
  1170. </svg>
  1171. </button>
  1172. </div>
  1173. </div>
  1174. <hr class=" dark:border-gray-700" />
  1175. <form
  1176. on:submit|preventDefault={() => {
  1177. uploadModelHandler();
  1178. }}
  1179. >
  1180. <div class=" mb-2 flex w-full justify-between">
  1181. <div class=" text-sm font-medium">
  1182. Upload a GGUF model <a
  1183. class=" text-xs font-medium text-gray-500 underline"
  1184. href="https://github.com/jmorganca/ollama/blob/main/README.md#import-from-gguf"
  1185. target="_blank">(Experimental)</a
  1186. >
  1187. </div>
  1188. <button
  1189. class="p-1 px-3 text-xs flex rounded transition"
  1190. on:click={() => {
  1191. if (modelUploadMode === 'file') {
  1192. modelUploadMode = 'url';
  1193. } else {
  1194. modelUploadMode = 'file';
  1195. }
  1196. }}
  1197. type="button"
  1198. >
  1199. {#if modelUploadMode === 'file'}
  1200. <span class="ml-2 self-center">File Mode</span>
  1201. {:else}
  1202. <span class="ml-2 self-center">URL Mode</span>
  1203. {/if}
  1204. </button>
  1205. </div>
  1206. <div class="flex w-full mb-1.5">
  1207. <div class="flex flex-col w-full">
  1208. {#if modelUploadMode === 'file'}
  1209. <div
  1210. class="flex-1 {modelInputFile && modelInputFile.length > 0 ? 'mr-2' : ''}"
  1211. >
  1212. <input
  1213. id="model-upload-input"
  1214. type="file"
  1215. bind:files={modelInputFile}
  1216. on:change={() => {
  1217. console.log(modelInputFile);
  1218. }}
  1219. accept=".gguf"
  1220. required
  1221. hidden
  1222. />
  1223. <button
  1224. type="button"
  1225. class="w-full rounded text-left py-2 px-4 dark:text-gray-300 dark:bg-gray-800"
  1226. on:click={() => {
  1227. document.getElementById('model-upload-input').click();
  1228. }}
  1229. >
  1230. {#if modelInputFile && modelInputFile.length > 0}
  1231. {modelInputFile[0].name}
  1232. {:else}
  1233. Click here to select
  1234. {/if}
  1235. </button>
  1236. </div>
  1237. {:else}
  1238. <div class="flex-1 {modelFileUrl !== '' ? 'mr-2' : ''}">
  1239. <input
  1240. class="w-full rounded text-left py-2 px-4 dark:text-gray-300 dark:bg-gray-800 outline-none {modelFileUrl !==
  1241. ''
  1242. ? 'mr-2'
  1243. : ''}"
  1244. type="url"
  1245. required
  1246. bind:value={modelFileUrl}
  1247. placeholder="Type HuggingFace Resolve (Download) URL"
  1248. />
  1249. </div>
  1250. {/if}
  1251. </div>
  1252. {#if (modelUploadMode === 'file' && modelInputFile && modelInputFile.length > 0) || (modelUploadMode === 'url' && modelFileUrl !== '')}
  1253. <button
  1254. class="px-3 text-gray-100 bg-emerald-600 hover:bg-emerald-700 disabled:bg-gray-700 disabled:cursor-not-allowed rounded transition"
  1255. type="submit"
  1256. disabled={modelTransferring}
  1257. >
  1258. {#if modelTransferring}
  1259. <div class="self-center">
  1260. <svg
  1261. class=" w-4 h-4"
  1262. viewBox="0 0 24 24"
  1263. fill="currentColor"
  1264. xmlns="http://www.w3.org/2000/svg"
  1265. ><style>
  1266. .spinner_ajPY {
  1267. transform-origin: center;
  1268. animation: spinner_AtaB 0.75s infinite linear;
  1269. }
  1270. @keyframes spinner_AtaB {
  1271. 100% {
  1272. transform: rotate(360deg);
  1273. }
  1274. }
  1275. </style><path
  1276. d="M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"
  1277. opacity=".25"
  1278. /><path
  1279. d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
  1280. class="spinner_ajPY"
  1281. /></svg
  1282. >
  1283. </div>
  1284. {:else}
  1285. <svg
  1286. xmlns="http://www.w3.org/2000/svg"
  1287. viewBox="0 0 16 16"
  1288. fill="currentColor"
  1289. class="w-4 h-4"
  1290. >
  1291. <path
  1292. d="M7.25 10.25a.75.75 0 0 0 1.5 0V4.56l2.22 2.22a.75.75 0 1 0 1.06-1.06l-3.5-3.5a.75.75 0 0 0-1.06 0l-3.5 3.5a.75.75 0 0 0 1.06 1.06l2.22-2.22v5.69Z"
  1293. />
  1294. <path
  1295. d="M3.5 9.75a.75.75 0 0 0-1.5 0v1.5A2.75 2.75 0 0 0 4.75 14h6.5A2.75 2.75 0 0 0 14 11.25v-1.5a.75.75 0 0 0-1.5 0v1.5c0 .69-.56 1.25-1.25 1.25h-6.5c-.69 0-1.25-.56-1.25-1.25v-1.5Z"
  1296. />
  1297. </svg>
  1298. {/if}
  1299. </button>
  1300. {/if}
  1301. </div>
  1302. {#if (modelUploadMode === 'file' && modelInputFile && modelInputFile.length > 0) || (modelUploadMode === 'url' && modelFileUrl !== '')}
  1303. <div>
  1304. <div>
  1305. <div class=" my-2.5 text-sm font-medium">Modelfile Content</div>
  1306. <textarea
  1307. bind:value={modelFileContent}
  1308. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  1309. rows="6"
  1310. />
  1311. </div>
  1312. </div>
  1313. {/if}
  1314. <div class=" mt-1 text-xs text-gray-400 dark:text-gray-500">
  1315. To access the GGUF models available for downloading, <a
  1316. class=" text-gray-500 dark:text-gray-300 font-medium"
  1317. href="https://huggingface.co/models?search=gguf"
  1318. target="_blank">click here.</a
  1319. >
  1320. </div>
  1321. {#if uploadProgress !== null}
  1322. <div class="mt-2">
  1323. <div class=" mb-2 text-xs">Upload Progress</div>
  1324. <div class="w-full rounded-full dark:bg-gray-800">
  1325. <div
  1326. class="dark:bg-gray-600 text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full"
  1327. style="width: {Math.max(15, uploadProgress ?? 0)}%"
  1328. >
  1329. {uploadProgress ?? 0}%
  1330. </div>
  1331. </div>
  1332. <div class="mt-1 text-xs dark:text-gray-500" style="font-size: 0.5rem;">
  1333. {modelFileDigest}
  1334. </div>
  1335. </div>
  1336. {/if}
  1337. </form>
  1338. </div>
  1339. </div>
  1340. {:else if selectedTab === 'external'}
  1341. <form
  1342. class="flex flex-col h-full justify-between space-y-3 text-sm"
  1343. on:submit|preventDefault={() => {
  1344. saveSettings({
  1345. OPENAI_API_KEY: OPENAI_API_KEY !== '' ? OPENAI_API_KEY : undefined,
  1346. OPENAI_API_BASE_URL: OPENAI_API_BASE_URL !== '' ? OPENAI_API_BASE_URL : undefined
  1347. });
  1348. show = false;
  1349. }}
  1350. >
  1351. <div class=" space-y-3">
  1352. <div>
  1353. <div class=" mb-2.5 text-sm font-medium">OpenAI API Key</div>
  1354. <div class="flex w-full">
  1355. <div class="flex-1">
  1356. <input
  1357. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1358. placeholder="Enter OpenAI API Key"
  1359. bind:value={OPENAI_API_KEY}
  1360. autocomplete="off"
  1361. />
  1362. </div>
  1363. </div>
  1364. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  1365. Adds optional support for online models.
  1366. </div>
  1367. </div>
  1368. <hr class=" dark:border-gray-700" />
  1369. <div>
  1370. <div class=" mb-2.5 text-sm font-medium">OpenAI API Base URL</div>
  1371. <div class="flex w-full">
  1372. <div class="flex-1">
  1373. <input
  1374. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1375. placeholder="Enter OpenAI API Key"
  1376. bind:value={OPENAI_API_BASE_URL}
  1377. autocomplete="off"
  1378. />
  1379. </div>
  1380. </div>
  1381. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  1382. WebUI will make requests to <span class=" text-gray-200"
  1383. >'{OPENAI_API_BASE_URL}/chat'</span
  1384. >
  1385. </div>
  1386. </div>
  1387. </div>
  1388. <div class="flex justify-end pt-3 text-sm font-medium">
  1389. <button
  1390. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  1391. type="submit"
  1392. >
  1393. Save
  1394. </button>
  1395. </div>
  1396. </form>
  1397. {:else if selectedTab === 'addons'}
  1398. <form
  1399. class="flex flex-col h-full justify-between space-y-3 text-sm"
  1400. on:submit|preventDefault={() => {
  1401. saveSettings({
  1402. gravatarEmail: gravatarEmail !== '' ? gravatarEmail : undefined,
  1403. gravatarUrl: gravatarEmail !== '' ? getGravatarURL(gravatarEmail) : undefined
  1404. });
  1405. show = false;
  1406. }}
  1407. >
  1408. <div class=" space-y-3">
  1409. <div>
  1410. <div class=" mb-1 text-sm font-medium">WebUI Add-ons</div>
  1411. <div>
  1412. <div class=" py-0.5 flex w-full justify-between">
  1413. <div class=" self-center text-xs font-medium">Title Auto Generation</div>
  1414. <button
  1415. class="p-1 px-3 text-xs flex rounded transition"
  1416. on:click={() => {
  1417. toggleTitleAutoGenerate();
  1418. }}
  1419. type="button"
  1420. >
  1421. {#if titleAutoGenerate === true}
  1422. <span class="ml-2 self-center">On</span>
  1423. {:else}
  1424. <span class="ml-2 self-center">Off</span>
  1425. {/if}
  1426. </button>
  1427. </div>
  1428. </div>
  1429. <div>
  1430. <div class=" py-0.5 flex w-full justify-between">
  1431. <div class=" self-center text-xs font-medium">Voice Input Auto-Send</div>
  1432. <button
  1433. class="p-1 px-3 text-xs flex rounded transition"
  1434. on:click={() => {
  1435. toggleSpeechAutoSend();
  1436. }}
  1437. type="button"
  1438. >
  1439. {#if speechAutoSend === true}
  1440. <span class="ml-2 self-center">On</span>
  1441. {:else}
  1442. <span class="ml-2 self-center">Off</span>
  1443. {/if}
  1444. </button>
  1445. </div>
  1446. </div>
  1447. <div>
  1448. <div class=" py-0.5 flex w-full justify-between">
  1449. <div class=" self-center text-xs font-medium">
  1450. Response AutoCopy to Clipboard
  1451. </div>
  1452. <button
  1453. class="p-1 px-3 text-xs flex rounded transition"
  1454. on:click={() => {
  1455. toggleResponseAutoCopy();
  1456. }}
  1457. type="button"
  1458. >
  1459. {#if responseAutoCopy === true}
  1460. <span class="ml-2 self-center">On</span>
  1461. {:else}
  1462. <span class="ml-2 self-center">Off</span>
  1463. {/if}
  1464. </button>
  1465. </div>
  1466. </div>
  1467. </div>
  1468. <hr class=" dark:border-gray-700" />
  1469. <div>
  1470. <div class=" mb-2.5 text-sm font-medium">
  1471. Gravatar Email <span class=" text-gray-400 text-sm">(optional)</span>
  1472. </div>
  1473. <div class="flex w-full">
  1474. <div class="flex-1">
  1475. <input
  1476. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1477. placeholder="Enter Your Email"
  1478. bind:value={gravatarEmail}
  1479. autocomplete="off"
  1480. type="email"
  1481. />
  1482. </div>
  1483. </div>
  1484. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  1485. Changes user profile image to match your <a
  1486. class=" text-gray-500 dark:text-gray-300 font-medium"
  1487. href="https://gravatar.com/"
  1488. target="_blank">Gravatar.</a
  1489. >
  1490. </div>
  1491. </div>
  1492. </div>
  1493. <div class="flex justify-end pt-3 text-sm font-medium">
  1494. <button
  1495. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  1496. type="submit"
  1497. >
  1498. Save
  1499. </button>
  1500. </div>
  1501. </form>
  1502. {:else if selectedTab === 'chats'}
  1503. <div class="flex flex-col h-full justify-between space-y-3 text-sm">
  1504. <div class=" space-y-2">
  1505. <div class="flex flex-col">
  1506. <input
  1507. id="chat-import-input"
  1508. bind:files={importFiles}
  1509. type="file"
  1510. accept=".json"
  1511. hidden
  1512. />
  1513. <button
  1514. class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  1515. on:click={() => {
  1516. document.getElementById('chat-import-input').click();
  1517. }}
  1518. >
  1519. <div class=" self-center mr-3">
  1520. <svg
  1521. xmlns="http://www.w3.org/2000/svg"
  1522. viewBox="0 0 16 16"
  1523. fill="currentColor"
  1524. class="w-4 h-4"
  1525. >
  1526. <path
  1527. fill-rule="evenodd"
  1528. d="M4 2a1.5 1.5 0 0 0-1.5 1.5v9A1.5 1.5 0 0 0 4 14h8a1.5 1.5 0 0 0 1.5-1.5V6.621a1.5 1.5 0 0 0-.44-1.06L9.94 2.439A1.5 1.5 0 0 0 8.878 2H4Zm4 9.5a.75.75 0 0 1-.75-.75V8.06l-.72.72a.75.75 0 0 1-1.06-1.06l2-2a.75.75 0 0 1 1.06 0l2 2a.75.75 0 1 1-1.06 1.06l-.72-.72v2.69a.75.75 0 0 1-.75.75Z"
  1529. clip-rule="evenodd"
  1530. />
  1531. </svg>
  1532. </div>
  1533. <div class=" self-center text-sm font-medium">Import Chats</div>
  1534. </button>
  1535. <button
  1536. class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  1537. on:click={() => {
  1538. exportChats();
  1539. }}
  1540. >
  1541. <div class=" self-center mr-3">
  1542. <svg
  1543. xmlns="http://www.w3.org/2000/svg"
  1544. viewBox="0 0 16 16"
  1545. fill="currentColor"
  1546. class="w-4 h-4"
  1547. >
  1548. <path
  1549. fill-rule="evenodd"
  1550. d="M4 2a1.5 1.5 0 0 0-1.5 1.5v9A1.5 1.5 0 0 0 4 14h8a1.5 1.5 0 0 0 1.5-1.5V6.621a1.5 1.5 0 0 0-.44-1.06L9.94 2.439A1.5 1.5 0 0 0 8.878 2H4Zm4 3.5a.75.75 0 0 1 .75.75v2.69l.72-.72a.75.75 0 1 1 1.06 1.06l-2 2a.75.75 0 0 1-1.06 0l-2-2a.75.75 0 0 1 1.06-1.06l.72.72V6.25A.75.75 0 0 1 8 5.5Z"
  1551. clip-rule="evenodd"
  1552. />
  1553. </svg>
  1554. </div>
  1555. <div class=" self-center text-sm font-medium">Export Chats</div>
  1556. </button>
  1557. </div>
  1558. <hr class=" dark:border-gray-700" />
  1559. {#if showDeleteConfirm}
  1560. <div
  1561. class="flex justify-between rounded-md items-center py-2 px-3.5 w-full transition"
  1562. >
  1563. <div class="flex items-center space-x-3">
  1564. <svg
  1565. xmlns="http://www.w3.org/2000/svg"
  1566. viewBox="0 0 16 16"
  1567. fill="currentColor"
  1568. class="w-4 h-4"
  1569. >
  1570. <path
  1571. d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z"
  1572. />
  1573. <path
  1574. fill-rule="evenodd"
  1575. d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM5.72 7.47a.75.75 0 0 1 1.06 0L8 8.69l1.22-1.22a.75.75 0 1 1 1.06 1.06L9.06 9.75l1.22 1.22a.75.75 0 1 1-1.06 1.06L8 10.81l-1.22 1.22a.75.75 0 0 1-1.06-1.06l1.22-1.22-1.22-1.22a.75.75 0 0 1 0-1.06Z"
  1576. clip-rule="evenodd"
  1577. />
  1578. </svg>
  1579. <span>Are you sure?</span>
  1580. </div>
  1581. <div class="flex space-x-1.5 items-center">
  1582. <button
  1583. class="hover:text-white transition"
  1584. on:click={() => {
  1585. deleteChats();
  1586. showDeleteConfirm = false;
  1587. }}
  1588. >
  1589. <svg
  1590. xmlns="http://www.w3.org/2000/svg"
  1591. viewBox="0 0 20 20"
  1592. fill="currentColor"
  1593. class="w-4 h-4"
  1594. >
  1595. <path
  1596. fill-rule="evenodd"
  1597. d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
  1598. clip-rule="evenodd"
  1599. />
  1600. </svg>
  1601. </button>
  1602. <button
  1603. class="hover:text-white transition"
  1604. on:click={() => {
  1605. showDeleteConfirm = false;
  1606. }}
  1607. >
  1608. <svg
  1609. xmlns="http://www.w3.org/2000/svg"
  1610. viewBox="0 0 20 20"
  1611. fill="currentColor"
  1612. class="w-4 h-4"
  1613. >
  1614. <path
  1615. 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"
  1616. />
  1617. </svg>
  1618. </button>
  1619. </div>
  1620. </div>
  1621. {:else}
  1622. <button
  1623. class=" flex rounded-md py-2 px-3.5 w-full hover:bg-gray-200 dark:hover:bg-gray-800 transition"
  1624. on:click={() => {
  1625. showDeleteConfirm = true;
  1626. }}
  1627. >
  1628. <div class=" self-center mr-3">
  1629. <svg
  1630. xmlns="http://www.w3.org/2000/svg"
  1631. viewBox="0 0 16 16"
  1632. fill="currentColor"
  1633. class="w-4 h-4"
  1634. >
  1635. <path
  1636. d="M2 3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3Z"
  1637. />
  1638. <path
  1639. fill-rule="evenodd"
  1640. d="M13 6H3v6a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V6ZM5.72 7.47a.75.75 0 0 1 1.06 0L8 8.69l1.22-1.22a.75.75 0 1 1 1.06 1.06L9.06 9.75l1.22 1.22a.75.75 0 1 1-1.06 1.06L8 10.81l-1.22 1.22a.75.75 0 0 1-1.06-1.06l1.22-1.22-1.22-1.22a.75.75 0 0 1 0-1.06Z"
  1641. clip-rule="evenodd"
  1642. />
  1643. </svg>
  1644. </div>
  1645. <div class=" self-center text-sm font-medium">Delete All Chats</div>
  1646. </button>
  1647. {/if}
  1648. </div>
  1649. </div>
  1650. {:else if selectedTab === 'auth'}
  1651. <form
  1652. class="flex flex-col h-full justify-between space-y-3 text-sm"
  1653. on:submit|preventDefault={() => {
  1654. console.log('auth save');
  1655. saveSettings({
  1656. authHeader: authEnabled ? `${authType} ${authContent}` : undefined
  1657. });
  1658. show = false;
  1659. }}
  1660. >
  1661. <div class=" space-y-3">
  1662. <div>
  1663. <div class=" py-1 flex w-full justify-between">
  1664. <div class=" self-center text-sm font-medium">Authorization Header</div>
  1665. <button
  1666. class="p-1 px-3 text-xs flex rounded transition"
  1667. type="button"
  1668. on:click={() => {
  1669. toggleAuthHeader();
  1670. }}
  1671. >
  1672. {#if authEnabled === true}
  1673. <svg
  1674. xmlns="http://www.w3.org/2000/svg"
  1675. viewBox="0 0 24 24"
  1676. fill="currentColor"
  1677. class="w-4 h-4"
  1678. >
  1679. <path
  1680. fill-rule="evenodd"
  1681. 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"
  1682. clip-rule="evenodd"
  1683. />
  1684. </svg>
  1685. <span class="ml-2 self-center"> On </span>
  1686. {:else}
  1687. <svg
  1688. xmlns="http://www.w3.org/2000/svg"
  1689. viewBox="0 0 24 24"
  1690. fill="currentColor"
  1691. class="w-4 h-4"
  1692. >
  1693. <path
  1694. 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"
  1695. />
  1696. </svg>
  1697. <span class="ml-2 self-center">Off</span>
  1698. {/if}
  1699. </button>
  1700. </div>
  1701. </div>
  1702. {#if authEnabled}
  1703. <hr class=" dark:border-gray-700" />
  1704. <div class="mt-2">
  1705. <div class=" py-1 flex w-full space-x-2">
  1706. <button
  1707. class=" py-1 font-semibold flex rounded transition"
  1708. on:click={() => {
  1709. authType = authType === 'Basic' ? 'Bearer' : 'Basic';
  1710. }}
  1711. type="button"
  1712. >
  1713. {#if authType === 'Basic'}
  1714. <span class="self-center mr-2">Basic</span>
  1715. {:else if authType === 'Bearer'}
  1716. <span class="self-center mr-2">Bearer</span>
  1717. {/if}
  1718. </button>
  1719. <div class="flex-1">
  1720. <input
  1721. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1722. placeholder="Enter Authorization Header Content"
  1723. bind:value={authContent}
  1724. />
  1725. </div>
  1726. </div>
  1727. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  1728. Toggle between <span class=" text-gray-500 dark:text-gray-300 font-medium"
  1729. >'Basic'</span
  1730. >
  1731. and <span class=" text-gray-500 dark:text-gray-300 font-medium">'Bearer'</span> by
  1732. clicking on the label next to the input.
  1733. </div>
  1734. </div>
  1735. <hr class=" dark:border-gray-700" />
  1736. <div>
  1737. <div class=" mb-2.5 text-sm font-medium">Preview Authorization Header</div>
  1738. <textarea
  1739. value={JSON.stringify({
  1740. Authorization: `${authType} ${authContent}`
  1741. })}
  1742. class="w-full rounded p-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none resize-none"
  1743. rows="2"
  1744. disabled
  1745. />
  1746. </div>
  1747. {/if}
  1748. </div>
  1749. <div class="flex justify-end pt-3 text-sm font-medium">
  1750. <button
  1751. class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
  1752. type="submit"
  1753. >
  1754. Save
  1755. </button>
  1756. </div>
  1757. </form>
  1758. {:else if selectedTab === 'account'}
  1759. <form
  1760. class="flex flex-col h-full text-sm"
  1761. on:submit|preventDefault={() => {
  1762. updatePasswordHandler();
  1763. }}
  1764. >
  1765. <div class=" mb-2.5 font-medium">Change Password</div>
  1766. <div class=" space-y-1.5">
  1767. <div class="flex flex-col w-full">
  1768. <div class=" mb-1 text-xs text-gray-500">Current Password</div>
  1769. <div class="flex-1">
  1770. <input
  1771. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1772. type="password"
  1773. bind:value={currentPassword}
  1774. autocomplete="current-password"
  1775. required
  1776. />
  1777. </div>
  1778. </div>
  1779. <div class="flex flex-col w-full">
  1780. <div class=" mb-1 text-xs text-gray-500">New Password</div>
  1781. <div class="flex-1">
  1782. <input
  1783. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1784. type="password"
  1785. bind:value={newPassword}
  1786. autocomplete="new-password"
  1787. required
  1788. />
  1789. </div>
  1790. </div>
  1791. <div class="flex flex-col w-full">
  1792. <div class=" mb-1 text-xs text-gray-500">Confirm Password</div>
  1793. <div class="flex-1">
  1794. <input
  1795. class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
  1796. type="password"
  1797. bind:value={newPasswordConfirm}
  1798. autocomplete="off"
  1799. required
  1800. />
  1801. </div>
  1802. </div>
  1803. </div>
  1804. <div class="mt-3 flex justify-end">
  1805. <button
  1806. class=" px-4 py-2 text-xs bg-gray-800 hover:bg-gray-900 dark:bg-gray-700 dark:hover:bg-gray-800 text-gray-100 transition rounded-md font-medium"
  1807. >
  1808. Update password
  1809. </button>
  1810. </div>
  1811. </form>
  1812. {:else if selectedTab === 'about'}
  1813. <div class="flex flex-col h-full justify-between space-y-3 text-sm mb-6">
  1814. <div class=" space-y-3">
  1815. <div>
  1816. <div class=" mb-2.5 text-sm font-medium">Ollama Web UI Version</div>
  1817. <div class="flex w-full">
  1818. <div class="flex-1 text-xs text-gray-700 dark:text-gray-200">
  1819. {$config && $config.version ? $config.version : WEB_UI_VERSION}
  1820. </div>
  1821. </div>
  1822. </div>
  1823. <hr class=" dark:border-gray-700" />
  1824. <div>
  1825. <div class=" mb-2.5 text-sm font-medium">Ollama Version</div>
  1826. <div class="flex w-full">
  1827. <div class="flex-1 text-xs text-gray-700 dark:text-gray-200">
  1828. {ollamaVersion ?? 'N/A'}
  1829. </div>
  1830. </div>
  1831. </div>
  1832. <hr class=" dark:border-gray-700" />
  1833. <div class="flex space-x-1">
  1834. <a href="https://discord.gg/5rJgQTnV4s" target="_blank">
  1835. <img
  1836. alt="Discord"
  1837. src="https://img.shields.io/badge/Discord-Ollama_Web_UI-blue?logo=discord&logoColor=white"
  1838. />
  1839. </a>
  1840. <a href="https://github.com/ollama-webui/ollama-webui" target="_blank">
  1841. <img
  1842. alt="Github Repo"
  1843. src="https://img.shields.io/github/stars/ollama-webui/ollama-webui?style=social&label=Star us on Github"
  1844. />
  1845. </a>
  1846. </div>
  1847. <div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
  1848. Created by <a
  1849. class=" text-gray-500 dark:text-gray-300 font-medium"
  1850. href="https://github.com/tjbck"
  1851. target="_blank">Timothy J. Baek</a
  1852. >
  1853. </div>
  1854. </div>
  1855. </div>
  1856. {/if}
  1857. </div>
  1858. </div>
  1859. </div>
  1860. </Modal>
  1861. <style>
  1862. input::-webkit-outer-spin-button,
  1863. input::-webkit-inner-spin-button {
  1864. /* display: none; <- Crashes Chrome on hover */
  1865. -webkit-appearance: none;
  1866. margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
  1867. }
  1868. .tabs::-webkit-scrollbar {
  1869. display: none; /* for Chrome, Safari and Opera */
  1870. }
  1871. .tabs {
  1872. -ms-overflow-style: none; /* IE and Edge */
  1873. scrollbar-width: none; /* Firefox */
  1874. }
  1875. input[type='number'] {
  1876. -moz-appearance: textfield; /* Firefox */
  1877. }
  1878. </style>