From 5f89c1b1378d69dcd7408dd1722fd03592fbb3cd Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 3 Mar 2025 21:47:27 -0800 Subject: [PATCH] enh: model selector tag filter --- .../chat/ModelSelector/Selector.svelte | 78 ++++++++++++++++--- 1 file changed, 68 insertions(+), 10 deletions(-) diff --git a/src/lib/components/chat/ModelSelector/Selector.svelte b/src/lib/components/chat/ModelSelector/Selector.svelte index b4cb5d003..8a126d85a 100644 --- a/src/lib/components/chat/ModelSelector/Selector.svelte +++ b/src/lib/components/chat/ModelSelector/Selector.svelte @@ -52,12 +52,17 @@ export let className = 'w-[32rem]'; export let triggerClassName = 'text-lg'; + let tagsContainerElement; + let show = false; + let tags = []; let selectedModel = ''; $: selectedModel = items.find((item) => item.value === value) ?? ''; let searchValue = ''; + let selectedTag = ''; + let ollamaVersion = null; let selectedModelIdx = 0; @@ -79,10 +84,23 @@ ); $: filteredItems = searchValue - ? fuse.search(searchValue).map((e) => { - return e.item; - }) - : items; + ? fuse + .search(searchValue) + .map((e) => { + return e.item; + }) + .filter((item) => { + if (selectedTag === '') { + return true; + } + return item.model?.info?.meta?.tags?.map((tag) => tag.name).includes(selectedTag); + }) + : items.filter((item) => { + if (selectedTag === '') { + return true; + } + return item.model?.info?.meta?.tags?.map((tag) => tag.name).includes(selectedTag); + }); const pullModelHandler = async () => { const sanitizedModelTag = searchValue.trim().replace(/^ollama\s+(run|pull)\s+/, ''); @@ -214,6 +232,11 @@ onMount(async () => { ollamaVersion = await getOllamaVersion(localStorage.token).catch((error) => false); + + if (items) { + tags = items.flatMap((item) => item.model?.info?.meta?.tags ?? []); + tags = [...new Set(tags)].map((tag) => tag.name).sort(); + } }); const cancelModelPullHandler = async (model: string) => { @@ -298,10 +321,43 @@ /> -
+
{/if} -
+
+ {#if tags} +
+
+ + + {#each tags as tag} + + {/each} +
+
+ {/if} + {#each filteredItems as item, index}