mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Split group weight and trigger%
This commit is contained in:
@ -74,6 +74,7 @@ const SORT_ORDER_KEY = 'world_info_sort_order';
|
||||
const METADATA_KEY = 'world_info';
|
||||
|
||||
const DEFAULT_DEPTH = 4;
|
||||
const DEFAULT_WEIGHT = 100;
|
||||
const MAX_SCAN_DEPTH = 1000;
|
||||
|
||||
/**
|
||||
@ -1093,6 +1094,7 @@ const originalDataKeyMap = {
|
||||
'automationId': 'extensions.automation_id',
|
||||
'vectorized': 'extensions.vectorized',
|
||||
'groupOverride': 'extensions.group_override',
|
||||
'groupWeight': 'extensions.group_weight',
|
||||
};
|
||||
|
||||
/** Checks the state of the current search, and adds/removes the search sorting option accordingly */
|
||||
@ -1466,11 +1468,24 @@ function getWorldEntry(name, data, entry) {
|
||||
const uid = $(this).data('uid');
|
||||
const value = $(this).prop('checked');
|
||||
data.entries[uid].groupOverride = value;
|
||||
setOriginalDataValue(data, uid, 'extensions.groupOverride', data.entries[uid].groupOverride);
|
||||
setOriginalDataValue(data, uid, 'extensions.group_override', data.entries[uid].groupOverride);
|
||||
saveWorldInfo(name, data);
|
||||
});
|
||||
groupOverrideInput.prop('checked', entry.groupOverride).trigger('input');
|
||||
|
||||
// group weight
|
||||
const groupWeightInput = template.find('input[name="groupWeight"]');
|
||||
groupWeightInput.data('uid', entry.uid);
|
||||
groupWeightInput.on('input', function () {
|
||||
const uid = $(this).data('uid');
|
||||
const value = Number($(this).val());
|
||||
|
||||
data.entries[uid].groupWeight = !isNaN(value) ? Math.abs(value) : 0;
|
||||
setOriginalDataValue(data, uid, 'extensions.group_weight', data.entries[uid].groupWeight);
|
||||
saveWorldInfo(name, data);
|
||||
});
|
||||
groupWeightInput.val(entry.groupWeight).trigger('input');
|
||||
|
||||
// probability
|
||||
if (entry.probability === undefined) {
|
||||
entry.probability = null;
|
||||
@ -1971,6 +1986,7 @@ const newEntryTemplate = {
|
||||
depth: DEFAULT_DEPTH,
|
||||
group: '',
|
||||
groupOverride: false,
|
||||
groupWeight: DEFAULT_WEIGHT,
|
||||
scanDepth: null,
|
||||
caseSensitive: null,
|
||||
matchWholeWords: null,
|
||||
@ -2424,7 +2440,7 @@ async function checkWorldInfo(chat, maxContext) {
|
||||
for (const entry of newEntries) {
|
||||
const rollValue = Math.random() * 100;
|
||||
|
||||
if (!entry.group && entry.useProbability && rollValue > entry.probability) {
|
||||
if (entry.useProbability && rollValue > entry.probability) {
|
||||
console.debug(`WI entry ${entry.uid} ${entry.key} failed probability check, skipping`);
|
||||
failedProbabilityChecks.add(entry);
|
||||
continue;
|
||||
@ -2633,14 +2649,14 @@ function filterByInclusionGroups(newEntries, allActivatedEntries, buffer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Do weighted random using probability of entry as weight
|
||||
const totalWeight = group.reduce((acc, item) => acc + item.probability, 0);
|
||||
// Do weighted random using entry's weight
|
||||
const totalWeight = group.reduce((acc, item) => acc + (item.groupWeight ?? DEFAULT_WEIGHT), 0);
|
||||
const rollValue = Math.random() * totalWeight;
|
||||
let currentWeight = 0;
|
||||
let winner = null;
|
||||
|
||||
for (const entry of group) {
|
||||
currentWeight += entry.probability;
|
||||
currentWeight += (entry.group_weight ?? DEFAULT_WEIGHT);
|
||||
|
||||
if (rollValue <= currentWeight) {
|
||||
console.debug(`Activated inclusion group '${key}' with roll winner entry '${entry.uid}'`, entry);
|
||||
@ -2684,6 +2700,7 @@ function convertAgnaiMemoryBook(inputObj) {
|
||||
useProbability: false,
|
||||
group: '',
|
||||
groupOverride: false,
|
||||
groupWeight: DEFAULT_WEIGHT,
|
||||
scanDepth: null,
|
||||
caseSensitive: null,
|
||||
matchWholeWords: null,
|
||||
@ -2721,6 +2738,7 @@ function convertRisuLorebook(inputObj) {
|
||||
useProbability: entry.activationPercent ?? false,
|
||||
group: '',
|
||||
groupOverride: false,
|
||||
groupWeight: DEFAULT_WEIGHT,
|
||||
scanDepth: null,
|
||||
caseSensitive: null,
|
||||
matchWholeWords: null,
|
||||
@ -2763,6 +2781,7 @@ function convertNovelLorebook(inputObj) {
|
||||
useProbability: false,
|
||||
group: '',
|
||||
groupOverride: false,
|
||||
groupWeight: DEFAULT_WEIGHT,
|
||||
scanDepth: null,
|
||||
caseSensitive: null,
|
||||
matchWholeWords: null,
|
||||
@ -2806,6 +2825,7 @@ function convertCharacterBook(characterBook) {
|
||||
selectiveLogic: entry.extensions?.selectiveLogic ?? world_info_logic.AND_ANY,
|
||||
group: entry.extensions?.group ?? '',
|
||||
groupOverride: entry.extensions?.group_override ?? false,
|
||||
groupWeight: entry.extensions?.group_weight ?? DEFAULT_WEIGHT,
|
||||
scanDepth: entry.extensions?.scan_depth ?? null,
|
||||
caseSensitive: entry.extensions?.case_sensitive ?? null,
|
||||
matchWholeWords: entry.extensions?.match_whole_words ?? null,
|
||||
|
Reference in New Issue
Block a user