From 9283ed168542356235793810e76e095634f82a23 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 31 May 2024 02:11:25 -0700 Subject: [PATCH] feat: hide/unhide model from selector --- .../chat/ModelSelector/Selector.svelte | 8 +- .../icons/EllipsisHorizontal.svelte | 19 +++ src/lib/components/workspace/Models.svelte | 128 ++++++++-------- .../workspace/Models/ModelMenu.svelte | 142 ++++++++++++++++++ .../(app)/workspace/models/edit/+page.svelte | 4 +- 5 files changed, 231 insertions(+), 70 deletions(-) create mode 100644 src/lib/components/icons/EllipsisHorizontal.svelte create mode 100644 src/lib/components/workspace/Models/ModelMenu.svelte diff --git a/src/lib/components/chat/ModelSelector/Selector.svelte b/src/lib/components/chat/ModelSelector/Selector.svelte index 96af8c763..8507f7a21 100644 --- a/src/lib/components/chat/ModelSelector/Selector.svelte +++ b/src/lib/components/chat/ModelSelector/Selector.svelte @@ -42,9 +42,11 @@ let searchValue = ''; let ollamaVersion = null; - $: filteredItems = searchValue - ? items.filter((item) => item.value.toLowerCase().includes(searchValue.toLowerCase())) - : items; + $: filteredItems = items.filter((item) => + searchValue + ? item.value.toLowerCase().includes(searchValue.toLowerCase()) + : true && !(item.model?.info?.meta?.hidden ?? false) + ); const pullModelHandler = async () => { const sanitizedModelTag = searchValue.trim().replace(/^ollama\s+(run|pull)\s+/, ''); diff --git a/src/lib/components/icons/EllipsisHorizontal.svelte b/src/lib/components/icons/EllipsisHorizontal.svelte new file mode 100644 index 000000000..6a7d532e3 --- /dev/null +++ b/src/lib/components/icons/EllipsisHorizontal.svelte @@ -0,0 +1,19 @@ + + + + + diff --git a/src/lib/components/workspace/Models.svelte b/src/lib/components/workspace/Models.svelte index 7c4829e3a..2fe8cef27 100644 --- a/src/lib/components/workspace/Models.svelte +++ b/src/lib/components/workspace/Models.svelte @@ -12,6 +12,8 @@ import { goto } from '$app/navigation'; import { getModels } from '$lib/apis'; + import EllipsisHorizontal from '../icons/EllipsisHorizontal.svelte'; + import ModelMenu from './Models/ModelMenu.svelte'; const i18n = getContext('i18n'); @@ -74,6 +76,41 @@ ); }; + const hideModelHandler = async (model) => { + let info = model.info; + + if (!info) { + info = { + id: model.id, + name: model.name, + meta: { + suggestion_prompts: null + }, + params: {} + }; + } + + info.meta = { + ...info.meta, + hidden: !(info?.meta?.hidden ?? false) + }; + + console.log(info); + + const res = await updateModelById(localStorage.token, info.id, info); + + if (res) { + toast.success( + $i18n.t(`Model {{name}} is now {{status}}`, { + name: info.id, + status: info.meta.hidden ? 'hidden' : 'visible' + }) + ); + } + + await models.set(await getModels(localStorage.token)); + }; + const downloadModels = async (models) => { let blob = new Blob([JSON.stringify(models)], { type: 'application/json' @@ -177,7 +214,11 @@ href={`/?models=${encodeURIComponent(model.id)}`} >
-
+
modelfile profile
-
+
{model.name}
{!!model?.info?.meta?.description ? model?.info?.meta?.description : model.id}
-
+
- - - - - + + +
{/each} diff --git a/src/lib/components/workspace/Models/ModelMenu.svelte b/src/lib/components/workspace/Models/ModelMenu.svelte new file mode 100644 index 000000000..364893229 --- /dev/null +++ b/src/lib/components/workspace/Models/ModelMenu.svelte @@ -0,0 +1,142 @@ + + + { + if (e.detail === false) { + onClose(); + } + }} +> + + + + +
+ + { + shareHandler(); + }} + > + +
{$i18n.t('Share')}
+
+ + { + cloneHandler(); + }} + > + + + + +
{$i18n.t('Clone')}
+
+ + { + hideHandler(); + }} + > + {#if model?.info?.meta?.hidden ?? false} + + + + {:else} + + + + + {/if} + +
+ {$i18n.t(model?.info?.meta?.hidden ?? false ? 'Show Model' : 'Hide Model')} +
+
+ +
+ + { + deleteHandler(); + }} + > + +
{$i18n.t('Delete')}
+
+
+
+
diff --git a/src/routes/(app)/workspace/models/edit/+page.svelte b/src/routes/(app)/workspace/models/edit/+page.svelte index a2d5a7d76..558ad3663 100644 --- a/src/routes/(app)/workspace/models/edit/+page.svelte +++ b/src/routes/(app)/workspace/models/edit/+page.svelte @@ -460,7 +460,7 @@
-
+
{$i18n.t('Capabilities')}
@@ -473,7 +473,7 @@ }} /> -
+
{$i18n.t(capability)}