Selector.svelte 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <script lang="ts">
  2. import { DropdownMenu } from 'bits-ui';
  3. import { marked } from 'marked';
  4. import Fuse from 'fuse.js';
  5. import { flyAndScale } from '$lib/utils/transitions';
  6. import { createEventDispatcher, onMount, getContext, tick } from 'svelte';
  7. import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
  8. import Check from '$lib/components/icons/Check.svelte';
  9. import Search from '$lib/components/icons/Search.svelte';
  10. import { deleteModel, getOllamaVersion, pullModel } from '$lib/apis/ollama';
  11. import {
  12. user,
  13. MODEL_DOWNLOAD_POOL,
  14. models,
  15. mobile,
  16. temporaryChatEnabled,
  17. settings,
  18. config
  19. } from '$lib/stores';
  20. import { toast } from 'svelte-sonner';
  21. import { capitalizeFirstLetter, sanitizeResponseContent, splitStream } from '$lib/utils';
  22. import { getModels } from '$lib/apis';
  23. import Tooltip from '$lib/components/common/Tooltip.svelte';
  24. import Switch from '$lib/components/common/Switch.svelte';
  25. import ChatBubbleOval from '$lib/components/icons/ChatBubbleOval.svelte';
  26. import { goto } from '$app/navigation';
  27. const i18n = getContext('i18n');
  28. const dispatch = createEventDispatcher();
  29. export let id = '';
  30. export let value = '';
  31. export let placeholder = 'Select a model';
  32. export let searchEnabled = true;
  33. export let searchPlaceholder = $i18n.t('Search a model');
  34. export let showTemporaryChatControl = false;
  35. export let items: {
  36. label: string;
  37. value: string;
  38. model: Model;
  39. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  40. [key: string]: any;
  41. }[] = [];
  42. export let className = 'w-[32rem]';
  43. export let triggerClassName = 'text-lg';
  44. let tagsContainerElement;
  45. let show = false;
  46. let tags = [];
  47. let selectedModel = '';
  48. $: selectedModel = items.find((item) => item.value === value) ?? '';
  49. let searchValue = '';
  50. let selectedTag = '';
  51. let selectedConnectionType = '';
  52. let ollamaVersion = null;
  53. let selectedModelIdx = 0;
  54. const fuse = new Fuse(
  55. items.map((item) => {
  56. const _item = {
  57. ...item,
  58. modelName: item.model?.name,
  59. tags: item.model?.info?.meta?.tags?.map((tag) => tag.name).join(' '),
  60. desc: item.model?.info?.meta?.description
  61. };
  62. return _item;
  63. }),
  64. {
  65. keys: ['value', 'tags', 'modelName'],
  66. threshold: 0.4
  67. }
  68. );
  69. $: filteredItems = searchValue
  70. ? fuse
  71. .search(searchValue)
  72. .map((e) => {
  73. return e.item;
  74. })
  75. .filter((item) => {
  76. if (selectedTag === '') {
  77. return true;
  78. }
  79. return item.model?.info?.meta?.tags?.map((tag) => tag.name).includes(selectedTag);
  80. })
  81. .filter((item) => {
  82. if (selectedConnectionType === '') {
  83. return true;
  84. } else if (selectedConnectionType === 'ollama') {
  85. return item.model?.owned_by === 'ollama';
  86. } else if (selectedConnectionType === 'openai') {
  87. return item.model?.owned_by === 'openai';
  88. } else if (selectedConnectionType === 'direct') {
  89. return item.model?.direct;
  90. }
  91. })
  92. : items
  93. .filter((item) => {
  94. if (selectedTag === '') {
  95. return true;
  96. }
  97. return item.model?.info?.meta?.tags?.map((tag) => tag.name).includes(selectedTag);
  98. })
  99. .filter((item) => {
  100. if (selectedConnectionType === '') {
  101. return true;
  102. } else if (selectedConnectionType === 'ollama') {
  103. return item.model?.owned_by === 'ollama';
  104. } else if (selectedConnectionType === 'openai') {
  105. return item.model?.owned_by === 'openai';
  106. } else if (selectedConnectionType === 'direct') {
  107. return item.model?.direct;
  108. }
  109. });
  110. const pullModelHandler = async () => {
  111. const sanitizedModelTag = searchValue.trim().replace(/^ollama\s+(run|pull)\s+/, '');
  112. console.log($MODEL_DOWNLOAD_POOL);
  113. if ($MODEL_DOWNLOAD_POOL[sanitizedModelTag]) {
  114. toast.error(
  115. $i18n.t(`Model '{{modelTag}}' is already in queue for downloading.`, {
  116. modelTag: sanitizedModelTag
  117. })
  118. );
  119. return;
  120. }
  121. if (Object.keys($MODEL_DOWNLOAD_POOL).length === 3) {
  122. toast.error(
  123. $i18n.t('Maximum of 3 models can be downloaded simultaneously. Please try again later.')
  124. );
  125. return;
  126. }
  127. const [res, controller] = await pullModel(localStorage.token, sanitizedModelTag, '0').catch(
  128. (error) => {
  129. toast.error(`${error}`);
  130. return null;
  131. }
  132. );
  133. if (res) {
  134. const reader = res.body
  135. .pipeThrough(new TextDecoderStream())
  136. .pipeThrough(splitStream('\n'))
  137. .getReader();
  138. MODEL_DOWNLOAD_POOL.set({
  139. ...$MODEL_DOWNLOAD_POOL,
  140. [sanitizedModelTag]: {
  141. ...$MODEL_DOWNLOAD_POOL[sanitizedModelTag],
  142. abortController: controller,
  143. reader,
  144. done: false
  145. }
  146. });
  147. while (true) {
  148. try {
  149. const { value, done } = await reader.read();
  150. if (done) break;
  151. let lines = value.split('\n');
  152. for (const line of lines) {
  153. if (line !== '') {
  154. let data = JSON.parse(line);
  155. console.log(data);
  156. if (data.error) {
  157. throw data.error;
  158. }
  159. if (data.detail) {
  160. throw data.detail;
  161. }
  162. if (data.status) {
  163. if (data.digest) {
  164. let downloadProgress = 0;
  165. if (data.completed) {
  166. downloadProgress = Math.round((data.completed / data.total) * 1000) / 10;
  167. } else {
  168. downloadProgress = 100;
  169. }
  170. MODEL_DOWNLOAD_POOL.set({
  171. ...$MODEL_DOWNLOAD_POOL,
  172. [sanitizedModelTag]: {
  173. ...$MODEL_DOWNLOAD_POOL[sanitizedModelTag],
  174. pullProgress: downloadProgress,
  175. digest: data.digest
  176. }
  177. });
  178. } else {
  179. toast.success(data.status);
  180. MODEL_DOWNLOAD_POOL.set({
  181. ...$MODEL_DOWNLOAD_POOL,
  182. [sanitizedModelTag]: {
  183. ...$MODEL_DOWNLOAD_POOL[sanitizedModelTag],
  184. done: data.status === 'success'
  185. }
  186. });
  187. }
  188. }
  189. }
  190. }
  191. } catch (error) {
  192. console.log(error);
  193. if (typeof error !== 'string') {
  194. error = error.message;
  195. }
  196. toast.error(`${error}`);
  197. // opts.callback({ success: false, error, modelName: opts.modelName });
  198. break;
  199. }
  200. }
  201. if ($MODEL_DOWNLOAD_POOL[sanitizedModelTag].done) {
  202. toast.success(
  203. $i18n.t(`Model '{{modelName}}' has been successfully downloaded.`, {
  204. modelName: sanitizedModelTag
  205. })
  206. );
  207. models.set(
  208. await getModels(
  209. localStorage.token,
  210. $config?.features?.enable_direct_connections && ($settings?.directConnections ?? null)
  211. )
  212. );
  213. } else {
  214. toast.error($i18n.t('Download canceled'));
  215. }
  216. delete $MODEL_DOWNLOAD_POOL[sanitizedModelTag];
  217. MODEL_DOWNLOAD_POOL.set({
  218. ...$MODEL_DOWNLOAD_POOL
  219. });
  220. }
  221. };
  222. onMount(async () => {
  223. ollamaVersion = await getOllamaVersion(localStorage.token).catch((error) => false);
  224. if (items) {
  225. tags = items.flatMap((item) => item.model?.info?.meta?.tags ?? []).map((tag) => tag.name);
  226. // Remove duplicates and sort
  227. tags = Array.from(new Set(tags)).sort((a, b) => a.localeCompare(b));
  228. }
  229. });
  230. const cancelModelPullHandler = async (model: string) => {
  231. const { reader, abortController } = $MODEL_DOWNLOAD_POOL[model];
  232. if (abortController) {
  233. abortController.abort();
  234. }
  235. if (reader) {
  236. await reader.cancel();
  237. delete $MODEL_DOWNLOAD_POOL[model];
  238. MODEL_DOWNLOAD_POOL.set({
  239. ...$MODEL_DOWNLOAD_POOL
  240. });
  241. await deleteModel(localStorage.token, model);
  242. toast.success(`${model} download has been canceled`);
  243. }
  244. };
  245. </script>
  246. <DropdownMenu.Root
  247. bind:open={show}
  248. onOpenChange={async () => {
  249. searchValue = '';
  250. selectedModelIdx = 0;
  251. window.setTimeout(() => document.getElementById('model-search-input')?.focus(), 0);
  252. }}
  253. closeFocus={false}
  254. >
  255. <DropdownMenu.Trigger
  256. class="relative w-full font-primary"
  257. aria-label={placeholder}
  258. id="model-selector-{id}-button"
  259. >
  260. <div
  261. class="flex w-full text-left px-0.5 outline-hidden bg-transparent truncate {triggerClassName} justify-between font-medium placeholder-gray-400 focus:outline-hidden"
  262. >
  263. {#if selectedModel}
  264. {selectedModel.label}
  265. {:else}
  266. {placeholder}
  267. {/if}
  268. <ChevronDown className=" self-center ml-2 size-3" strokeWidth="2.5" />
  269. </div>
  270. </DropdownMenu.Trigger>
  271. <DropdownMenu.Content
  272. class=" z-40 {$mobile
  273. ? `w-full`
  274. : `${className}`} max-w-[calc(100vw-1rem)] justify-start rounded-xl bg-white dark:bg-gray-850 dark:text-white shadow-lg outline-hidden"
  275. transition={flyAndScale}
  276. side={$mobile ? 'bottom' : 'bottom-start'}
  277. sideOffset={3}
  278. >
  279. <slot>
  280. {#if searchEnabled}
  281. <div class="flex items-center gap-2.5 px-5 mt-3.5 mb-1.5">
  282. <Search className="size-4" strokeWidth="2.5" />
  283. <input
  284. id="model-search-input"
  285. bind:value={searchValue}
  286. class="w-full text-sm bg-transparent outline-hidden"
  287. placeholder={searchPlaceholder}
  288. autocomplete="off"
  289. on:keydown={(e) => {
  290. if (e.code === 'Enter' && filteredItems.length > 0) {
  291. value = filteredItems[selectedModelIdx].value;
  292. show = false;
  293. return; // dont need to scroll on selection
  294. } else if (e.code === 'ArrowDown') {
  295. selectedModelIdx = Math.min(selectedModelIdx + 1, filteredItems.length - 1);
  296. } else if (e.code === 'ArrowUp') {
  297. selectedModelIdx = Math.max(selectedModelIdx - 1, 0);
  298. } else {
  299. // if the user types something, reset to the top selection.
  300. selectedModelIdx = 0;
  301. }
  302. const item = document.querySelector(`[data-arrow-selected="true"]`);
  303. item?.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
  304. }}
  305. />
  306. </div>
  307. {/if}
  308. <div class="px-3 mb-2 max-h-64 overflow-y-auto scrollbar-hidden group relative">
  309. {#if tags}
  310. <div class=" flex w-full sticky top-0 z-10 bg-white dark:bg-gray-850">
  311. <div
  312. class="flex gap-1 scrollbar-none overflow-x-auto w-fit text-center text-sm font-medium rounded-full bg-transparent px-1.5 pb-0.5"
  313. bind:this={tagsContainerElement}
  314. >
  315. <button
  316. class="min-w-fit outline-none p-1.5 {selectedTag === '' &&
  317. selectedConnectionType === ''
  318. ? ''
  319. : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition capitalize"
  320. on:click={() => {
  321. selectedConnectionType = '';
  322. selectedTag = '';
  323. }}
  324. >
  325. {$i18n.t('All')}
  326. </button>
  327. {#if items.find((item) => item.model?.owned_by === 'ollama') && items.find((item) => item.model?.owned_by === 'openai')}
  328. <button
  329. class="min-w-fit outline-none p-1.5 {selectedConnectionType === 'ollama'
  330. ? ''
  331. : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition capitalize"
  332. on:click={() => {
  333. selectedTag = '';
  334. selectedConnectionType = 'ollama';
  335. }}
  336. >
  337. {$i18n.t('Local')}
  338. </button>
  339. <button
  340. class="min-w-fit outline-none p-1.5 {selectedConnectionType === 'openai'
  341. ? ''
  342. : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition capitalize"
  343. on:click={() => {
  344. selectedTag = '';
  345. selectedConnectionType = 'openai';
  346. }}
  347. >
  348. {$i18n.t('External')}
  349. </button>
  350. {/if}
  351. {#if items.find((item) => item.model?.direct)}
  352. <button
  353. class="min-w-fit outline-none p-1.5 {selectedConnectionType === 'direct'
  354. ? ''
  355. : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition capitalize"
  356. on:click={() => {
  357. selectedTag = '';
  358. selectedConnectionType = 'direct';
  359. }}
  360. >
  361. {$i18n.t('Direct')}
  362. </button>
  363. {/if}
  364. {#each tags as tag}
  365. <button
  366. class="min-w-fit outline-none p-1.5 {selectedTag === tag
  367. ? ''
  368. : 'text-gray-300 dark:text-gray-600 hover:text-gray-700 dark:hover:text-white'} transition capitalize"
  369. on:click={() => {
  370. selectedConnectionType = '';
  371. selectedTag = tag;
  372. }}
  373. >
  374. {tag}
  375. </button>
  376. {/each}
  377. </div>
  378. </div>
  379. {/if}
  380. {#each filteredItems as item, index}
  381. <button
  382. aria-label="model-item"
  383. class="flex w-full text-left font-medium line-clamp-1 select-none items-center rounded-button py-2 pl-3 pr-1.5 text-sm text-gray-700 dark:text-gray-100 outline-hidden transition-all duration-75 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg cursor-pointer data-highlighted:bg-muted {index ===
  384. selectedModelIdx
  385. ? 'bg-gray-100 dark:bg-gray-800 group-hover:bg-transparent'
  386. : ''}"
  387. data-arrow-selected={index === selectedModelIdx}
  388. on:click={() => {
  389. value = item.value;
  390. selectedModelIdx = index;
  391. show = false;
  392. }}
  393. >
  394. <div class="flex flex-col">
  395. {#if $mobile && (item?.model?.info?.meta?.tags ?? []).length > 0}
  396. <div class="flex gap-0.5 self-start h-full mb-1.5 -translate-x-1">
  397. {#each item.model?.info?.meta.tags as tag}
  398. <div
  399. class=" text-xs font-bold px-1 rounded-sm uppercase line-clamp-1 bg-gray-500/20 text-gray-700 dark:text-gray-200"
  400. >
  401. {tag.name}
  402. </div>
  403. {/each}
  404. </div>
  405. {/if}
  406. <div class="flex items-center gap-2">
  407. <div class="flex items-center min-w-fit">
  408. <div class="line-clamp-1">
  409. <div class="flex items-center min-w-fit">
  410. <Tooltip
  411. content={$user?.role === 'admin' ? (item?.value ?? '') : ''}
  412. placement="top-start"
  413. >
  414. <img
  415. src={item.model?.info?.meta?.profile_image_url ?? '/static/favicon.png'}
  416. alt="Model"
  417. class="rounded-full size-5 flex items-center mr-2"
  418. />
  419. {item.label}
  420. </Tooltip>
  421. </div>
  422. </div>
  423. {#if item.model.owned_by === 'ollama' && (item.model.ollama?.details?.parameter_size ?? '') !== ''}
  424. <div class="flex ml-1 items-center translate-y-[0.5px]">
  425. <Tooltip
  426. content={`${
  427. item.model.ollama?.details?.quantization_level
  428. ? item.model.ollama?.details?.quantization_level + ' '
  429. : ''
  430. }${
  431. item.model.ollama?.size
  432. ? `(${(item.model.ollama?.size / 1024 ** 3).toFixed(1)}GB)`
  433. : ''
  434. }`}
  435. className="self-end"
  436. >
  437. <span
  438. class=" text-xs font-medium text-gray-600 dark:text-gray-400 line-clamp-1"
  439. >{item.model.ollama?.details?.parameter_size ?? ''}</span
  440. >
  441. </Tooltip>
  442. </div>
  443. {/if}
  444. </div>
  445. <!-- {JSON.stringify(item.info)} -->
  446. {#if item.model?.direct}
  447. <Tooltip content={`${'Direct'}`}>
  448. <div class="translate-y-[1px]">
  449. <svg
  450. xmlns="http://www.w3.org/2000/svg"
  451. viewBox="0 0 16 16"
  452. fill="currentColor"
  453. class="size-3"
  454. >
  455. <path
  456. fill-rule="evenodd"
  457. d="M2 2.75A.75.75 0 0 1 2.75 2C8.963 2 14 7.037 14 13.25a.75.75 0 0 1-1.5 0c0-5.385-4.365-9.75-9.75-9.75A.75.75 0 0 1 2 2.75Zm0 4.5a.75.75 0 0 1 .75-.75 6.75 6.75 0 0 1 6.75 6.75.75.75 0 0 1-1.5 0C8 10.35 5.65 8 2.75 8A.75.75 0 0 1 2 7.25ZM3.5 11a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3Z"
  458. clip-rule="evenodd"
  459. />
  460. </svg>
  461. </div>
  462. </Tooltip>
  463. {:else if item.model.owned_by === 'openai'}
  464. <Tooltip content={`${'External'}`}>
  465. <div class="translate-y-[1px]">
  466. <svg
  467. xmlns="http://www.w3.org/2000/svg"
  468. viewBox="0 0 16 16"
  469. fill="currentColor"
  470. class="size-3"
  471. >
  472. <path
  473. fill-rule="evenodd"
  474. d="M8.914 6.025a.75.75 0 0 1 1.06 0 3.5 3.5 0 0 1 0 4.95l-2 2a3.5 3.5 0 0 1-5.396-4.402.75.75 0 0 1 1.251.827 2 2 0 0 0 3.085 2.514l2-2a2 2 0 0 0 0-2.828.75.75 0 0 1 0-1.06Z"
  475. clip-rule="evenodd"
  476. />
  477. <path
  478. fill-rule="evenodd"
  479. d="M7.086 9.975a.75.75 0 0 1-1.06 0 3.5 3.5 0 0 1 0-4.95l2-2a3.5 3.5 0 0 1 5.396 4.402.75.75 0 0 1-1.251-.827 2 2 0 0 0-3.085-2.514l-2 2a2 2 0 0 0 0 2.828.75.75 0 0 1 0 1.06Z"
  480. clip-rule="evenodd"
  481. />
  482. </svg>
  483. </div>
  484. </Tooltip>
  485. {/if}
  486. {#if item.model?.info?.meta?.description}
  487. <Tooltip
  488. content={`${marked.parse(
  489. sanitizeResponseContent(item.model?.info?.meta?.description).replaceAll(
  490. '\n',
  491. '<br>'
  492. )
  493. )}`}
  494. >
  495. <div class=" translate-y-[1px]">
  496. <svg
  497. xmlns="http://www.w3.org/2000/svg"
  498. fill="none"
  499. viewBox="0 0 24 24"
  500. stroke-width="1.5"
  501. stroke="currentColor"
  502. class="w-4 h-4"
  503. >
  504. <path
  505. stroke-linecap="round"
  506. stroke-linejoin="round"
  507. d="m11.25 11.25.041-.02a.75.75 0 0 1 1.063.852l-.708 2.836a.75.75 0 0 0 1.063.853l.041-.021M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9-3.75h.008v.008H12V8.25Z"
  508. />
  509. </svg>
  510. </div>
  511. </Tooltip>
  512. {/if}
  513. {#if !$mobile && (item?.model?.info?.meta?.tags ?? []).length > 0}
  514. <div
  515. class="flex gap-0.5 self-center items-center h-full translate-y-[0.5px] overflow-x-auto scrollbar-none"
  516. >
  517. {#each item.model?.info?.meta.tags as tag}
  518. <Tooltip content={tag.name} className="flex-shrink-0">
  519. <div
  520. class=" text-xs font-bold px-1 rounded-sm uppercase bg-gray-500/20 text-gray-700 dark:text-gray-200"
  521. >
  522. {tag.name}
  523. </div>
  524. </Tooltip>
  525. {/each}
  526. </div>
  527. {/if}
  528. </div>
  529. </div>
  530. {#if value === item.value}
  531. <div class="ml-auto pl-2 pr-2 md:pr-0">
  532. <Check />
  533. </div>
  534. {/if}
  535. </button>
  536. {:else}
  537. <div>
  538. <div class="block px-3 py-2 text-sm text-gray-700 dark:text-gray-100">
  539. {$i18n.t('No results found')}
  540. </div>
  541. </div>
  542. {/each}
  543. {#if !(searchValue.trim() in $MODEL_DOWNLOAD_POOL) && searchValue && ollamaVersion && $user.role === 'admin'}
  544. <Tooltip
  545. content={$i18n.t(`Pull "{{searchValue}}" from Ollama.com`, {
  546. searchValue: searchValue
  547. })}
  548. placement="top-start"
  549. >
  550. <button
  551. class="flex w-full font-medium line-clamp-1 select-none items-center rounded-button py-2 pl-3 pr-1.5 text-sm text-gray-700 dark:text-gray-100 outline-hidden transition-all duration-75 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg cursor-pointer data-highlighted:bg-muted"
  552. on:click={() => {
  553. pullModelHandler();
  554. }}
  555. >
  556. <div class=" truncate">
  557. {$i18n.t(`Pull "{{searchValue}}" from Ollama.com`, { searchValue: searchValue })}
  558. </div>
  559. </button>
  560. </Tooltip>
  561. {/if}
  562. {#each Object.keys($MODEL_DOWNLOAD_POOL) as model}
  563. <div
  564. class="flex w-full justify-between font-medium select-none rounded-button py-2 pl-3 pr-1.5 text-sm text-gray-700 dark:text-gray-100 outline-hidden transition-all duration-75 rounded-lg cursor-pointer data-highlighted:bg-muted"
  565. >
  566. <div class="flex">
  567. <div class="-ml-2 mr-2.5 translate-y-0.5">
  568. <svg
  569. class="size-4"
  570. viewBox="0 0 24 24"
  571. fill="currentColor"
  572. xmlns="http://www.w3.org/2000/svg"
  573. ><style>
  574. .spinner_ajPY {
  575. transform-origin: center;
  576. animation: spinner_AtaB 0.75s infinite linear;
  577. }
  578. @keyframes spinner_AtaB {
  579. 100% {
  580. transform: rotate(360deg);
  581. }
  582. }
  583. </style><path
  584. 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"
  585. opacity=".25"
  586. /><path
  587. 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"
  588. class="spinner_ajPY"
  589. /></svg
  590. >
  591. </div>
  592. <div class="flex flex-col self-start">
  593. <div class="flex gap-1">
  594. <div class="line-clamp-1">
  595. Downloading "{model}"
  596. </div>
  597. <div class="shrink-0">
  598. {'pullProgress' in $MODEL_DOWNLOAD_POOL[model]
  599. ? `(${$MODEL_DOWNLOAD_POOL[model].pullProgress}%)`
  600. : ''}
  601. </div>
  602. </div>
  603. {#if 'digest' in $MODEL_DOWNLOAD_POOL[model] && $MODEL_DOWNLOAD_POOL[model].digest}
  604. <div class="-mt-1 h-fit text-[0.7rem] dark:text-gray-500 line-clamp-1">
  605. {$MODEL_DOWNLOAD_POOL[model].digest}
  606. </div>
  607. {/if}
  608. </div>
  609. </div>
  610. <div class="mr-2 ml-1 translate-y-0.5">
  611. <Tooltip content={$i18n.t('Cancel')}>
  612. <button
  613. class="text-gray-800 dark:text-gray-100"
  614. on:click={() => {
  615. cancelModelPullHandler(model);
  616. }}
  617. >
  618. <svg
  619. class="w-4 h-4 text-gray-800 dark:text-white"
  620. aria-hidden="true"
  621. xmlns="http://www.w3.org/2000/svg"
  622. width="24"
  623. height="24"
  624. fill="currentColor"
  625. viewBox="0 0 24 24"
  626. >
  627. <path
  628. stroke="currentColor"
  629. stroke-linecap="round"
  630. stroke-linejoin="round"
  631. stroke-width="2"
  632. d="M6 18 17.94 6M18 18 6.06 6"
  633. />
  634. </svg>
  635. </button>
  636. </Tooltip>
  637. </div>
  638. </div>
  639. {/each}
  640. </div>
  641. {#if showTemporaryChatControl}
  642. <hr class="border-gray-100 dark:border-gray-800" />
  643. <div class="flex items-center mx-2 my-2">
  644. <button
  645. class="flex justify-between w-full font-medium line-clamp-1 select-none items-center rounded-button py-2 px-3 text-sm text-gray-700 dark:text-gray-100 outline-hidden transition-all duration-75 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg cursor-pointer data-highlighted:bg-muted"
  646. on:click={async () => {
  647. temporaryChatEnabled.set(!$temporaryChatEnabled);
  648. await goto('/');
  649. const newChatButton = document.getElementById('new-chat-button');
  650. setTimeout(() => {
  651. newChatButton?.click();
  652. }, 0);
  653. // add 'temporary-chat=true' to the URL
  654. if ($temporaryChatEnabled) {
  655. history.replaceState(null, '', '?temporary-chat=true');
  656. } else {
  657. history.replaceState(null, '', location.pathname);
  658. }
  659. show = false;
  660. }}
  661. >
  662. <div class="flex gap-2.5 items-center">
  663. <ChatBubbleOval className="size-4" strokeWidth="2.5" />
  664. {$i18n.t(`Temporary Chat`)}
  665. </div>
  666. <div>
  667. <Switch state={$temporaryChatEnabled} />
  668. </div>
  669. </button>
  670. </div>
  671. {/if}
  672. <div class="hidden w-[42rem]" />
  673. <div class="hidden w-[32rem]" />
  674. </slot>
  675. </DropdownMenu.Content>
  676. </DropdownMenu.Root>