diff --git a/backend/apps/web/models/modelfiles.py b/backend/apps/web/models/modelfiles.py index a0f9f1aa3..4d8202db9 100644 --- a/backend/apps/web/models/modelfiles.py +++ b/backend/apps/web/models/modelfiles.py @@ -74,11 +74,16 @@ class ModelfilesTable: "timestamp": int(time.time()), } ) - result = Modelfile.create(**modelfile.model_dump()) - if result: - return modelfile - else: + + try: + result = Modelfile.create(**modelfile.model_dump()) + if result: + return modelfile + else: + return None + except: return None + else: return None diff --git a/backend/apps/web/routers/modelfiles.py b/backend/apps/web/routers/modelfiles.py index 4563c4df2..dd1f6cc59 100644 --- a/backend/apps/web/routers/modelfiles.py +++ b/backend/apps/web/routers/modelfiles.py @@ -56,12 +56,19 @@ async def create_new_modelfile(form_data: ModelfileForm, cred=Depends(bearer_sch # Admin Only if user.role == "admin": modelfile = Modelfiles.insert_new_modelfile(user.id, form_data) - return ModelfileResponse( - **{ - **modelfile.model_dump(), - "modelfile": json.loads(modelfile.modelfile), - } - ) + + if modelfile: + return ModelfileResponse( + **{ + **modelfile.model_dump(), + "modelfile": json.loads(modelfile.modelfile), + } + ) + else: + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail=ERROR_MESSAGES.DEFAULT(), + ) else: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, diff --git a/src/lib/apis/modelfiles/index.ts b/src/lib/apis/modelfiles/index.ts index ad72eec90..91af5e381 100644 --- a/src/lib/apis/modelfiles/index.ts +++ b/src/lib/apis/modelfiles/index.ts @@ -19,7 +19,7 @@ export const createNewModelfile = async (token: string, modelfile: object) => { return res.json(); }) .catch((err) => { - error = err; + error = err.detail; console.log(err); return null; }); diff --git a/src/routes/(app)/modelfiles/+page.svelte b/src/routes/(app)/modelfiles/+page.svelte index 2a8f12ab4..416915241 100644 --- a/src/routes/(app)/modelfiles/+page.svelte +++ b/src/routes/(app)/modelfiles/+page.svelte @@ -1,11 +1,20 @@
@@ -175,6 +199,79 @@
{/each} + {#if localModelfiles.length > 0} +
+ +
+
+ {localModelfiles.length} Local Modelfiles Detected +
+ +
+ + + +
+
+ {/if} +
Made by OllamaHub Community
diff --git a/src/routes/(app)/modelfiles/create/+page.svelte b/src/routes/(app)/modelfiles/create/+page.svelte index 96d742b0e..506edb9f7 100644 --- a/src/routes/(app)/modelfiles/create/+page.svelte +++ b/src/routes/(app)/modelfiles/create/+page.svelte @@ -95,12 +95,6 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, ''); }; const saveModelfile = async (modelfile) => { - // await modelfiles.set([ - // ...$modelfiles.filter((m) => m.tagName !== modelfile.tagName), - // modelfile - // ]); - // localStorage.setItem('modelfiles', JSON.stringify($modelfiles)); - await createNewModelfile(localStorage.token, modelfile); await modelfiles.set(await getModelfiles(localStorage.token)); };