mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Use proportional WI budget. Add None option for WI editor.
This commit is contained in:
@@ -1848,7 +1848,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="range-block-range">
|
<div class="range-block-range">
|
||||||
<select id="world_info" class="flexGrow margin0">
|
<select id="world_info" class="flexGrow margin0">
|
||||||
<option value="None">None</option>
|
<option value="">--- None ---</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1887,11 +1887,11 @@
|
|||||||
|
|
||||||
<div class="flex1 gap5px range-block">
|
<div class="flex1 gap5px range-block">
|
||||||
<div class="wide10pMinFit">
|
<div class="wide10pMinFit">
|
||||||
<small data-i18n="Token Budget">Max Tokens</small>
|
<small data-i18n="Token Budget">Context %</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="range-block-range-and-counter ">
|
<div class="range-block-range-and-counter ">
|
||||||
<div class="range-block-range paddingLeftRight5">
|
<div class="range-block-range paddingLeftRight5">
|
||||||
<input type="range" id="world_info_budget" name="volume" min="32" max="8192" step="1">
|
<input type="range" id="world_info_budget" name="volume" min="1" max="100" step="1">
|
||||||
</div>
|
</div>
|
||||||
<div class="range-block-counter margin0">
|
<div class="range-block-counter margin0">
|
||||||
<div contenteditable="true" data-for="world_info_budget" id="world_info_budget_counter">
|
<div contenteditable="true" data-for="world_info_budget" id="world_info_budget_counter">
|
||||||
@@ -1946,7 +1946,9 @@
|
|||||||
<div id="world_popup_export" class="menu_button fa-solid fa-file-export margin0 fa-fw" title="Export World Info"></div>
|
<div id="world_popup_export" class="menu_button fa-solid fa-file-export margin0 fa-fw" title="Export World Info"></div>
|
||||||
<div id="world_popup_delete" class="menu_button fa-solid fa-trash-can redWarningBG margin0 fa-fw" title="Delete World Info"></div>
|
<div id="world_popup_delete" class="menu_button fa-solid fa-trash-can redWarningBG margin0 fa-fw" title="Delete World Info"></div>
|
||||||
<span> Editing:</span>
|
<span> Editing:</span>
|
||||||
<select id="world_editor_select" class="margin0"></select>
|
<select id="world_editor_select" class="margin0">
|
||||||
|
<option value="">--- None ---</option>
|
||||||
|
</select>
|
||||||
<div id="world_popup_name_button" class="menu_button fa-solid fa-i-cursor fa-fw" title="Rename World Info"></div>
|
<div id="world_popup_name_button" class="menu_button fa-solid fa-i-cursor fa-fw" title="Rename World Info"></div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@@ -2026,7 +2026,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
// Set non-WI AN
|
// Set non-WI AN
|
||||||
setFloatingPrompt();
|
setFloatingPrompt();
|
||||||
// Add WI to prompt (and also inject WI to AN value via hijack)
|
// Add WI to prompt (and also inject WI to AN value via hijack)
|
||||||
let { worldInfoString, worldInfoBefore, worldInfoAfter } = await getWorldInfoPrompt(chat2);
|
let { worldInfoString, worldInfoBefore, worldInfoAfter } = await getWorldInfoPrompt(chat2, this_max_context);
|
||||||
// Call combined AN into Generate
|
// Call combined AN into Generate
|
||||||
let allAnchors = getAllExtensionPrompts();
|
let allAnchors = getAllExtensionPrompts();
|
||||||
const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.AFTER_SCENARIO);
|
const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.AFTER_SCENARIO);
|
||||||
|
@@ -27,7 +27,7 @@ const world_info_insertion_strategy = {
|
|||||||
let world_info = null;
|
let world_info = null;
|
||||||
let world_names;
|
let world_names;
|
||||||
let world_info_depth = 2;
|
let world_info_depth = 2;
|
||||||
let world_info_budget = 128;
|
let world_info_budget = 25;
|
||||||
let world_info_recursive = false;
|
let world_info_recursive = false;
|
||||||
let world_info_case_sensitive = false;
|
let world_info_case_sensitive = false;
|
||||||
let world_info_match_whole_words = false;
|
let world_info_match_whole_words = false;
|
||||||
@@ -43,10 +43,10 @@ const world_info_position = {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getWorldInfoPrompt(chat2) {
|
async function getWorldInfoPrompt(chat2, maxContext) {
|
||||||
let worldInfoString = "", worldInfoBefore = "", worldInfoAfter = "";
|
let worldInfoString = "", worldInfoBefore = "", worldInfoAfter = "";
|
||||||
|
|
||||||
const activatedWorldInfo = await checkWorldInfo(chat2);
|
const activatedWorldInfo = await checkWorldInfo(chat2, maxContext);
|
||||||
worldInfoBefore = activatedWorldInfo.worldInfoBefore;
|
worldInfoBefore = activatedWorldInfo.worldInfoBefore;
|
||||||
worldInfoAfter = activatedWorldInfo.worldInfoAfter;
|
worldInfoAfter = activatedWorldInfo.worldInfoAfter;
|
||||||
worldInfoString = worldInfoBefore + worldInfoAfter;
|
worldInfoString = worldInfoBefore + worldInfoAfter;
|
||||||
@@ -68,6 +68,11 @@ function setWorldInfoSettings(settings, data) {
|
|||||||
if (settings.world_info_character_strategy !== undefined)
|
if (settings.world_info_character_strategy !== undefined)
|
||||||
world_info_character_strategy = Number(settings.world_info_character_strategy);
|
world_info_character_strategy = Number(settings.world_info_character_strategy);
|
||||||
|
|
||||||
|
// Migrate old settings
|
||||||
|
if (world_info_budget > 100) {
|
||||||
|
world_info_budget = 25;
|
||||||
|
}
|
||||||
|
|
||||||
$("#world_info_depth_counter").text(world_info_depth);
|
$("#world_info_depth_counter").text(world_info_depth);
|
||||||
$("#world_info_depth").val(world_info_depth);
|
$("#world_info_depth").val(world_info_depth);
|
||||||
|
|
||||||
@@ -141,8 +146,8 @@ async function updateWorldInfoList(importedWorldName) {
|
|||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
var data = await result.json();
|
var data = await result.json();
|
||||||
world_names = data.world_names?.length ? data.world_names : [];
|
world_names = data.world_names?.length ? data.world_names : [];
|
||||||
$("#world_info").find('option[value!="None"]').remove();
|
$("#world_info").find('option[value!=""]').remove();
|
||||||
$("#world_editor_select").empty();
|
$("#world_editor_select").find('option[value!=""]').remove();
|
||||||
|
|
||||||
world_names.forEach((item, i) => {
|
world_names.forEach((item, i) => {
|
||||||
$("#world_info").append(`<option value='${i}'>${item}</option>`);
|
$("#world_info").append(`<option value='${i}'>${item}</option>`);
|
||||||
@@ -165,13 +170,14 @@ function nullWorldInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function displayWorldEntries(name, data) {
|
function displayWorldEntries(name, data) {
|
||||||
$("#world_popup_entries_list").empty();
|
$("#world_popup_entries_list").empty().show();
|
||||||
|
|
||||||
if (!data || !("entries" in data)) {
|
if (!data || !("entries" in data)) {
|
||||||
$("#world_popup_new").off('click').on('click', nullWorldInfo);
|
$("#world_popup_new").off('click').on('click', nullWorldInfo);
|
||||||
$("#world_popup_name_button").off('click').on('click', nullWorldInfo);
|
$("#world_popup_name_button").off('click').on('click', nullWorldInfo);
|
||||||
$("#world_popup_export").off('click').on('click', nullWorldInfo);
|
$("#world_popup_export").off('click').on('click', nullWorldInfo);
|
||||||
$("#world_popup_delete").off('click').on('click', nullWorldInfo);
|
$("#world_popup_delete").off('click').on('click', nullWorldInfo);
|
||||||
|
$("#world_popup_entries_list").hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -515,7 +521,7 @@ async function deleteWorldInfo(worldInfoName, selectWorldName) {
|
|||||||
if (selectedIndex !== -1) {
|
if (selectedIndex !== -1) {
|
||||||
$("#world_info").val(selectedIndex).trigger('change');
|
$("#world_info").val(selectedIndex).trigger('change');
|
||||||
} else {
|
} else {
|
||||||
$("#world_info").val("None").trigger('change');
|
$("#world_info").val("").trigger('change');
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#world_editor_select').trigger('change');
|
$('#world_editor_select').trigger('change');
|
||||||
@@ -567,7 +573,7 @@ async function createNewWorldInfo(worldInfoName) {
|
|||||||
$("#world_info").val(selectedIndex).trigger('change');
|
$("#world_info").val(selectedIndex).trigger('change');
|
||||||
$('#world_editor_select').val(selectedIndex).trigger('change');
|
$('#world_editor_select').val(selectedIndex).trigger('change');
|
||||||
} else {
|
} else {
|
||||||
$("#world_info").val("None").trigger('change');
|
$("#world_info").val("").trigger('change');
|
||||||
hideWorldEditor();
|
hideWorldEditor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -654,7 +660,7 @@ async function getSortedEntries() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkWorldInfo(chat) {
|
async function checkWorldInfo(chat, maxContext) {
|
||||||
const context = getContext();
|
const context = getContext();
|
||||||
const messagesToLookBack = world_info_depth * 2 || 1;
|
const messagesToLookBack = world_info_depth * 2 || 1;
|
||||||
let textToScan = transformString(chat.slice(0, messagesToLookBack).join(""));
|
let textToScan = transformString(chat.slice(0, messagesToLookBack).join(""));
|
||||||
@@ -664,6 +670,8 @@ async function checkWorldInfo(chat) {
|
|||||||
let count = 0;
|
let count = 0;
|
||||||
let allActivatedEntries = new Set();
|
let allActivatedEntries = new Set();
|
||||||
|
|
||||||
|
const budget = Math.round(world_info_budget * maxContext / 100) || 1;
|
||||||
|
console.debug(`Context size: ${maxContext}; WI budget: ${budget} (${world_info_budget}%)`);
|
||||||
const sortedEntries = await getSortedEntries();
|
const sortedEntries = await getSortedEntries();
|
||||||
|
|
||||||
if (sortedEntries.length === 0) {
|
if (sortedEntries.length === 0) {
|
||||||
@@ -737,8 +745,9 @@ async function checkWorldInfo(chat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(getTokenCount(worldInfoBefore + worldInfoAfter) + ANInjectionTokens) >= world_info_budget
|
(getTokenCount(worldInfoBefore + worldInfoAfter) + ANInjectionTokens) >= budget
|
||||||
) {
|
) {
|
||||||
|
console.debug(`WI budget reached, stopping`);
|
||||||
needsToScan = false;
|
needsToScan = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -785,7 +794,7 @@ jQuery(() => {
|
|||||||
const selectedWorld = $("#world_info").find(":selected").val();
|
const selectedWorld = $("#world_info").find(":selected").val();
|
||||||
world_info = null;
|
world_info = null;
|
||||||
|
|
||||||
if (selectedWorld !== "None") {
|
if (selectedWorld !== "") {
|
||||||
const worldIndex = Number(selectedWorld);
|
const worldIndex = Number(selectedWorld);
|
||||||
world_info = !isNaN(worldIndex) ? world_names[worldIndex] : null;
|
world_info = !isNaN(worldIndex) ? world_names[worldIndex] : null;
|
||||||
}
|
}
|
||||||
@@ -854,8 +863,13 @@ jQuery(() => {
|
|||||||
|
|
||||||
$("#world_editor_select").on('change', async () => {
|
$("#world_editor_select").on('change', async () => {
|
||||||
const selectedIndex = $("#world_editor_select").find(":selected").val();
|
const selectedIndex = $("#world_editor_select").find(":selected").val();
|
||||||
const worldName = world_names[selectedIndex];
|
|
||||||
showWorldEditor(worldName);
|
if (selectedIndex === "") {
|
||||||
|
hideWorldEditor();
|
||||||
|
} else {
|
||||||
|
const worldName = world_names[selectedIndex];
|
||||||
|
showWorldEditor(worldName);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on("input", "#world_info_depth", function () {
|
$(document).on("input", "#world_info_depth", function () {
|
||||||
|
@@ -2025,6 +2025,7 @@ grammarly-extension {
|
|||||||
height: auto;
|
height: auto;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
min-height: 32px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.delete_entry_button {
|
.delete_entry_button {
|
||||||
|
Reference in New Issue
Block a user