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 01/37] 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 5d52adb6ed..c41ad8da92 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 02/37] 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 c41ad8da92..104a7a9b23 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 03/37] 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 df798132bc..5a45b3fbe2 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 04/37] 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 5a45b3fbe2..a8fbd667f6 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 05/37] 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 104a7a9b23..5d52adb6ed 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 034a5a48c25b934398149503e0a69f63e2655669 Mon Sep 17 00:00:00 2001 From: RossAscends <124905043+RossAscends@users.noreply.github.com> Date: Sun, 29 Sep 2024 21:47:18 +0900 Subject: [PATCH 06/37] initial commit, functional, needs proofing --- public/index.html | 6 ++++- public/script.js | 32 +++++++++++++++++++------ public/scripts/power-user.js | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 8 deletions(-) diff --git a/public/index.html b/public/index.html index 13f59da05c..e6f70355a0 100644 --- a/public/index.html +++ b/public/index.html @@ -4011,6 +4011,10 @@

Compact Input Area + -