diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 80f7a7ef..976b6115 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,14 @@ } }; - const toggleAuthHeader = async () => { - authEnabled = !authEnabled; + const toggleSaveChatHistory = async () => { + saveChatHistory = !saveChatHistory; + console.log(saveChatHistory); + + if (saveChatHistory === false) { + await goto('/'); + } + saveSettings({ saveChatHistory: saveChatHistory }); }; const pullModelHandler = async () => { @@ -576,6 +583,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 +1625,64 @@ {:else if selectedTab === 'chats'}
+
+
+
Chat History
+ + +
+ +
+ This setting does not sync across browsers or devices. +
+
+ +
+
{ + 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('/'); + } + });