From 080ecec5f2bb23e84eb564b2c2553f4812560d07 Mon Sep 17 00:00:00 2001 From: kingbri Date: Sat, 1 Jul 2023 15:27:44 -0400 Subject: [PATCH 1/3] Chat: Add AI reply prefixes Experimentation yields that prefixing a reply with something drives the AI to possibly produce more targeted and meaningful conversation. The example I used is showing an AI's "thoughts" in a message via the use of backticks. By automatically prefixing {{char}}'s thoughts, the AI generates an internal monologue that the user can also use for their own responses. This feature is stable, but in an experimental state for now in terms of expansion. Signed-off-by: kingbri --- public/index.html | 13 ++++++++ public/script.js | 59 +++++++++++++++++++++--------------- public/scripts/power-user.js | 15 +++++++++ 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/public/index.html b/public/index.html index d79a81d92..185f96e75 100644 --- a/public/index.html +++ b/public/index.html @@ -1851,6 +1851,19 @@
+

+ + Start Reply With + +

+
+ +
+

Pygmalion Formatting diff --git a/public/script.js b/public/script.js index 898cffaa8..d7af2e276 100644 --- a/public/script.js +++ b/public/script.js @@ -1062,6 +1062,11 @@ function messageFormatting(mes, ch_name, isSystem, isUser) { mes = ''; } + // Prompt bias replacement should be applied on the raw message + if (!power_user.show_user_prompt_bias && ch_name && !isUser && !isSystem) { + mes = mes.replaceAll(substituteParams(power_user.user_prompt_bias), ""); + } + if (power_user.auto_fix_generated_markdown) { mes = fixMarkdown(mes); } @@ -1122,7 +1127,6 @@ function messageFormatting(mes, ch_name, isSystem, isUser) { //console.log('mes after removed ') //console.log(mes) } */ - return mes; } @@ -2308,7 +2312,17 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, if (!mesSendString.endsWith('\n')) { mesSendString += '\n'; } - mesSendString += (`${name2}:${promptBias || ''}`); + + let addedPromptBias = promptBias || substituteParams(power_user.user_prompt_bias) || ''; + + // Add a leading space to the prompt bias if applicable + if (addedPromptBias.length !== 0 && !addedPromptBias.startsWith(' ')) { + addedPromptBias = ` ${addedPromptBias}` + } + + mesSendString += (`${name2}:${addedPromptBias}`); + } else if (power_user.user_prompt_bias) { + mesSendString += substituteParams(power_user.user_prompt_bias); } return mesSendString; @@ -3309,32 +3323,29 @@ function extractTitleFromData(data) { } function extractMessageFromData(data) { - let getMessage = ""; - - if (main_api == 'kobold') { - getMessage = data.results[0].text; + switch (main_api) { + case 'kobold': + return data.results[0].text; + case 'koboldhorde': + return data.text; + case 'textgenerationwebui': + return data.results[0].text; + case 'novel': + return data.output; + case 'openai': + case 'poe': + return data; + default: + return '' } - - if (main_api == 'koboldhorde') { - getMessage = data.text; - } - - if (main_api == 'textgenerationwebui') { - getMessage = data.results[0].text; - } - - if (main_api == 'novel') { - getMessage = data.output; - } - - if (main_api == 'openai' || main_api == 'poe') { - getMessage = data; - } - - return getMessage; } function cleanUpMessage(getMessage, isImpersonate, displayIncompleteSentences = false) { + // Append the user bias first before trimming anything else + if (power_user.user_prompt_bias && power_user.user_prompt_bias.length !== 0) { + getMessage = substituteParams(power_user.user_prompt_bias) + getMessage; + } + if (!displayIncompleteSentences && power_user.trim_sentences) { getMessage = end_trim_to_sentence(getMessage, power_user.include_newline); } diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index dcc355be5..d13f58374 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -101,6 +101,8 @@ let power_user = { trim_sentences: false, include_newline: false, always_force_name2: false, + user_prompt_bias: '', + show_user_prompt_bias: true, multigen: false, multigen_first_chunk: 50, multigen_next_chunks: 30, @@ -598,6 +600,8 @@ function loadPowerUserSettings(settings, data) { $("#waifuMode").prop("checked", power_user.waifuMode); $("#movingUImode").prop("checked", power_user.movingUI); $("#noShadowsmode").prop("checked", power_user.noShadows); + $("#start_reply_with").val(power_user.user_prompt_bias); + $("#chat-show-reply-prefix-checkbox").prop("checked", power_user.show_user_prompt_bias); $("#multigen").prop("checked", power_user.multigen); $("#multigen_first_chunk").val(power_user.multigen_first_chunk); $("#multigen_next_chunks").val(power_user.multigen_next_chunks); @@ -1074,6 +1078,17 @@ $(document).ready(() => { reloadMarkdownProcessor(power_user.render_formulas); }); + $("#start_reply_with").on('input', function() { + power_user.user_prompt_bias = $(this).val(); + saveSettingsDebounced(); + }); + + $("#chat-show-reply-prefix-checkbox").change(function () { + power_user.show_user_prompt_bias = !!$(this).prop("checked"); + reloadCurrentChat(); + saveSettingsDebounced(); + }) + $("#multigen").change(function () { power_user.multigen = $(this).prop("checked"); saveSettingsDebounced(); From 990a5faf7d2301fad1e8528ac079d68a3625a86a Mon Sep 17 00:00:00 2001 From: kingbri Date: Sat, 1 Jul 2023 16:37:39 -0400 Subject: [PATCH 2/3] Generate: Move reply prefix call to common function Helps pass down user biases to OpenAI's prompt builder. Signed-off-by: kingbri --- public/script.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/public/script.js b/public/script.js index d7af2e276..a49f663cb 100644 --- a/public/script.js +++ b/public/script.js @@ -1996,7 +1996,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, deactivateSendButtons(); - let { messageBias, promptBias } = getBiasStrings(textareaText, type); + let { messageBias, promptBias, isUserPromptBias } = getBiasStrings(textareaText, type); //********************************* //PRE FORMATING STRING @@ -2071,7 +2071,8 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, storyString += appendToStoryString(Scenario, power_user.disable_scenario_formatting ? '' : 'Circumstances and context of the dialogue: '); } - if (promptBias || power_user.always_force_name2 || is_pygmalion) { + // kingbri MARK: - Make sure the prompt bias isn't the same as the user bias + if ((promptBias && !isUserPromptBias) || power_user.always_force_name2 || is_pygmalion) { force_name2 = true; } @@ -2313,15 +2314,19 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, mesSendString += '\n'; } - let addedPromptBias = promptBias || substituteParams(power_user.user_prompt_bias) || ''; - // Add a leading space to the prompt bias if applicable - if (addedPromptBias.length !== 0 && !addedPromptBias.startsWith(' ')) { - addedPromptBias = ` ${addedPromptBias}` + if (!promptBias || promptBias.length === 0) { + console.debug("No prompt bias was found."); + mesSendString += `${name2}:`; + } else if (promptBias.startsWith(' ')) { + console.debug(`A prompt bias with a leading space was found: ${promptBias}`); + mesSendString += `${name2}:${promptBias}` + } else { + console.debug(`A prompt bias was found: ${promptBias}`); + mesSendString += `${name2}: ${promptBias}`; } - - mesSendString += (`${name2}:${addedPromptBias}`); } else if (power_user.user_prompt_bias) { + console.debug(`A prompt bias was found without character's name appended: ${promptBias}`); mesSendString += substituteParams(power_user.user_prompt_bias); } @@ -2735,8 +2740,14 @@ export function getBiasStrings(textareaText, type) { } } - promptBias = messageBias || promptBias || ''; - return { messageBias, promptBias }; + promptBias = messageBias || promptBias || power_user.user_prompt_bias || ''; + const isUserPromptBias = promptBias === power_user.user_prompt_bias; + + // Substitute params for everything + messageBias = substituteParams(messageBias); + promptBias = substituteParams(promptBias); + + return { messageBias, promptBias, isUserPromptBias }; } function formatMessageHistoryItem(chatItem, isInstruct) { From 37219c3370fe447a27ea05e126b8ff553eb88426 Mon Sep 17 00:00:00 2001 From: kingbri Date: Sat, 1 Jul 2023 19:50:13 -0400 Subject: [PATCH 3/3] Formatting: Switch reply prefix to textarea Fixes newline formatting. Signed-off-by: kingbri --- public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/index.html b/public/index.html index 185f96e75..da0e6fbb0 100644 --- a/public/index.html +++ b/public/index.html @@ -1857,7 +1857,7 @@

- +