diff --git a/public/scripts/extensions/infinity-context/index.js b/public/scripts/extensions/infinity-context/index.js index 30f8f10f4..6d52d70f4 100644 --- a/public/scripts/extensions/infinity-context/index.js +++ b/public/scripts/extensions/infinity-context/index.js @@ -20,6 +20,11 @@ const defaultSettings = { n_results_max: 500, n_results_step: 1, + chroma_depth: 20, + chroma_depth_min: -1, + chroma_depth_max: 500, + chroma_depth_step: 1, + split_length: 384, split_length_min: 64, split_length_max: 4096, @@ -100,17 +105,29 @@ async function loadSettings() { $('#chromadb_n_results').val(extension_settings.chromadb.n_results).trigger('input'); $('#chromadb_split_length').val(extension_settings.chromadb.split_length).trigger('input'); $('#chromadb_file_split_length').val(extension_settings.chromadb.file_split_length).trigger('input'); - $('#chromadb_keep_context_proportion').val(extension_settings.chromadb.keep_context_proportion).trigger('input'); + $('#chromadb_keep_context_proportion').val(extension_settings.chromadb.keep_context_proportion).trigger('input'); + $('#chromadb_custom_depth').val(extension_settings.chromadb.chroma_depth).trigger('input'); + $('#chromadb_custom_msg').val(extension_settings.chromadb.recall_msg).trigger('input'); $('#chromadb_auto_adjust').prop('checked', extension_settings.chromadb.auto_adjust); $('#chromadb_freeze').prop('checked', extension_settings.chromadb.freeze); enableDisableSliders(); + onStrategyChange(); } function onStrategyChange() { console.debug('changing chromadb strat'); extension_settings.chromadb.strategy = $('#chromadb_strategy').val(); - - //$('#chromadb_strategy').select(extension_settings.chromadb.strategy); + if(extension_settings.chromadb.strategy === "custom"){ + $('#chromadb_custom_depth').show(); + $('label[for="chromadb_custom_depth"]').show(); + $('#chromadb_custom_msg').show(); + $('label[for="chromadb_custom_msg"]').show(); + } else { + $('#chromadb_custom_depth').hide(); + $('label[for="chromadb_custom_depth"]').hide(); + $('#chromadb_custom_msg').hide(); + $('label[for="chromadb_custom_msg"]').hide(); + } saveSettingsDebounced(); } @@ -133,6 +150,17 @@ function onNResultsInput() { saveSettingsDebounced(); } +function onChromaDepthInput() { + extension_settings.chromadb.chroma_depth = Number($('#chromadb_custom_depth').val()); + $('#chromadb_custom_depth_value').text(extension_settings.chromadb.chroma_depth); + saveSettingsDebounced(); +} + +function onChromaMsgInput() { + extension_settings.chromadb.recall_msg = $('#chromadb_custom_msg').val(); + saveSettingsDebounced(); +} + function onSplitLengthInput() { extension_settings.chromadb.split_length = Number($('#chromadb_split_length').val()); $('#chromadb_split_length_value').text(extension_settings.chromadb.split_length); @@ -490,6 +518,8 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { const currentChatId = getCurrentChatId(); const selectedStrategy = extension_settings.chromadb.strategy; const recallStrategy = extension_settings.chromadb.recall_strategy; + const recallMsg = extension_settings.chromadb.recall_msg; + const chromaDepth = extension_settings.chromadb.chroma_depth; if (currentChatId) { const messagesToStore = chat.slice(0, -extension_settings.chromadb.keep_context); @@ -538,7 +568,35 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { ); chat.splice(chat.length, 0, ...newChat); } - + if (selectedStrategy === 'custom') { + const context = getContext(); + const charname = context.name2; + newChat.push( + { + is_name: false, + is_user: false, + mes: recallMsg + " [", + name: "system", + send_date: 0, + } + ); + newChat.push(...queriedMessages.map(m => m.meta).filter(onlyUnique).map(JSON.parse)); + newChat.push( + { + is_name: false, + is_user: false, + mes: `]\n`, + name: "system", + send_date: 0, + } + ); + if(chromaDepth === -1){ + chat.splice(messagesToStore.length, 0, ...newChat); + } + else{ + chat.splice(chromaDepth, 0, ...newChat); + } + } if (selectedStrategy === 'original') { //removes .length # messages from the start of 'kept messages' //replaces them with chromaDB results (with no separator) @@ -552,6 +610,7 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => { } } + function onFreezeInput() { extension_settings.chromadb.freeze = $('#chromadb_freeze').is(':checked'); saveSettingsDebounced(); @@ -597,7 +656,12 @@ jQuery(async () => { + + + + Memory Recall Strategy