Summarize the chat messages handed to the embedding beforehand

This commit is contained in:
Kristan Schlikow 2024-04-10 00:00:12 +02:00
parent 8a4b675143
commit 59abee3043
No known key found for this signature in database
GPG Key ID: B92ED0CBF4AD31EA
1 changed files with 17 additions and 1 deletions

View File

@ -1,4 +1,15 @@
import { eventSource, event_types, extension_prompt_types, getCurrentChatId, getRequestHeaders, is_send_press, saveSettingsDebounced, setExtensionPrompt, substituteParams } from '../../../script.js';
import {
eventSource,
event_types,
extension_prompt_types,
getCurrentChatId,
getRequestHeaders,
is_send_press,
saveSettingsDebounced,
setExtensionPrompt,
substituteParams,
generateRaw,
} from '../../../script.js';
import { ModuleWorkerWrapper, extension_settings, getContext, modules, renderExtensionTemplateAsync } from '../../extensions.js';
import { collapseNewlines } from '../../power-user.js';
import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js';
@ -141,6 +152,11 @@ async function synchronizeChat(batchSize = 5) {
const newVectorItems = hashedMessages.filter(x => !hashesInCollection.includes(x.hash));
const deletedHashes = hashesInCollection.filter(x => !hashedMessages.some(y => y.hash === x));
const sysPrompt = 'Pause your roleplay. Summarize the most important parts of the message. Your response should include nothing but the summary.';
for (let i = 0; i < hashedMessages.length; i++) {
hashedMessages[i].text = await generateRaw(hashedMessages[i].text, '', false, false, sysPrompt);
}
if (newVectorItems.length > 0) {
const chunkedBatch = splitByChunks(newVectorItems.slice(0, batchSize));
console.log(`Vectors: Found ${newVectorItems.length} new items. Processing ${batchSize}...`);