From 552936a0d8c623e2ffde13c074e99743a4cd40ce Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 19 Apr 2026 15:08:52 +0200 Subject: [PATCH] fix: exclude other group members' reasoning from prompt context in group chats (#5473) In group chats, only include reasoning from the currently generating character instead of all group members. This prevents reasoning from other characters being injected into the prompt context when generating responses. - Filter reasoning in coreChat loop based on message author matching name2 - Filter reasoning in setOpenAIMessages based on message author matching name2 - Add isOtherGroupMember check before adding reasoning to messages --- public/script.js | 24 +++++++++++++++--------- public/scripts/openai.js | 6 ++++-- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/public/script.js b/public/script.js index 3c0a5529d..aaa2040c1 100644 --- a/public/script.js +++ b/public/script.js @@ -4470,18 +4470,24 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro for (let i = coreChat.length - 1; i >= 0; i--) { const depth = coreChat.length - i - (isContinue ? 2 : 1); const isPrefix = isContinue && i === coreChat.length - 1; + + // In group chats, only include reasoning from the currently generating character + const isOtherGroupMember = selected_group && coreChat[i].name !== name2; + coreChat[i] = { ...coreChat[i], - mes: promptReasoning.addToMessage( - coreChat[i].mes, - getRegexedString( - String(coreChat[i].extra?.reasoning ?? ''), - regex_placement.REASONING, - { isPrompt: true, depth: depth }, + mes: isOtherGroupMember + ? coreChat[i].mes + : promptReasoning.addToMessage( + coreChat[i].mes, + getRegexedString( + String(coreChat[i].extra?.reasoning ?? ''), + regex_placement.REASONING, + { isPrompt: true, depth: depth }, + ), + isPrefix, + coreChat[i].extra?.reasoning_duration, ), - isPrefix, - coreChat[i].extra?.reasoning_duration, - ), }; if (promptReasoning.isLimitReached()) { break; diff --git a/public/scripts/openai.js b/public/scripts/openai.js index dda588fa2..fdba275f3 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -604,8 +604,10 @@ function setOpenAIMessages(chat) { const originApi = chat[j]?.extra?.api; const originModel = chat[j]?.extra?.model; const isSameModel = originApi === currentApi && originModel === currentModel; - const signature = isSameModel ? chat[j]?.extra?.reasoning_signature : null; - const reasoning = isSameModel ? String(chat[j]?.extra?.reasoning ?? '') : ''; + // In group chats, only include reasoning from the currently generating character + const isOtherGroupMember = selected_group && chat[j].name !== name2; + const signature = isSameModel && !isOtherGroupMember ? chat[j]?.extra?.reasoning_signature : null; + const reasoning = isSameModel && !isOtherGroupMember ? String(chat[j]?.extra?.reasoning ?? '') : ''; // Remove reasoning metadata from invocations if the API/model don't match if (Array.isArray(invocations) && invocations.length > 0) {