SettingsModal.svelte 69 KB

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