From 9ecf261a76f989cfaaa4a79590f0162c7f3194d3 Mon Sep 17 00:00:00 2001 From: pcpthm Date: Fri, 31 Jan 2025 21:06:15 +0900 Subject: [PATCH] Always add reasoning for continue --- public/script.js | 8 +++++--- public/scripts/reasoning.js | 12 +++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/public/script.js b/public/script.js index 9c9f8fc3a..76acef1d6 100644 --- a/public/script.js +++ b/public/script.js @@ -3863,10 +3863,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro const reasoning = new PromptReasoning(); for (let i = coreChat.length - 1; i >= 0; i--) { - if (reasoning.isLimitReached()) { - break; - } const depth = coreChat.length - i - 1; + const isPrefix = isContinue && i === coreChat.length - 1; coreChat[i] = { ...coreChat[i], mes: reasoning.addToMessage( @@ -3876,8 +3874,12 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro regex_placement.REASONING, { isPrompt: true, depth: depth }, ), + isPrefix, ), }; + if (reasoning.isLimitReached()) { + break; + } } // Determine token limit diff --git a/public/scripts/reasoning.js b/public/scripts/reasoning.js index 26f276600..74ce1db50 100644 --- a/public/scripts/reasoning.js +++ b/public/scripts/reasoning.js @@ -50,11 +50,12 @@ export class PromptReasoning { * Add reasoning to a message according to the power user settings. * @param {string} content Message content * @param {string} reasoning Message reasoning + * @param {boolean} isPrefix Whether this is the last message prefix * @returns {string} Message content with reasoning */ - addToMessage(content, reasoning) { + addToMessage(content, reasoning, isPrefix) { // Disabled or reached limit of additions - if (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions) { + if (!isPrefix && (!power_user.reasoning.add_to_prompts || this.counter >= power_user.reasoning.max_additions)) { return content; } @@ -71,6 +72,11 @@ export class PromptReasoning { const separator = substituteParams(power_user.reasoning.separator || ''); const suffix = substituteParams(power_user.reasoning.suffix || ''); + // Combine parts with reasoning only + if (isPrefix && !content) { + return `${prefix}${reasoning}`; + } + // Combine parts with reasoning and content return `${prefix}${reasoning}${suffix}${separator}${content}`; } @@ -218,7 +224,7 @@ function registerReasoningMacros() { MacrosParser.registerMacro('reasoningSeparator', () => power_user.reasoning.separator, t`Reasoning Separator`); } -function setReasoningEventHandlers(){ +function setReasoningEventHandlers() { $(document).on('click', '.mes_reasoning_copy', (e) => { e.stopPropagation(); e.preventDefault();