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
Signed| @@ -4470,18 +4470,24 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4470 | 4470 | for (let i = coreChat.length - 1; i >= 0; i--) { |
| 4471 | 4471 | const depth = coreChat.length - i - (isContinue ? 2 : 1); |
| 4472 | 4472 | const isPrefix = isContinue && i === coreChat.length - 1; |
| 4473 | + | |
| 4474 | + // In group chats, only include reasoning from the currently generating character | |
| 4475 | + const isOtherGroupMember = selected_group && coreChat[i].name !== name2; | |
| 4476 | + | |
| 4473 | 4477 | coreChat[i] = { |
| 4474 | 4478 | ...coreChat[i], |
| 4475 | 4479 | mes: promptReasoning.addToMessage(isOtherGroupMember |
| 4476 | 4480 | ? coreChat[i].mes, |
| 4477 | - getRegexedString( | |
| 4481 | + : promptReasoning.addToMessage( | |
| 4478 | 4482 | String(coreChat[i].extra?.reasoning ?? '')mes, |
| 4479 | - regex_placement.REASONING, | |
| 4483 | + getRegexedString( | |
| 4480 | - { isPrompt: true, depth: depth }, | |
| 4484 | + String(coreChat[i].extra?.reasoning ?? ''), | |
| 4485 | + regex_placement.REASONING, | |
| 4486 | + { isPrompt: true, depth: depth }, | |
| 4487 | + ), | |
| 4488 | + isPrefix, | |
| 4489 | + coreChat[i].extra?.reasoning_duration, | |
| 4481 | 4490 | ), |
| 4482 | - isPrefix, | |
| 4483 | - coreChat[i].extra?.reasoning_duration, | |
| 4484 | - ), | |
| 4485 | 4491 | }; |
| 4486 | 4492 | if (promptReasoning.isLimitReached()) { |
| 4487 | 4493 | break; |
| @@ -604,8 +604,10 @@ function setOpenAIMessages(chat) { | ||
| 604 | 604 | const originApi = chat[j]?.extra?.api; |
| 605 | 605 | const originModel = chat[j]?.extra?.model; |
| 606 | 606 | const isSameModel = originApi === currentApi && originModel === currentModel; |
| 607 | - const signature = isSameModel ? chat[j]?.extra?.reasoning_signature : null; | |
| 607 | + // In group chats, only include reasoning from the currently generating character | |
| 608 | 608 | const reasoningisOtherGroupMember = isSameModelselected_group ?&& String(chat[j]?.extra?.reasoning ?? '')name :!== ''name2; |
| 609 | + const signature = isSameModel && !isOtherGroupMember ? chat[j]?.extra?.reasoning_signature : null; | |
| 610 | + const reasoning = isSameModel && !isOtherGroupMember ? String(chat[j]?.extra?.reasoning ?? '') : ''; | |
| 609 | 611 | |
| 610 | 612 | // Remove reasoning metadata from invocations if the API/model don't match |
| 611 | 613 | if (Array.isArray(invocations) && invocations.length > 0) { |