diff --git a/src/misc/shared.ts b/src/misc/shared.ts index 4218376..23be7d5 100644 --- a/src/misc/shared.ts +++ b/src/misc/shared.ts @@ -32,22 +32,27 @@ export interface ChatCost { maxTokensForModel: number; } -export function createNewChat() { +export function createNewChat(template?: { + context?: string; + title?: string; + settings?: OpenAiSettings; + messages?: ChatCompletionRequestMessage[]; +}) { const slug = generateSlug(); const chat: Chat = { - title: slug, - settings: { ...defaultOpenAiSettings }, + title: template?.title || slug, + settings: { ...(template?.settings || defaultOpenAiSettings) }, contextMessage: { role: 'system', - content: '' + content: template?.context || '' }, - messages: [], + messages: template?.messages || [], created: new Date() }; chatStore.updateChat(slug, chat); - goto(`/${slug}`); + goto(`/${slug}`, { invalidateAll: true }); } export function showModalComponent( diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 746ea1c..54e7aa9 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -71,7 +71,7 @@ // update the local store $chatStore = {}; - goto('/', { replaceState: true }); + goto('/'); } $: sortedChats = Object.entries($chatStore).sort((a, b) => { @@ -83,7 +83,7 @@ class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-6 px-4 md:px-8" > - + Edit + + {#if hasContext} + + {/if} + diff --git a/src/routes/shared/[slug]/+error.svelte b/src/routes/shared/[slug]/+error.svelte index 2eac308..840dde9 100644 --- a/src/routes/shared/[slug]/+error.svelte +++ b/src/routes/shared/[slug]/+error.svelte @@ -10,7 +10,7 @@

-