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
This commit is contained in:
+15
-9
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user