Reformat plugin code

This commit is contained in:
Cohee
2023-07-07 12:37:07 +03:00
parent 2edc34db81
commit bd74ea12ea

View File

@@ -123,7 +123,7 @@ async function loadSettings() {
function onStrategyChange() { function onStrategyChange() {
console.debug('changing chromadb strat'); console.debug('changing chromadb strat');
extension_settings.chromadb.strategy = $('#chromadb_strategy').val(); extension_settings.chromadb.strategy = $('#chromadb_strategy').val();
if(extension_settings.chromadb.strategy === "custom"){ if (extension_settings.chromadb.strategy === "custom") {
$('#chromadb_custom_depth').show(); $('#chromadb_custom_depth').show();
$('label[for="chromadb_custom_depth"]').show(); $('label[for="chromadb_custom_depth"]').show();
$('#chromadb_custom_msg').show(); $('#chromadb_custom_msg').show();
@@ -188,7 +188,7 @@ function onFileSplitLengthInput() {
function onChunkNLInput() { function onChunkNLInput() {
let shouldSplit = $('#onChunkNLInput').is(':checked'); let shouldSplit = $('#onChunkNLInput').is(':checked');
if(shouldSplit){ if (shouldSplit) {
extension_settings.chromadb.file_split_type = "newline"; extension_settings.chromadb.file_split_type = "newline";
} else { } else {
extension_settings.chromadb.file_split_type = "length"; extension_settings.chromadb.file_split_type = "length";
@@ -406,7 +406,7 @@ async function queryMultiMessages(chat_id, query) {
const context = getContext(); const context = getContext();
const response = await fetch("/getallchatsofcharacter", { const response = await fetch("/getallchatsofcharacter", {
method: 'POST', method: 'POST',
body: JSON.stringify({ avatar_url: context.characters[context.characterId].avatar}), body: JSON.stringify({ avatar_url: context.characters[context.characterId].avatar }),
headers: getRequestHeaders(), headers: getRequestHeaders(),
}); });
if (!response.ok) { if (!response.ok) {
@@ -451,7 +451,7 @@ async function onSelectInjectFile(e) {
extension_settings.chromadb.file_split_type = "newline"; extension_settings.chromadb.file_split_type = "newline";
//allow splitting on newlines or splitrecursively //allow splitting on newlines or splitrecursively
let split = []; let split = [];
if(extension_settings.chromadb.file_split_type == "newline"){ if (extension_settings.chromadb.file_split_type == "newline") {
split = text.split(/\r?\n/).filter(onlyUnique); split = text.split(/\r?\n/).filter(onlyUnique);
} else { } else {
split = splitRecursive(text, extension_settings.chromadb.file_split_length).filter(onlyUnique); split = splitRecursive(text, extension_settings.chromadb.file_split_length).filter(onlyUnique);
@@ -574,17 +574,17 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => {
let queriedMessages; let queriedMessages;
console.debug(recallStrategy) console.debug(recallStrategy)
if (lastMessage) { if (lastMessage) {
if (recallStrategy === 'multichat'){ if (recallStrategy === 'multichat') {
queriedMessages = await queryMultiMessages(currentChatId, lastMessage.mes); queriedMessages = await queryMultiMessages(currentChatId, lastMessage.mes);
} }
else{ else {
queriedMessages = await queryMessages(currentChatId, lastMessage.mes); queriedMessages = await queryMessages(currentChatId, lastMessage.mes);
} }
if(chromaSortStrategy === "date"){ if (chromaSortStrategy === "date") {
queriedMessages.sort((a, b) => a.date - b.date); queriedMessages.sort((a, b) => a.date - b.date);
} }
else{ else {
queriedMessages.sort((a, b) => b.distance - a.distance); queriedMessages.sort((a, b) => b.distance - a.distance);
} }
@@ -649,10 +649,10 @@ window.chromadb_interceptGeneration = async (chat, maxContext) => {
let chatset = new Set(chat.map(obj => obj.mes)); let chatset = new Set(chat.map(obj => obj.mes));
newChat = newChat.filter(obj => !chatset.has(obj.mes)); newChat = newChat.filter(obj => !chatset.has(obj.mes));
if(chromaDepth === -1){ if (chromaDepth === -1) {
chat.splice(chat.length, 0, ...newChat); chat.splice(chat.length, 0, ...newChat);
} }
else{ else {
chat.splice(chromaDepth, 0, ...newChat); chat.splice(chromaDepth, 0, ...newChat);
} }
} }