Use common methods for extras summary

This commit is contained in:
Cohee 2024-08-12 23:08:11 +03:00
parent 8685c2f471
commit 5b3388d0c8

View File

@ -65,7 +65,7 @@ async function getSourceContextSize() {
} }
if (extension_settings.source === summary_sources.extras) { if (extension_settings.source === summary_sources.extras) {
return 1024; return 1024 - 64;
} }
return getMaxContextSize(overrideLength); return getMaxContextSize(overrideLength);
@ -792,7 +792,7 @@ async function summarizeChatExtras(context) {
const reversedChat = chat.slice().reverse(); const reversedChat = chat.slice().reverse();
reversedChat.shift(); reversedChat.shift();
const memoryBuffer = []; const memoryBuffer = [];
const CONTEXT_SIZE = 1024 - 64; const CONTEXT_SIZE = await getSourceContextSize();
for (const message of reversedChat) { for (const message of reversedChat) {
// we reached the point of latest memory // we reached the point of latest memory
@ -810,14 +810,14 @@ async function summarizeChatExtras(context) {
memoryBuffer.push(entry); memoryBuffer.push(entry);
// check if token limit was reached // check if token limit was reached
const tokens = getTextTokens(tokenizers.GPT2, getMemoryString()).length; const tokens = await countSourceTokens(getMemoryString());
if (tokens >= CONTEXT_SIZE) { if (tokens >= CONTEXT_SIZE) {
break; break;
} }
} }
const resultingString = getMemoryString(); const resultingString = getMemoryString();
const resultingTokens = getTextTokens(tokenizers.GPT2, resultingString).length; const resultingTokens = await countSourceTokens(resultingString);
if (!resultingString || resultingTokens < CONTEXT_SIZE) { if (!resultingString || resultingTokens < CONTEXT_SIZE) {
console.debug('Not enough context to summarize'); console.debug('Not enough context to summarize');