From cbcce68c61f0ab36056668c90e88131e277912b6 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 3 Dec 2023 23:44:12 -0800 Subject: [PATCH] feat: ollamahub modelfile import --- src/routes/(app)/modelfiles/+page.svelte | 2 +- .../(app)/modelfiles/create/+page.svelte | 34 +++++++++++++++++ .../modelfiles/edit/{[tag] => }/+page.svelte | 38 ++++++++++--------- 3 files changed, 56 insertions(+), 18 deletions(-) rename src/routes/(app)/modelfiles/edit/{[tag] => }/+page.svelte (95%) diff --git a/src/routes/(app)/modelfiles/+page.svelte b/src/routes/(app)/modelfiles/+page.svelte index d9c2b6e2..f4862852 100644 --- a/src/routes/(app)/modelfiles/+page.svelte +++ b/src/routes/(app)/modelfiles/+page.svelte @@ -103,7 +103,7 @@ Edit diff --git a/src/routes/(app)/modelfiles/create/+page.svelte b/src/routes/(app)/modelfiles/create/+page.svelte index 04a01b78..989f34c0 100644 --- a/src/routes/(app)/modelfiles/create/+page.svelte +++ b/src/routes/(app)/modelfiles/create/+page.svelte @@ -7,6 +7,7 @@ import Advanced from '$lib/components/chat/Settings/Advanced.svelte'; import { splitStream } from '$lib/utils'; + import { onMount, tick } from 'svelte'; let loading = false; @@ -209,6 +210,39 @@ SYSTEM """${system}"""`.replace(/^\s*\n/gm, ''); loading = false; success = false; }; + + onMount(() => { + window.addEventListener('message', async (event) => { + if ( + !['https://ollamahub.com', 'https://www.ollamahub.com', 'http://localhost:5173'].includes( + event.origin + ) + ) + return; + const modelfile = JSON.parse(event.data); + console.log(modelfile); + + imageUrl = modelfile.imageUrl; + title = modelfile.title; + await tick(); + tagName = `${modelfile.user.username}/${modelfile.tagName}`; + desc = modelfile.desc; + content = modelfile.content; + suggestions = + modelfile.suggestionPrompts.length != 0 + ? modelfile.suggestionPrompts + : [ + { + content: '' + } + ]; + + for (const category of modelfile.categories) { + categories[category.toLowerCase()] = true; + } + }); + window.opener.postMessage('loaded', '*'); + });
diff --git a/src/routes/(app)/modelfiles/edit/[tag]/+page.svelte b/src/routes/(app)/modelfiles/edit/+page.svelte similarity index 95% rename from src/routes/(app)/modelfiles/edit/[tag]/+page.svelte rename to src/routes/(app)/modelfiles/edit/+page.svelte index c9716d33..48d12239 100644 --- a/src/routes/(app)/modelfiles/edit/[tag]/+page.svelte +++ b/src/routes/(app)/modelfiles/edit/+page.svelte @@ -50,27 +50,31 @@ }; onMount(() => { - tagName = $page.params.tag; + tagName = $page.url.searchParams.get('tag'); - modelfile = $modelfiles.filter((modelfile) => modelfile.tagName === tagName)[0]; + if (tagName) { + modelfile = $modelfiles.filter((modelfile) => modelfile.tagName === tagName)[0]; - console.log(modelfile); + console.log(modelfile); - imageUrl = modelfile.imageUrl; - title = modelfile.title; - desc = modelfile.desc; - content = modelfile.content; - suggestions = - modelfile.suggestionPrompts.length != 0 - ? modelfile.suggestionPrompts - : [ - { - content: '' - } - ]; + imageUrl = modelfile.imageUrl; + title = modelfile.title; + desc = modelfile.desc; + content = modelfile.content; + suggestions = + modelfile.suggestionPrompts.length != 0 + ? modelfile.suggestionPrompts + : [ + { + content: '' + } + ]; - for (const category of modelfile.categories) { - categories[category.toLowerCase()] = true; + for (const category of modelfile.categories) { + categories[category.toLowerCase()] = true; + } + } else { + goto('/modelfiles'); } });