Fix continue duplicating reasoning block

This commit is contained in:
Cohee
2025-03-04 00:42:50 +02:00
parent 7d568dd4e0
commit 7be6e0d5af
2 changed files with 57 additions and 8 deletions

View File

@@ -3135,8 +3135,9 @@ class StreamingProcessor {
* @param {boolean} forceName2 If true, force the use of name2
* @param {Date} timeStarted Date when generation was started
* @param {string} continueMessage Previous message if the type is 'continue'
* @param {PromptReasoning} promptReasoning Prompt reasoning instance
*/
constructor(type, forceName2, timeStarted, continueMessage) {
constructor(type, forceName2, timeStarted, continueMessage, promptReasoning) {
this.result = '';
this.messageId = -1;
/** @type {HTMLElement} */
@@ -3164,6 +3165,8 @@ class StreamingProcessor {
this.toolCalls = [];
// Initialize reasoning in its own handler
this.reasoningHandler = new ReasoningHandler(timeStarted);
/** @type {PromptReasoning} */
this.promptReasoning = promptReasoning;
}
#checkDomElements(messageId) {
@@ -3192,6 +3195,10 @@ class StreamingProcessor {
}
async onStartStreaming(text) {
if (this.type === 'continue' && this.promptReasoning.prefixReasoning) {
this.reasoningHandler.initContinue(this.promptReasoning);
}
let messageId = -1;
if (this.type == 'impersonate') {
@@ -3882,13 +3889,13 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
};
}));
const reasoning = new PromptReasoning();
const promptReasoning = new PromptReasoning();
for (let i = coreChat.length - 1; i >= 0; i--) {
const depth = coreChat.length - i - 1;
const isPrefix = isContinue && i === coreChat.length - 1;
coreChat[i] = {
...coreChat[i],
mes: reasoning.addToMessage(
mes: promptReasoning.addToMessage(
coreChat[i].mes,
getRegexedString(
String(coreChat[i].extra?.reasoning ?? ''),
@@ -3896,9 +3903,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
{ isPrompt: true, depth: depth },
),
isPrefix,
coreChat[i].extra?.reasoning_duration,
),
};
if (reasoning.isLimitReached()) {
if (promptReasoning.isLimitReached()) {
break;
}
}
@@ -4723,7 +4731,8 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
console.debug(`pushed prompt bits to itemizedPrompts array. Length is now: ${itemizedPrompts.length}`);
if (isStreamingEnabled() && type !== 'quiet') {
streamingProcessor = new StreamingProcessor(type, force_name2, generation_started, continue_mag);
continue_mag = promptReasoning.removePrefix(continue_mag);
streamingProcessor = new StreamingProcessor(type, force_name2, generation_started, continue_mag, promptReasoning);
if (isContinue) {
// Save reply does add cycle text to the prompt, so it's not needed here
streamingProcessor.firstMessageText = '';
@@ -4824,6 +4833,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
}
if (isContinue) {
continue_mag = promptReasoning.removePrefix(continue_mag);
getMessage = continue_mag + getMessage;
}