From fbb64406d89db13e92470cb936aedefbcd645b86 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Tue, 26 Dec 2023 23:19:43 -0800 Subject: [PATCH] fix: check existing model before model creation --- src/routes/(app)/+layout.svelte | 2 -- src/routes/(app)/modelfiles/create/+page.svelte | 7 +++++-- src/routes/(app)/modelfiles/edit/+page.svelte | 11 ----------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 5bd550899..e2843fd54 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -97,8 +97,6 @@ console.log(); await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}')); - // await models.set(await getModels()); - // JSON.parse(localStorage.getItem('modelfiles') ?? '[]') await modelfiles.set(await getModelfiles(localStorage.token)); console.log($modelfiles); diff --git a/src/routes/(app)/modelfiles/create/+page.svelte b/src/routes/(app)/modelfiles/create/+page.svelte index a509b6410..96d742b0e 100644 --- a/src/routes/(app)/modelfiles/create/+page.svelte +++ b/src/routes/(app)/modelfiles/create/+page.svelte @@ -9,7 +9,7 @@ import { splitStream } from '$lib/utils'; import { onMount, tick } from 'svelte'; import { createModel } from '$lib/apis/ollama'; - import { createNewModelfile, getModelfiles } from '$lib/apis/modelfiles'; + import { createNewModelfile, getModelfileByTagName, getModelfiles } from '$lib/apis/modelfiles'; let loading = false; @@ -117,7 +117,10 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, ''); return success; } - if ($models.includes(tagName)) { + if ( + $models.map((model) => model.name).includes(tagName) || + (await getModelfileByTagName(localStorage.token, tagName).catch(() => false)) + ) { toast.error( `Uh-oh! It looks like you already have a model named '${tagName}'. Please choose a different name to complete your modelfile.` ); diff --git a/src/routes/(app)/modelfiles/edit/+page.svelte b/src/routes/(app)/modelfiles/edit/+page.svelte index f3068724f..19b7f1f0f 100644 --- a/src/routes/(app)/modelfiles/edit/+page.svelte +++ b/src/routes/(app)/modelfiles/edit/+page.svelte @@ -85,17 +85,6 @@ }); const updateModelfile = async (modelfile) => { - // await modelfiles.set( - // $modelfiles.map((e) => { - // if (e.tagName === modelfile.tagName) { - // return modelfile; - // } else { - // return e; - // } - // }) - // ); - // localStorage.setItem('modelfiles', JSON.stringify($modelfiles)); - await updateModelfileByTagName(localStorage.token, modelfile.tagName, modelfile); await modelfiles.set(await getModelfiles(localStorage.token)); };