⎗ ✓ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47diff --git a/index.js b/index.js index 1a1bcb9..27c8b7b 100644 --- a/index.js +++ b/index.js @@ -330,14 +330,22 @@ eventSource.on(event_types.CHAT_COMPLETION_PROMPT_READY, async (data) => { const n = data.chat.length - system_message_count; const messages = data.chat.slice(-n); const separator = { newline: '\n', space: ' ' }[activeSet.messages_separator] || '\n\n'; + let lastMessage = null; + // Only separate last assistant message if we're not squashing as assistant + if (messages[messages.length - 1].role === MessageRole.ASSISTANT && + extension_settings.NoAss.squash_role !== MessageRole.ASSISTANT) { + lastMessage = messages.pop(); + } + + // Build chat history from remaining messages let chatHistory = messages.slice(1).reduce((history, message, idx) => { const timestampDict = { timestamp: getSendDate(idx) }; let prefix = substituteParamsExtended(message.role === MessageRole.USER ? activeSet.user_prefix : activeSet.char_prefix, timestampDict); - let suffix = substituteParamsExtended(message.role === MessageRole.USER ? activeSet.user_suffix: activeSet.char_suffix, timestampDict); + let suffix = substituteParamsExtended(message.role === MessageRole.USER ? activeSet.user_suffix : activeSet.char_suffix, timestampDict); return `${history}${separator}${prefix}${message.content}${suffix}`; }, messages[0].content); - + if (extension_settings.NoAss.enable_zero_prefill) { const pseudoPrefill = separator + substituteParamsExtended(activeSet.char_prefix, {timestamp: getSendDate()}); chatHistory += (messages[messages.length - 1].role === MessageRole.ASSISTANT ? '' : pseudoPrefill); @@ -351,11 +359,17 @@ eventSource.on(event_types.CHAT_COMPLETION_PROMPT_READY, async (data) => { }; } + // Replace messages with squashed history data.chat.splice(-n, n, { role: extension_settings.NoAss.squash_role, content: chatHistory }); + // If we had a last assistant message, add it back + if (lastMessage) { + data.chat.push(lastMessage); + } + if (extension_settings.NoAss.human_prompt_active) { const humanPromptBefore = substituteParamsExtended(extension_settings.NoAss.human_prompt_before, { timestamp: getSendDate() }); const humanPromptAfter = substituteParamsExtended(extension_settings.NoAss.human_prompt_after, { timestamp: getSendDate() });
Warning LINK You are about to visit a link which has been flagged with the above content warnings. Do you wish to continue? Continue Cancel