diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js
index 5d5178e6d..9b259548e 100644
--- a/public/scripts/world-info.js
+++ b/public/scripts/world-info.js
@@ -35,6 +35,12 @@ const world_info_insertion_strategy = {
global_first: 2,
};
+const world_info_logic = {
+ AND: 0,
+ NOT_ALL: 1,
+ NOT_ONE: 2,
+};
+
let world_info = {};
let selected_world_info = [];
let world_names;
@@ -843,7 +849,7 @@ function getWorldEntry(name, data, entry) {
const uid = $(this).data('uid');
const value = Number($(this).val());
console.debug(`logic for ${entry.uid} set to ${value}`);
- data.entries[uid].selectiveLogic = !isNaN(value) ? value : 0;
+ data.entries[uid].selectiveLogic = !isNaN(value) ? value : world_info_logic.AND;
setOriginalDataValue(data, uid, 'selectiveLogic', data.entries[uid].selectiveLogic);
saveWorldInfo(name, data);
});
@@ -1365,7 +1371,7 @@ const newEntryTemplate = {
content: '',
constant: false,
selective: true,
- selectiveLogic: 0,
+ selectiveLogic: world_info_logic.AND,
addMemo: false,
order: 100,
position: 0,
@@ -1775,23 +1781,35 @@ async function checkWorldInfo(chat, maxContext) {
entry.keysecondary.length //ignore empties
) {
console.debug(`WI UID:${entry.uid} found. Checking logic: ${entry.selectiveLogic}`);
+ let hasAnyMatch = false;
secondary: for (let keysecondary of entry.keysecondary) {
const secondarySubstituted = substituteParams(keysecondary);
+ const hasSecondaryMatch = secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim());
console.debug(`WI UID:${entry.uid}: Filtering for secondary keyword - "${secondarySubstituted}".`);
-
- // Simplified AND/NOT if statement. (Proper fix for PR#1356 by Bronya)
- if (selectiveLogic === 0 && (secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim())) || // If AND logic and the main checks pass
- selectiveLogic === 1 && !(secondarySubstituted && matchKeys(textToScan, secondarySubstituted.trim()))) { // OR if NOT logic and the main checks do not pass
+
+ if (hasSecondaryMatch) {
+ hasAnyMatch = true;
+ }
+
+ // Simplified AND/NAND if statement. (Proper fix for PR#1356 by Bronya)
+ // If AND logic and the main checks pass OR if NOT logic and the main checks do not pass
+ if ((selectiveLogic === world_info_logic.AND && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) {
// Differ both logic statements in the debugger
- if (selectiveLogic === 0) {
+ if (selectiveLogic === world_info_logic.AND) {
console.debug(`(AND Check) Activating WI Entry ${entry.uid}. Found match for word: ${substituted} ${secondarySubstituted}`);
} else {
- console.debug(`(NOT Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword: ${secondarySubstituted}`);
+ console.debug(`(NOT AND Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword: ${secondarySubstituted}`);
}
activatedNow.add(entry);
break secondary;
}
}
+
+ // Handle NOT OR logic
+ if (selectiveLogic === world_info_logic.NOT_ONE && !hasAnyMatch) {
+ console.debug(`(NOT OR Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword.`);
+ activatedNow.add(entry);
+ }
// Handle cases where secondary is empty
} else {
console.debug(`WI UID ${entry.uid}: Activated without filter logic.`);
@@ -1956,6 +1974,7 @@ function convertAgnaiMemoryBook(inputObj) {
content: entry.entry,
constant: false,
selective: false,
+ selectiveLogic: world_info_logic.AND,
order: entry.weight,
position: 0,
disable: !entry.enabled,
@@ -1983,6 +2002,7 @@ function convertRisuLorebook(inputObj) {
content: entry.content,
constant: entry.alwaysActive,
selective: entry.selective,
+ selectiveLogic: world_info_logic.AND,
order: entry.insertorder,
position: world_info_position.before,
disable: false,
@@ -2015,6 +2035,7 @@ function convertNovelLorebook(inputObj) {
content: entry.text,
constant: false,
selective: false,
+ selectiveLogic: world_info_logic.AND,
order: entry.contextConfig?.budgetPriority ?? 0,
position: 0,
disable: !entry.enabled,
@@ -2056,7 +2077,7 @@ function convertCharacterBook(characterBook) {
probability: entry.extensions?.probability ?? null,
useProbability: entry.extensions?.useProbability ?? false,
depth: entry.extensions?.depth ?? DEFAULT_DEPTH,
- selectiveLogic: entry.extensions?.selectiveLogic ?? 0,
+ selectiveLogic: entry.extensions?.selectiveLogic ?? world_info_logic.AND,
group: entry.extensions?.group ?? '',
};
});
From 42c2170b6e89ffb01af29df99d28fa666a5c07e9 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Tue, 5 Dec 2023 02:28:04 +0200
Subject: [PATCH 2/5] AND => AND ONE, fix comments
---
public/index.html | 2 +-
public/scripts/world-info.js | 30 +++++++++++++++---------------
2 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/public/index.html b/public/index.html
index cd7afa5e3..94c4ea54c 100644
--- a/public/index.html
+++ b/public/index.html
@@ -4071,7 +4071,7 @@
Logic
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js
index 9b259548e..b084f39cc 100644
--- a/public/scripts/world-info.js
+++ b/public/scripts/world-info.js
@@ -36,7 +36,7 @@ const world_info_insertion_strategy = {
};
const world_info_logic = {
- AND: 0,
+ AND_ONE: 0,
NOT_ALL: 1,
NOT_ONE: 2,
};
@@ -849,7 +849,7 @@ function getWorldEntry(name, data, entry) {
const uid = $(this).data('uid');
const value = Number($(this).val());
console.debug(`logic for ${entry.uid} set to ${value}`);
- data.entries[uid].selectiveLogic = !isNaN(value) ? value : world_info_logic.AND;
+ data.entries[uid].selectiveLogic = !isNaN(value) ? value : world_info_logic.AND_ONE;
setOriginalDataValue(data, uid, 'selectiveLogic', data.entries[uid].selectiveLogic);
saveWorldInfo(name, data);
});
@@ -1371,7 +1371,7 @@ const newEntryTemplate = {
content: '',
constant: false,
selective: true,
- selectiveLogic: world_info_logic.AND,
+ selectiveLogic: world_info_logic.AND_ONE,
addMemo: false,
order: 100,
position: 0,
@@ -1791,23 +1791,23 @@ async function checkWorldInfo(chat, maxContext) {
hasAnyMatch = true;
}
- // Simplified AND/NAND if statement. (Proper fix for PR#1356 by Bronya)
- // If AND logic and the main checks pass OR if NOT logic and the main checks do not pass
- if ((selectiveLogic === world_info_logic.AND && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) {
+ // Simplified AND ONE / NOT ALL if statement. (Proper fix for PR#1356 by Bronya)
+ // If AND ONE logic and the main checks pass OR if NOT ALL logic and the main checks do not pass
+ if ((selectiveLogic === world_info_logic.AND_ONE && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) {
// Differ both logic statements in the debugger
- if (selectiveLogic === world_info_logic.AND) {
- console.debug(`(AND Check) Activating WI Entry ${entry.uid}. Found match for word: ${substituted} ${secondarySubstituted}`);
+ if (selectiveLogic === world_info_logic.AND_ONE) {
+ console.debug(`(AND ONE Check) Activating WI Entry ${entry.uid}. Found match for word: ${substituted} ${secondarySubstituted}`);
} else {
- console.debug(`(NOT AND Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword: ${secondarySubstituted}`);
+ console.debug(`(NOT ALL Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword: ${secondarySubstituted}`);
}
activatedNow.add(entry);
break secondary;
}
}
- // Handle NOT OR logic
+ // Handle NOT ONE logic
if (selectiveLogic === world_info_logic.NOT_ONE && !hasAnyMatch) {
- console.debug(`(NOT OR Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword.`);
+ console.debug(`(NOT ONE Check) Activating WI Entry ${entry.uid}, no secondary keywords found.`);
activatedNow.add(entry);
}
// Handle cases where secondary is empty
@@ -1974,7 +1974,7 @@ function convertAgnaiMemoryBook(inputObj) {
content: entry.entry,
constant: false,
selective: false,
- selectiveLogic: world_info_logic.AND,
+ selectiveLogic: world_info_logic.AND_ONE,
order: entry.weight,
position: 0,
disable: !entry.enabled,
@@ -2002,7 +2002,7 @@ function convertRisuLorebook(inputObj) {
content: entry.content,
constant: entry.alwaysActive,
selective: entry.selective,
- selectiveLogic: world_info_logic.AND,
+ selectiveLogic: world_info_logic.AND_ONE,
order: entry.insertorder,
position: world_info_position.before,
disable: false,
@@ -2035,7 +2035,7 @@ function convertNovelLorebook(inputObj) {
content: entry.text,
constant: false,
selective: false,
- selectiveLogic: world_info_logic.AND,
+ selectiveLogic: world_info_logic.AND_ONE,
order: entry.contextConfig?.budgetPriority ?? 0,
position: 0,
disable: !entry.enabled,
@@ -2077,7 +2077,7 @@ function convertCharacterBook(characterBook) {
probability: entry.extensions?.probability ?? null,
useProbability: entry.extensions?.useProbability ?? false,
depth: entry.extensions?.depth ?? DEFAULT_DEPTH,
- selectiveLogic: entry.extensions?.selectiveLogic ?? world_info_logic.AND,
+ selectiveLogic: entry.extensions?.selectiveLogic ?? world_info_logic.AND_ONE,
group: entry.extensions?.group ?? '',
};
});
From 0c6885a4534e0822b7e12c1699467e7b61c5c739 Mon Sep 17 00:00:00 2001
From: Bronya Rand
Date: Mon, 4 Dec 2023 18:40:33 -0600
Subject: [PATCH 3/5] fix comments and debug text
---
public/scripts/world-info.js | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js
index 9b259548e..aab4170c0 100644
--- a/public/scripts/world-info.js
+++ b/public/scripts/world-info.js
@@ -1791,25 +1791,26 @@ async function checkWorldInfo(chat, maxContext) {
hasAnyMatch = true;
}
- // Simplified AND/NAND if statement. (Proper fix for PR#1356 by Bronya)
- // If AND logic and the main checks pass OR if NOT logic and the main checks do not pass
+ // Simplified AND ONE/NOT ONE (AND/NOR) if statement. (Proper fix for PR#1356 by Bronya)
+ // If AND ONE logic and the main checks pass OR if NOT ONE logic and the main checks do not pass
if ((selectiveLogic === world_info_logic.AND && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) {
// Differ both logic statements in the debugger
if (selectiveLogic === world_info_logic.AND) {
- console.debug(`(AND Check) Activating WI Entry ${entry.uid}. Found match for word: ${substituted} ${secondarySubstituted}`);
+ console.debug(`(AND ONE Check) Activating WI Entry ${entry.uid}. Found match for word: ${substituted} ${secondarySubstituted}`);
} else {
- console.debug(`(NOT AND Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword: ${secondarySubstituted}`);
+ console.debug(`(NOT ONE Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword: ${secondarySubstituted}`);
}
activatedNow.add(entry);
break secondary;
}
}
- // Handle NOT OR logic
+ // Handle NOT ALL (NOT AND) logic
if (selectiveLogic === world_info_logic.NOT_ONE && !hasAnyMatch) {
- console.debug(`(NOT OR Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword.`);
+ console.debug(`(NOT ALL Check) Activating WI Entry ${entry.uid}. Found match for word "${substituted}" without secondary keyword.`);
activatedNow.add(entry);
}
+
// Handle cases where secondary is empty
} else {
console.debug(`WI UID ${entry.uid}: Activated without filter logic.`);
From d6649bf7d0bcc7a88647cc75d6431b6d7830e5c2 Mon Sep 17 00:00:00 2001
From: Bronya Rand
Date: Mon, 4 Dec 2023 18:44:49 -0600
Subject: [PATCH 4/5] update nums
---
public/scripts/world-info.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js
index a64bf426e..429e9d145 100644
--- a/public/scripts/world-info.js
+++ b/public/scripts/world-info.js
@@ -37,8 +37,8 @@ const world_info_insertion_strategy = {
const world_info_logic = {
AND_ONE: 0,
- NOT_ALL: 1,
- NOT_ONE: 2,
+ NOT_ONE: 1,
+ NOT_ALL: 2,
};
let world_info = {};
@@ -1793,7 +1793,7 @@ async function checkWorldInfo(chat, maxContext) {
// Simplified AND ONE / NOT ONE if statement. (Proper fix for PR#1356 by Bronya)
// If AND ONE logic and the main checks pass OR if NOT ONE logic and the main checks do not pass
- if ((selectiveLogic === world_info_logic.AND_ONE && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ALL && !hasSecondaryMatch)) {
+ if ((selectiveLogic === world_info_logic.AND_ONE && hasSecondaryMatch) || (selectiveLogic === world_info_logic.NOT_ONE && !hasSecondaryMatch)) {
// Differ both logic statements in the debugger
if (selectiveLogic === world_info_logic.AND_ONE) {
console.debug(`(AND ONE Check) Activating WI Entry ${entry.uid}. Found match for word: ${substituted} ${secondarySubstituted}`);
@@ -1806,7 +1806,7 @@ async function checkWorldInfo(chat, maxContext) {
}
// Handle NOT ALL logic
- if (selectiveLogic === world_info_logic.NOT_ONE && !hasAnyMatch) {
+ if (selectiveLogic === world_info_logic.NOT_ALL && !hasAnyMatch) {
console.debug(`(NOT ALL Check) Activating WI Entry ${entry.uid}, no secondary keywords found.`);
activatedNow.add(entry);
}
From c49f1555eaa95f71d7d883e6764acc9e125c9cfd Mon Sep 17 00:00:00 2001
From: Bronya Rand
Date: Mon, 4 Dec 2023 18:47:56 -0600
Subject: [PATCH 5/5] update ze html
---
public/index.html | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/public/index.html b/public/index.html
index 94c4ea54c..2c3d8f1f4 100644
--- a/public/index.html
+++ b/public/index.html
@@ -4072,8 +4072,8 @@
Logic