Optimize summarization on query

This commit is contained in:
Cohee 2024-10-15 23:27:18 +03:00
parent e3de69a235
commit 69283f511f
1 changed files with 6 additions and 14 deletions

View File

@ -706,25 +706,17 @@ const onChatEvent = debounce(async () => await moduleWorker.update(), debounce_t
* @returns {Promise<string>} Text to query
*/
async function getQueryText(chat, initiator) {
let queryText = '';
let i = 0;
let hashedMessages = chat.map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)) }));
let hashedMessages = chat
.map(x => ({ text: String(substituteParams(x.mes)), hash: getStringHash(substituteParams(x.mes)) }))
.filter(x => x.text)
.reverse()
.slice(0, settings.query);
if (initiator === 'chat' && settings.enabled_chats && settings.summarize && settings.summarize_sent) {
hashedMessages = await summarize(hashedMessages, settings.summary_source);
}
for (const message of hashedMessages.slice().reverse()) {
if (message.text) {
queryText += message.text + '\n';
i++;
}
if (i === settings.query) {
break;
}
}
const queryText = hashedMessages.map(x => x.text).join('\n');
return collapseNewlines(queryText).trim();
}