mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge pull request #205 from mdude1324/mdude/avoid-memory-last-chat
Avoid memory on most recent chat
This commit is contained in:
@ -119,6 +119,7 @@ function getLatestMemoryFromChat(chat) {
|
||||
}
|
||||
|
||||
const reversedChat = chat.slice().reverse();
|
||||
reversedChat.shift();
|
||||
for (let mes of reversedChat) {
|
||||
if (mes.extra && mes.extra.memory) {
|
||||
return mes.extra.memory;
|
||||
@ -194,7 +195,8 @@ async function summarizeChat(context) {
|
||||
const chat = context.chat;
|
||||
const longMemory = getLatestMemoryFromChat(chat);
|
||||
const reversedChat = chat.slice().reverse();
|
||||
const preSummaryLastMessage = getStringHash(chat.length ? chat[chat.length - 1] : '');
|
||||
reversedChat.shift();
|
||||
const preSummaryLastMessage = getStringHash(reversedChat.length ? reversedChat[reversedChat.length - 1] : '');
|
||||
let memoryBuffer = [];
|
||||
|
||||
for (let mes of reversedChat) {
|
||||
@ -254,7 +256,7 @@ async function summarizeChat(context) {
|
||||
const summary = data.summary;
|
||||
|
||||
const newContext = getContext();
|
||||
const postSummaryLastMessage = getStringHash(newContext.chat.length ? newContext.chat[newContext.chat.length - 1] : '');
|
||||
const postSummaryLastMessage = getStringHash(newContext.chat.length ? newContext.chat[newContext.chat.length - 2] : '');
|
||||
|
||||
// something changed during summarization request
|
||||
if (postSummaryLastMessage !== preSummaryLastMessage
|
||||
@ -280,6 +282,7 @@ function onMemoryRestoreClick() {
|
||||
const context = getContext();
|
||||
const content = $('#memory_contents').val();
|
||||
const reversedChat = context.chat.slice().reverse();
|
||||
reversedChat.shift();
|
||||
|
||||
for (let mes of reversedChat) {
|
||||
if (mes.extra && mes.extra.memory == content) {
|
||||
@ -303,7 +306,8 @@ function setMemoryContext(value, saveToMessage) {
|
||||
$('#memory_contents').val(value);
|
||||
|
||||
if (saveToMessage && context.chat.length) {
|
||||
const mes = context.chat[context.chat.length - 1];
|
||||
const idx = context.chat.length - 2;
|
||||
const mes = context.chat[idx < 0 ? 0 : idx];
|
||||
|
||||
if (!mes.extra) {
|
||||
mes.extra = {};
|
||||
|
Reference in New Issue
Block a user