Merge pull request #653 from BlipRanger/feature/chroma-wi

Chroma Newline Chunking Option
This commit is contained in:
Cohee
2023-07-07 12:35:48 +03:00
committed by GitHub
2 changed files with 32 additions and 5 deletions
-1
View File
@@ -757,7 +757,6 @@ $.get("/csrf-token").then(async (data) => {
function checkOnlineStatus() {
///////// REMOVED LINES THAT DUPLICATE RA_CHeckOnlineStatus FEATURES
if (online_status == "no_connection") {
$("#online_status_indicator2").css("background-color", "red"); //Kobold
$("#online_status_text2").html("No connection...");
@@ -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.');
@@ -438,8 +448,14 @@ 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
let split = [];
if(extension_settings.chromadb.file_split_type == "newline"){
split = text.split(/\r?\n/).filter(onlyUnique);
} else {
split = splitRecursive(text, extension_settings.chromadb.file_split_length).filter(onlyUnique);
}
const baseDate = Date.now();
const messages = split.map((m, i) => ({
@@ -538,10 +554,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];
@@ -550,7 +575,6 @@ 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{
@@ -639,7 +663,6 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => {
chat.splice(0, messagesToStore.length, ...newChat);
}
console.log('ChromaDB chat after injection', chat);
}
}
}
@@ -725,6 +748,10 @@ jQuery(async () => {
<input type="checkbox" id="chromadb_auto_adjust" />
<span>Use % strategy</span>
</label>
<label class="checkbox_label" for="chromadb_chunk_nl" title="Chunk injected documents on newline instead of at set character size." >
<input type="checkbox" id="chromadb_chunk_nl" />
<span>Chunk on Newlines</span>
</label>
<div class="flex-container spaceEvenly">
<div id="chromadb_inject" title="Upload custom textual data to use in the context of the current chat" class="menu_button">
<i class="fa-solid fa-file-arrow-up"></i>
@@ -766,6 +793,7 @@ jQuery(async () => {
$('#chromadb_purge').on('click', onPurgeClick);
$('#chromadb_export').on('click', onExportClick);
$('#chromadb_freeze').on('input', onFreezeInput);
$('#chromadb_chunk_nl').on('input', onChunkNLInput);
$('#chromadb_auto_adjust').on('input', onAutoAdjustInput);
$('#chromadb_keep_context_proportion').on('input', onKeepContextProportionInput);
await loadSettings();