From 426adbbca58ebeefd8530f1dade9d70bd67aad2d Mon Sep 17 00:00:00 2001 From: Webifi Date: Thu, 15 Jun 2023 12:49:21 -0500 Subject: [PATCH] Allow apply system prompt changes to current chat. --- src/lib/ChatSettingsModal.svelte | 16 ++++++++++++---- src/lib/Profiles.svelte | 21 ++++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/lib/ChatSettingsModal.svelte b/src/lib/ChatSettingsModal.svelte index a282f3d..74eac4d 100644 --- a/src/lib/ChatSettingsModal.svelte +++ b/src/lib/ChatSettingsModal.svelte @@ -1,5 +1,5 @@ @@ -322,6 +327,9 @@ Start New Chat Using Profile + + Apply Prompts to Current Chat + { return mergeProfileFields(settings, currentSummaryPrompt, Math.floor(maxTokens * 0.75)).trim() } +export const setSystemPrompt = (chatId: number) => { + const chat = getChat(chatId) + const systemPromptMessage:Message = { + role: 'system', + content: prepareProfilePrompt(chatId), + uuid: uuidv4() + } + if (chat.messages[0]?.role === 'system') deleteMessage(chatId, chat.messages[0].uuid) + chat.messages.unshift(systemPromptMessage) + saveChatStore() +} + // Restart currently loaded profile export const restartProfile = (chatId:number, noApply:boolean = false) => { const settings = getChatSettings(chatId) @@ -96,12 +108,7 @@ export const restartProfile = (chatId:number, noApply:boolean = false) => { // Clear current messages clearMessages(chatId) // Add the system prompt - const systemPromptMessage:Message = { - role: 'system', - content: prepareProfilePrompt(chatId), - uuid: uuidv4() - } - addMessage(chatId, systemPromptMessage) + setSystemPrompt(chatId) // Add trainingPrompts, if any if (settings.trainingPrompts) {