From 77a4c4ce3e6e0d3e31d33b17c8d3ffb250986283 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 6 Jan 2024 02:01:56 -0800 Subject: [PATCH 1/2] feat: chat history save added to settings --- src/lib/components/chat/SettingsModal.svelte | 66 +++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 80f7a7ef..3758d4f7 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -99,6 +99,7 @@ let titleAutoGenerateModel = ''; // Chats + let saveChatHistory = true; let importFiles; let showDeleteConfirm = false; @@ -235,8 +236,9 @@ } }; - const toggleAuthHeader = async () => { - authEnabled = !authEnabled; + const toggleSaveChatHistory = async () => { + saveChatHistory = !saveChatHistory; + saveSettings({ saveChatHistory: saveChatHistory }); }; const pullModelHandler = async () => { @@ -576,6 +578,8 @@ titleAutoGenerateModel = settings.titleAutoGenerateModel ?? ''; gravatarEmail = settings.gravatarEmail ?? ''; + saveChatHistory = settings.saveChatHistory ?? true; + authEnabled = settings.authHeader !== undefined ? true : false; if (authEnabled) { authType = settings.authHeader.split(' ')[0]; @@ -1616,6 +1620,64 @@ {:else if selectedTab === 'chats'}
+
+
+
Chat History
+ + +
+ +
+ This setting does not sync across browsers or devices. +
+
+ +
+
Date: Sat, 6 Jan 2024 02:33:00 -0800 Subject: [PATCH 2/2] feat: chat history incognito mode --- src/lib/components/chat/SettingsModal.svelte | 5 + src/lib/components/layout/Sidebar.svelte | 521 ++++++++++--------- src/routes/(app)/+page.svelte | 62 ++- src/routes/(app)/c/[id]/+page.svelte | 6 + 4 files changed, 332 insertions(+), 262 deletions(-) diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 3758d4f7..976b6115 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -238,6 +238,11 @@ const toggleSaveChatHistory = async () => { saveChatHistory = !saveChatHistory; + console.log(saveChatHistory); + + if (saveChatHistory === false) { + await goto('/'); + } saveSettings({ saveChatHistory: saveChatHistory }); }; diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index b0eb35b2..7ea08f98 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -6,7 +6,7 @@ import { goto, invalidateAll } from '$app/navigation'; import { page } from '$app/stores'; - import { user, chats, showSettings, chatId } from '$lib/stores'; + import { user, chats, settings, showSettings, chatId } from '$lib/stores'; import { onMount } from 'svelte'; import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats'; @@ -49,6 +49,12 @@ await deleteChatById(localStorage.token, id); await chats.set(await getChatList(localStorage.token)); }; + + const saveSettings = async (updated) => { + await settings.set({ ...$settings, ...updated }); + localStorage.setItem('settings', JSON.stringify($settings)); + location.href = '/'; + };
{/if} -
- + {/each} +
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index be0faef4..86bdbbea 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -280,11 +280,13 @@ } if ($chatId == _chatId) { - chat = await updateChatById(localStorage.token, _chatId, { - messages: messages, - history: history - }); - await chats.set(await getChatList(localStorage.token)); + if ($settings.saveChatHistory ?? true) { + chat = await updateChatById(localStorage.token, _chatId, { + messages: messages, + history: history + }); + await chats.set(await getChatList(localStorage.token)); + } } } else { if (res !== null) { @@ -444,11 +446,13 @@ } if ($chatId == _chatId) { - chat = await updateChatById(localStorage.token, _chatId, { - messages: messages, - history: history - }); - await chats.set(await getChatList(localStorage.token)); + if ($settings.saveChatHistory ?? true) { + chat = await updateChatById(localStorage.token, _chatId, { + messages: messages, + history: history + }); + await chats.set(await getChatList(localStorage.token)); + } } } else { if (res !== null) { @@ -527,20 +531,24 @@ // Create new chat if only one message in messages if (messages.length == 1) { - chat = await createNewChat(localStorage.token, { - id: $chatId, - title: 'New Chat', - models: selectedModels, - system: $settings.system ?? undefined, - options: { - ...($settings.options ?? {}) - }, - messages: messages, - history: history, - timestamp: Date.now() - }); - await chats.set(await getChatList(localStorage.token)); - await chatId.set(chat.id); + if ($settings.saveChatHistory ?? true) { + chat = await createNewChat(localStorage.token, { + id: $chatId, + title: 'New Chat', + models: selectedModels, + system: $settings.system ?? undefined, + options: { + ...($settings.options ?? {}) + }, + messages: messages, + history: history, + timestamp: Date.now() + }); + await chats.set(await getChatList(localStorage.token)); + await chatId.set(chat.id); + } else { + await chatId.set('local'); + } await tick(); } @@ -592,8 +600,10 @@ title = _title; } - chat = await updateChatById(localStorage.token, _chatId, { title: _title }); - await chats.set(await getChatList(localStorage.token)); + if ($settings.saveChatHistory ?? true) { + chat = await updateChatById(localStorage.token, _chatId, { title: _title }); + await chats.set(await getChatList(localStorage.token)); + } }; diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index d538b799..341d2ff9 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -609,6 +609,12 @@ chat = await updateChatById(localStorage.token, _chatId, { title: _title }); await chats.set(await getChatList(localStorage.token)); }; + + onMount(async () => { + if (!($settings.saveChatHistory ?? true)) { + await goto('/'); + } + });