diff --git a/public/script.js b/public/script.js index e25b9e4ef..85ac548ee 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 a97deda73..421eb65b1 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}`; } @@ -221,7 +227,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();