From e9ce2853cc60fec7e73ae8282ba7f043922a87ee Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Mon, 3 Jul 2023 17:48:53 -0400 Subject: [PATCH 1/4] Allow split on newlines (wip) --- public/script.js | 2 +- .../extensions/infinity-context/index.js | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/public/script.js b/public/script.js index 33469565b..2a8ce192e 100644 --- a/public/script.js +++ b/public/script.js @@ -688,7 +688,7 @@ $.get("/csrf-token").then(async (data) => { function checkOnlineStatus() { ///////// REMOVED LINES THAT DUPLICATE RA_CHeckOnlineStatus FEATURES - + console.log(online_status); if (online_status == "no_connection") { $("#online_status_indicator2").css("background-color", "red"); //Kobold $("#online_status_text2").html("No connection..."); diff --git a/public/scripts/extensions/infinity-context/index.js b/public/scripts/extensions/infinity-context/index.js index ccc82031a..56282fb96 100644 --- a/public/scripts/extensions/infinity-context/index.js +++ b/public/scripts/extensions/infinity-context/index.js @@ -433,8 +433,13 @@ async function onSelectInjectFile(e) { try { toastr.info('This may take some time, depending on the file size', 'Processing...'); const text = await getFileText(file); - - const split = splitRecursive(text, extension_settings.chromadb.file_split_length).filter(onlyUnique); + extension_settings.chromadb.file_split_type = "newline"; + //allow splitting on newlines or splitrecursively + if(extension_settings.chromadb.file_split_type == "newline"){ + var split = text.split(/\r?\n/).filter(onlyUnique); + } else { + const split = splitRecursive(text, extension_settings.chromadb.file_split_length).filter(onlyUnique); + } const baseDate = Date.now(); const messages = split.map((m, i) => ({ @@ -533,10 +538,19 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { let recallMsg = extension_settings.chromadb.recall_msg || defaultSettings.chroma_default_msg; const chromaDepth = extension_settings.chromadb.chroma_depth; const chromaSortStrategy = extension_settings.chromadb.sort_strategy; + + //log the current settings + console.debug("CHROMADB: Current settings: %o", extension_settings.chromadb); + + if (currentChatId) { const messagesToStore = chat.slice(0, -extension_settings.chromadb.keep_context); + //log the messages to store + console.debug("CHROMADB: Messages to store: %o", messagesToStore); if (messagesToStore.length > 0 || extension_settings.chromadb.freeze) { + //log the messages to store length vs keep context + console.debug("CHROMADB: Messages to store length vs keep context: %o vs %o", messagesToStore.length, extension_settings.chromadb.keep_context); await addMessages(currentChatId, messagesToStore); const lastMessage = chat[chat.length - 1]; @@ -549,13 +563,16 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { queriedMessages = await queryMultiMessages(currentChatId, lastMessage.mes); } else{ + console.log("Utilizing single chat"); queriedMessages = await queryMessages(currentChatId, lastMessage.mes); } if(chromaSortStrategy === "date"){ + console.log("Sorting by date"); queriedMessages.sort((a, b) => a.date - b.date); } else{ + console.log("Sorting by distance"); queriedMessages.sort((a, b) => b.distance - a.distance); } @@ -630,7 +647,11 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { if (selectedStrategy === 'original') { //removes .length # messages from the start of 'kept messages' //replaces them with chromaDB results (with no separator) + console.log('ChromaDB chat before injection', chat); + console.log('ChromaDB newChat', newChat); + console.log('ChromaDB queriedMessages', queriedMessages); newChat.push(...queriedMessages.map(m => m.meta).filter(onlyUnique).map(JSON.parse)); + console.log('ChromaDB newChat after push', newChat); chat.splice(0, messagesToStore.length, ...newChat); } From f854609512d11b10c92120bcfe7b350c0e5aedcb Mon Sep 17 00:00:00 2001 From: BlipRanger <1860540+BlipRanger@users.noreply.github.com> Date: Fri, 7 Jul 2023 00:23:28 -0400 Subject: [PATCH 2/4] Option to split on newlines --- .../extensions/infinity-context/index.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/public/scripts/extensions/infinity-context/index.js b/public/scripts/extensions/infinity-context/index.js index a2f3bd56d..6230a8fad 100644 --- a/public/scripts/extensions/infinity-context/index.js +++ b/public/scripts/extensions/infinity-context/index.js @@ -186,6 +186,16 @@ function onFileSplitLengthInput() { saveSettingsDebounced(); } +function onChunkNLInput() { + let shouldSplit = $('#onChunkNLInput').is(':checked'); + if(shouldSplit){ + extension_settings.chromadb.file_split_type = "newline"; + } else { + extension_settings.chromadb.file_split_type = "length"; + } + saveSettingsDebounced(); +} + function checkChatId(chat_id) { if (!chat_id || chat_id.trim() === '') { toastr.error('Please select a character and try again.'); @@ -564,20 +574,16 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { console.debug(recallStrategy) if (lastMessage) { if (recallStrategy === 'multichat'){ - console.log("Utilizing multichat") queriedMessages = await queryMultiMessages(currentChatId, lastMessage.mes); } else{ - console.log("Utilizing single chat"); queriedMessages = await queryMessages(currentChatId, lastMessage.mes); } if(chromaSortStrategy === "date"){ - console.log("Sorting by date"); queriedMessages.sort((a, b) => a.date - b.date); } else{ - console.log("Sorting by distance"); queriedMessages.sort((a, b) => b.distance - a.distance); } @@ -652,15 +658,10 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { if (selectedStrategy === 'original') { //removes .length # messages from the start of 'kept messages' //replaces them with chromaDB results (with no separator) - console.log('ChromaDB chat before injection', chat); - console.log('ChromaDB newChat', newChat); - console.log('ChromaDB queriedMessages', queriedMessages); newChat.push(...queriedMessages.map(m => m.meta).filter(onlyUnique).map(JSON.parse)); - console.log('ChromaDB newChat after push', newChat); chat.splice(0, messagesToStore.length, ...newChat); } - console.log('ChromaDB chat after injection', chat); } } } @@ -746,6 +747,10 @@ jQuery(async () => { Use % strategy +