mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-05 13:36:47 +01:00
Split group weight and trigger%
This commit is contained in:
parent
d54ccece5c
commit
83c77c1f18
@ -360,6 +360,14 @@
|
||||
flex: 2 !important;
|
||||
}
|
||||
|
||||
.flex3 {
|
||||
flex: 3;
|
||||
}
|
||||
|
||||
.flex4 {
|
||||
flex: 4;
|
||||
}
|
||||
|
||||
.flexFlowColumn {
|
||||
flex-flow: column;
|
||||
}
|
||||
@ -563,4 +571,4 @@ textarea:disabled {
|
||||
height: 30px;
|
||||
text-align: center;
|
||||
padding: 5px;
|
||||
}
|
||||
}
|
||||
|
@ -5197,7 +5197,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<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">
|
||||
<small for="characterFilter" data-i18n="Filter to Character(s)">
|
||||
Filter to Character(s)
|
||||
@ -5217,7 +5217,7 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex1 flex-container flexFlowColumn flexNoGap">
|
||||
<div class="flex3 flex-container flexFlowColumn flexNoGap">
|
||||
<div class="flex-container justifySpaceBetween">
|
||||
<small for="group" data-i18n="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">
|
||||
</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 name="WIEntryBottomControls" class="flex-container flex1 justifySpaceBetween world_entry_form_horizontal">
|
||||
<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 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,
|
||||
|
@ -434,6 +434,7 @@ function convertWorldInfoToCharacterBook(name, entries) {
|
||||
selectiveLogic: entry.selectiveLogic ?? 0,
|
||||
group: entry.group ?? '',
|
||||
group_override: entry.groupOverride ?? false,
|
||||
group_weight: entry.groupWeight ?? null,
|
||||
prevent_recursion: entry.preventRecursion ?? false,
|
||||
scan_depth: entry.scanDepth ?? null,
|
||||
match_whole_words: entry.matchWholeWords ?? null,
|
||||
|
Loading…
Reference in New Issue
Block a user