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:
@ -360,6 +360,14 @@
|
|||||||
flex: 2 !important;
|
flex: 2 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.flex3 {
|
||||||
|
flex: 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.flex4 {
|
||||||
|
flex: 4;
|
||||||
|
}
|
||||||
|
|
||||||
.flexFlowColumn {
|
.flexFlowColumn {
|
||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
}
|
}
|
||||||
@ -563,4 +571,4 @@ textarea:disabled {
|
|||||||
height: 30px;
|
height: 30px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
@ -5197,7 +5197,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-container wide100p flexGap10">
|
<div class="flex-container wide100p flexGap10">
|
||||||
<div class="flex1 flex-container flexFlowColumn flexNoGap">
|
<div class="flex4 flex-container flexFlowColumn flexNoGap">
|
||||||
<div class="flex-container justifySpaceBetween">
|
<div class="flex-container justifySpaceBetween">
|
||||||
<small for="characterFilter" data-i18n="Filter to Character(s)">
|
<small for="characterFilter" data-i18n="Filter to Character(s)">
|
||||||
Filter to Character(s)
|
Filter to Character(s)
|
||||||
@ -5217,7 +5217,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex1 flex-container flexFlowColumn flexNoGap">
|
<div class="flex3 flex-container flexFlowColumn flexNoGap">
|
||||||
<div class="flex-container justifySpaceBetween">
|
<div class="flex-container justifySpaceBetween">
|
||||||
<small for="group" data-i18n="Inclusion Group">
|
<small for="group" data-i18n="Inclusion Group">
|
||||||
Inclusion Group
|
Inclusion Group
|
||||||
@ -5239,6 +5239,16 @@
|
|||||||
<input type="text" class="text_pole margin0" name="group" rows="1" data-i18n="[placeholder]Only one entry with the same label will be activated" placeholder="Only one entry with the same label will be activated">
|
<input type="text" class="text_pole margin0" name="group" rows="1" data-i18n="[placeholder]Only one entry with the same label will be activated" placeholder="Only one entry with the same label will be activated">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex1 flex-container flexFlowColumn flexNoGap" data-i18n="[title]A relative likelihood of entry activation within the group" title="A relative likelihood of entry activation within the group">
|
||||||
|
<div class="flex-container justifySpaceBetween marginBot5">
|
||||||
|
<small for="groupWeight" data-i18n="Group Weight">
|
||||||
|
Group Weight
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<div class="range-block-range">
|
||||||
|
<input type="number" class="text_pole margin0" name="groupWeight" rows="1" placeholder="100" min="0" max="999999">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div name="WIEntryBottomControls" class="flex-container flex1 justifySpaceBetween world_entry_form_horizontal">
|
<div name="WIEntryBottomControls" class="flex-container flex1 justifySpaceBetween world_entry_form_horizontal">
|
||||||
<div class="flex-container flexFlowColumn flexNoGap wi-enter-footer-text ">
|
<div class="flex-container flexFlowColumn flexNoGap wi-enter-footer-text ">
|
||||||
|
@ -74,6 +74,7 @@ const SORT_ORDER_KEY = 'world_info_sort_order';
|
|||||||
const METADATA_KEY = 'world_info';
|
const METADATA_KEY = 'world_info';
|
||||||
|
|
||||||
const DEFAULT_DEPTH = 4;
|
const DEFAULT_DEPTH = 4;
|
||||||
|
const DEFAULT_WEIGHT = 100;
|
||||||
const MAX_SCAN_DEPTH = 1000;
|
const MAX_SCAN_DEPTH = 1000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1093,6 +1094,7 @@ const originalDataKeyMap = {
|
|||||||
'automationId': 'extensions.automation_id',
|
'automationId': 'extensions.automation_id',
|
||||||
'vectorized': 'extensions.vectorized',
|
'vectorized': 'extensions.vectorized',
|
||||||
'groupOverride': 'extensions.group_override',
|
'groupOverride': 'extensions.group_override',
|
||||||
|
'groupWeight': 'extensions.group_weight',
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Checks the state of the current search, and adds/removes the search sorting option accordingly */
|
/** 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 uid = $(this).data('uid');
|
||||||
const value = $(this).prop('checked');
|
const value = $(this).prop('checked');
|
||||||
data.entries[uid].groupOverride = value;
|
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);
|
saveWorldInfo(name, data);
|
||||||
});
|
});
|
||||||
groupOverrideInput.prop('checked', entry.groupOverride).trigger('input');
|
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
|
// probability
|
||||||
if (entry.probability === undefined) {
|
if (entry.probability === undefined) {
|
||||||
entry.probability = null;
|
entry.probability = null;
|
||||||
@ -1971,6 +1986,7 @@ const newEntryTemplate = {
|
|||||||
depth: DEFAULT_DEPTH,
|
depth: DEFAULT_DEPTH,
|
||||||
group: '',
|
group: '',
|
||||||
groupOverride: false,
|
groupOverride: false,
|
||||||
|
groupWeight: DEFAULT_WEIGHT,
|
||||||
scanDepth: null,
|
scanDepth: null,
|
||||||
caseSensitive: null,
|
caseSensitive: null,
|
||||||
matchWholeWords: null,
|
matchWholeWords: null,
|
||||||
@ -2424,7 +2440,7 @@ async function checkWorldInfo(chat, maxContext) {
|
|||||||
for (const entry of newEntries) {
|
for (const entry of newEntries) {
|
||||||
const rollValue = Math.random() * 100;
|
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`);
|
console.debug(`WI entry ${entry.uid} ${entry.key} failed probability check, skipping`);
|
||||||
failedProbabilityChecks.add(entry);
|
failedProbabilityChecks.add(entry);
|
||||||
continue;
|
continue;
|
||||||
@ -2633,14 +2649,14 @@ function filterByInclusionGroups(newEntries, allActivatedEntries, buffer) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do weighted random using probability of entry as weight
|
// Do weighted random using entry's weight
|
||||||
const totalWeight = group.reduce((acc, item) => acc + item.probability, 0);
|
const totalWeight = group.reduce((acc, item) => acc + (item.groupWeight ?? DEFAULT_WEIGHT), 0);
|
||||||
const rollValue = Math.random() * totalWeight;
|
const rollValue = Math.random() * totalWeight;
|
||||||
let currentWeight = 0;
|
let currentWeight = 0;
|
||||||
let winner = null;
|
let winner = null;
|
||||||
|
|
||||||
for (const entry of group) {
|
for (const entry of group) {
|
||||||
currentWeight += entry.probability;
|
currentWeight += (entry.group_weight ?? DEFAULT_WEIGHT);
|
||||||
|
|
||||||
if (rollValue <= currentWeight) {
|
if (rollValue <= currentWeight) {
|
||||||
console.debug(`Activated inclusion group '${key}' with roll winner entry '${entry.uid}'`, entry);
|
console.debug(`Activated inclusion group '${key}' with roll winner entry '${entry.uid}'`, entry);
|
||||||
@ -2684,6 +2700,7 @@ function convertAgnaiMemoryBook(inputObj) {
|
|||||||
useProbability: false,
|
useProbability: false,
|
||||||
group: '',
|
group: '',
|
||||||
groupOverride: false,
|
groupOverride: false,
|
||||||
|
groupWeight: DEFAULT_WEIGHT,
|
||||||
scanDepth: null,
|
scanDepth: null,
|
||||||
caseSensitive: null,
|
caseSensitive: null,
|
||||||
matchWholeWords: null,
|
matchWholeWords: null,
|
||||||
@ -2721,6 +2738,7 @@ function convertRisuLorebook(inputObj) {
|
|||||||
useProbability: entry.activationPercent ?? false,
|
useProbability: entry.activationPercent ?? false,
|
||||||
group: '',
|
group: '',
|
||||||
groupOverride: false,
|
groupOverride: false,
|
||||||
|
groupWeight: DEFAULT_WEIGHT,
|
||||||
scanDepth: null,
|
scanDepth: null,
|
||||||
caseSensitive: null,
|
caseSensitive: null,
|
||||||
matchWholeWords: null,
|
matchWholeWords: null,
|
||||||
@ -2763,6 +2781,7 @@ function convertNovelLorebook(inputObj) {
|
|||||||
useProbability: false,
|
useProbability: false,
|
||||||
group: '',
|
group: '',
|
||||||
groupOverride: false,
|
groupOverride: false,
|
||||||
|
groupWeight: DEFAULT_WEIGHT,
|
||||||
scanDepth: null,
|
scanDepth: null,
|
||||||
caseSensitive: null,
|
caseSensitive: null,
|
||||||
matchWholeWords: null,
|
matchWholeWords: null,
|
||||||
@ -2806,6 +2825,7 @@ function convertCharacterBook(characterBook) {
|
|||||||
selectiveLogic: entry.extensions?.selectiveLogic ?? world_info_logic.AND_ANY,
|
selectiveLogic: entry.extensions?.selectiveLogic ?? world_info_logic.AND_ANY,
|
||||||
group: entry.extensions?.group ?? '',
|
group: entry.extensions?.group ?? '',
|
||||||
groupOverride: entry.extensions?.group_override ?? false,
|
groupOverride: entry.extensions?.group_override ?? false,
|
||||||
|
groupWeight: entry.extensions?.group_weight ?? DEFAULT_WEIGHT,
|
||||||
scanDepth: entry.extensions?.scan_depth ?? null,
|
scanDepth: entry.extensions?.scan_depth ?? null,
|
||||||
caseSensitive: entry.extensions?.case_sensitive ?? null,
|
caseSensitive: entry.extensions?.case_sensitive ?? null,
|
||||||
matchWholeWords: entry.extensions?.match_whole_words ?? null,
|
matchWholeWords: entry.extensions?.match_whole_words ?? null,
|
||||||
|
@ -434,6 +434,7 @@ function convertWorldInfoToCharacterBook(name, entries) {
|
|||||||
selectiveLogic: entry.selectiveLogic ?? 0,
|
selectiveLogic: entry.selectiveLogic ?? 0,
|
||||||
group: entry.group ?? '',
|
group: entry.group ?? '',
|
||||||
group_override: entry.groupOverride ?? false,
|
group_override: entry.groupOverride ?? false,
|
||||||
|
group_weight: entry.groupWeight ?? null,
|
||||||
prevent_recursion: entry.preventRecursion ?? false,
|
prevent_recursion: entry.preventRecursion ?? false,
|
||||||
scan_depth: entry.scanDepth ?? null,
|
scan_depth: entry.scanDepth ?? null,
|
||||||
match_whole_words: entry.matchWholeWords ?? null,
|
match_whole_words: entry.matchWholeWords ?? null,
|
||||||
|
Reference in New Issue
Block a user