From 0afb6ed35cb2bce5d0c81c8648cf9f25f6cd59d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20Hopst=C3=A4tter?=
Date: Fri, 31 Mar 2023 02:17:59 +0200
Subject: [PATCH 1/2] add "New Chat" button to context message
---
src/misc/shared.ts | 17 +++++++-----
src/routes/+page.svelte | 4 +--
src/routes/[slug]/+page.svelte | 36 ++++++++++++--------------
src/routes/shared/[slug]/+error.svelte | 2 +-
4 files changed, 30 insertions(+), 29 deletions(-)
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"
>
-
-
+ createNewChat()}>