SettingsModal.svelte 64 KB

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