From 8401cc6032d389bd956f80749587381aab6bcb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Kragelund=20J=C3=B8rgensen?= Date: Thu, 12 Sep 2024 01:58:58 +0200 Subject: [PATCH 1/7] fix: append continuation message after prefill --- src/prompt-converters.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/prompt-converters.js b/src/prompt-converters.js index 5d52adb6e..c41ad8da9 100644 --- a/src/prompt-converters.js +++ b/src/prompt-converters.js @@ -132,7 +132,9 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi }); // Shouldn't be conditional anymore, messages api expects the last role to be user unless we're explicitly prefilling - if (prefillString) { + if (messages[messages.length - 1].role == 'assistant' && prefillString) { + messages[messages.length - 1].content = prefillString.trimEnd() + messages[messages.length - 1].content; + } else if (prefillString) { messages.push({ role: 'assistant', content: prefillString.trimEnd(), From d5f94577dc8d6e9f6c616cf3651e2c3430c81bff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Kragelund=20J=C3=B8rgensen?= Date: Sun, 15 Sep 2024 09:18:40 +0000 Subject: [PATCH 2/7] fix: dont trim prefill message, but do trim message --- src/prompt-converters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prompt-converters.js b/src/prompt-converters.js index c41ad8da9..104a7a9b2 100644 --- a/src/prompt-converters.js +++ b/src/prompt-converters.js @@ -133,7 +133,7 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi // Shouldn't be conditional anymore, messages api expects the last role to be user unless we're explicitly prefilling if (messages[messages.length - 1].role == 'assistant' && prefillString) { - messages[messages.length - 1].content = prefillString.trimEnd() + messages[messages.length - 1].content; + messages[messages.length - 1].content = prefillString + messages[messages.length - 1].content.trimEnd(); } else if (prefillString) { messages.push({ role: 'assistant', From aae934a84937a7219ca79f79a8562301e8b66ea2 Mon Sep 17 00:00:00 2001 From: Carsten Kragelund Date: Sat, 28 Sep 2024 22:36:56 +0000 Subject: [PATCH 3/7] fix: move prefill continuation handling to populateChatHistory --- public/scripts/openai.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index df798132b..5a45b3fbe 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -724,6 +724,12 @@ async function populateChatHistory(messages, prompts, chatCompletion, type = nul if (chatCompletion.canAfford(chatMessage)) { if (type === 'continue' && oai_settings.continue_prefill && chatPrompt === firstNonInjected) { + // in case we are using continue_prefill and the latest message is an assistant message, we want to prepend the users assistant prefill on the message + if (chatPrompt.role === 'assistant') { + const collection = new MessageCollection('continuePrefill', new Message(chatMessage.role, substituteParams(oai_settings.assistant_prefill + '\n\n') + chatMessage.content, chatMessage.identifier)); + chatCompletion.add(collection, -1); + continue; + } const collection = new MessageCollection('continuePrefill', chatMessage); chatCompletion.add(collection, -1); continue; @@ -1771,7 +1777,7 @@ async function sendOpenAIRequest(type, messages, signal) { generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings. generate_data['human_sysprompt_message'] = substituteParams(oai_settings.human_sysprompt_message); // Don't add a prefill on quiet gens (summarization) - if (!isQuiet) { + if (!isQuiet && !isContinue) { generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill); } } From 4966fb65f713f624a1244053ceedacdc718d098c Mon Sep 17 00:00:00 2001 From: Carsten Kragelund Date: Sat, 28 Sep 2024 22:46:23 +0000 Subject: [PATCH 4/7] fix: add assistant_prefill to request if people are using non prefill based continues --- public/scripts/openai.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 5a45b3fbe..a8fbd667f 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -1777,7 +1777,8 @@ async function sendOpenAIRequest(type, messages, signal) { generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings. generate_data['human_sysprompt_message'] = substituteParams(oai_settings.human_sysprompt_message); // Don't add a prefill on quiet gens (summarization) - if (!isQuiet && !isContinue) { + console.log(isContinue && oai_settings.continue_prefill); + if (!isQuiet && !(isContinue && oai_settings.continue_prefill)) { generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill); } } From 1711ef4e04bf274c1f0c3fed74f132b8e47ebcb2 Mon Sep 17 00:00:00 2001 From: Carsten Kragelund Date: Sat, 28 Sep 2024 23:34:38 +0000 Subject: [PATCH 5/7] fix: remove continue prefill logic from prompt-converters --- src/prompt-converters.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/prompt-converters.js b/src/prompt-converters.js index 104a7a9b2..5d52adb6e 100644 --- a/src/prompt-converters.js +++ b/src/prompt-converters.js @@ -132,9 +132,7 @@ function convertClaudeMessages(messages, prefillString, useSysPrompt, humanMsgFi }); // Shouldn't be conditional anymore, messages api expects the last role to be user unless we're explicitly prefilling - if (messages[messages.length - 1].role == 'assistant' && prefillString) { - messages[messages.length - 1].content = prefillString + messages[messages.length - 1].content.trimEnd(); - } else if (prefillString) { + if (prefillString) { messages.push({ role: 'assistant', content: prefillString.trimEnd(), From 7ac7398568c0c1c6fcf8e708f5a8eaf9feeb5c04 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 1 Oct 2024 00:37:33 +0300 Subject: [PATCH 6/7] Remove debug log. Fix comment --- public/scripts/openai.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index a8fbd667f..20c141316 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -1776,8 +1776,7 @@ async function sendOpenAIRequest(type, messages, signal) { generate_data['claude_use_sysprompt'] = oai_settings.claude_use_sysprompt; generate_data['stop'] = getCustomStoppingStrings(); // Claude shouldn't have limits on stop strings. generate_data['human_sysprompt_message'] = substituteParams(oai_settings.human_sysprompt_message); - // Don't add a prefill on quiet gens (summarization) - console.log(isContinue && oai_settings.continue_prefill); + // Don't add a prefill on quiet gens (summarization) and when using continue prefill. if (!isQuiet && !(isContinue && oai_settings.continue_prefill)) { generate_data['assistant_prefill'] = isImpersonate ? substituteParams(oai_settings.assistant_impersonation) : substituteParams(oai_settings.assistant_prefill); } From a23c31dd09e396934f4da76750efb509c0e60164 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:42:03 +0300 Subject: [PATCH 7/7] Update visuals and labels of CC postfix/prefix drawers --- public/index.html | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/public/index.html b/public/index.html index 741871edd..d272ca96a 100644 --- a/public/index.html +++ b/public/index.html @@ -1709,9 +1709,9 @@
-
+
Character Names Behavior - + ()
@@ -1720,25 +1720,22 @@
-
+
Continue Postfix - + ()