mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-09 08:38:53 +01:00
Add flat budget cap for hybrid WI budgeting
This commit is contained in:
parent
b75997cebd
commit
9e43f5f8b7
@ -2141,7 +2141,7 @@
|
||||
<div class="justifyContentSpaceAround wi-settings flex-container gap10px alignitemscenter">
|
||||
<div id="WIMultiSelector" class="flex2 flex alignSelfStart range-block">
|
||||
<div class="range-block-title justifyLeft">
|
||||
<span data-i18n="Active World(s)"><small>Active World(s)</small></span>
|
||||
<span data-i18n="Active World(s) for all chats"><small>Active World(s) for all chats</small></span>
|
||||
</div>
|
||||
<div class="range-block-range">
|
||||
<select id="world_info" multiple>
|
||||
@ -2186,7 +2186,7 @@
|
||||
|
||||
<div class="flex1 gap5px range-block">
|
||||
<div class="wide10pMinFit">
|
||||
<small data-i18n="Token Budget">Context %</small>
|
||||
<small data-i18n="Context %">Context %</small>
|
||||
</div>
|
||||
<div class="range-block-range-and-counter ">
|
||||
<div class="range-block-range paddingLeftRight5">
|
||||
@ -2199,6 +2199,25 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex1 gap5px range-block">
|
||||
<div class="wide10pMinFit">
|
||||
<small data-i18n="Budget Cap">Budget Cap</small>
|
||||
</div>
|
||||
<div class="range-block-range-and-counter ">
|
||||
<div class="range-block-range paddingLeftRight5">
|
||||
<input type="range" id="world_info_budget_cap" name="volume" min="0" max="8192" step="256">
|
||||
</div>
|
||||
<div class="range-block-counter margin0">
|
||||
<div contenteditable="true" data-for="world_info_budget_cap" id="world_info_budget_cap_counter">
|
||||
0
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="budget_cap_note">
|
||||
<small data-i18n="(0 = disabled)">(0 = disabled)</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -21,17 +21,11 @@ import {
|
||||
} from "./scripts/textgen-settings.js";
|
||||
|
||||
import {
|
||||
world_info_budget,
|
||||
world_info_depth,
|
||||
world_info,
|
||||
getWorldInfoPrompt,
|
||||
getWorldInfoSettings,
|
||||
setWorldInfoSettings,
|
||||
world_info_recursive,
|
||||
world_info_overflow_alert,
|
||||
world_info_case_sensitive,
|
||||
world_info_match_whole_words,
|
||||
world_names,
|
||||
world_info_character_strategy,
|
||||
importEmbeddedWorldInfo,
|
||||
checkEmbeddedWorld,
|
||||
setWorldInfoButtonClass,
|
||||
@ -5163,7 +5157,7 @@ async function getSettings(type) {
|
||||
api_server = settings.api_server;
|
||||
$("#api_url_text").val(api_server);
|
||||
|
||||
setWorldInfoSettings(settings, data);
|
||||
setWorldInfoSettings(settings.world_info_settings ?? settings, data);
|
||||
|
||||
api_server_textgenerationwebui = settings.api_server_textgenerationwebui;
|
||||
$("#textgenerationwebui_api_url_text").val(
|
||||
@ -5211,14 +5205,7 @@ async function saveSettings(type) {
|
||||
amount_gen: amount_gen,
|
||||
max_context: max_context,
|
||||
main_api: main_api,
|
||||
world_info: world_info,
|
||||
world_info_depth: world_info_depth,
|
||||
world_info_budget: world_info_budget,
|
||||
world_info_recursive: world_info_recursive,
|
||||
world_info_overflow_alert: world_info_overflow_alert,
|
||||
world_info_case_sensitive: world_info_case_sensitive,
|
||||
world_info_match_whole_words: world_info_match_whole_words,
|
||||
world_info_character_strategy: world_info_character_strategy,
|
||||
world_info_settings: getWorldInfoSettings(),
|
||||
textgenerationwebui_settings: textgenerationwebui_settings,
|
||||
swipes: swipes,
|
||||
horde_settings: horde_settings,
|
||||
|
@ -14,6 +14,7 @@ export {
|
||||
world_info_case_sensitive,
|
||||
world_info_match_whole_words,
|
||||
world_info_character_strategy,
|
||||
world_info_budget_cap,
|
||||
world_names,
|
||||
checkWorldInfo,
|
||||
deleteWorldInfo,
|
||||
@ -37,6 +38,7 @@ let world_info_overflow_alert = false;
|
||||
let world_info_case_sensitive = false;
|
||||
let world_info_match_whole_words = false;
|
||||
let world_info_character_strategy = world_info_insertion_strategy.character_first;
|
||||
let world_info_budget_cap = 0;
|
||||
const saveWorldDebounced = debounce(async (name, data) => await _save(name, data), 1000);
|
||||
const saveSettingsDebounced = debounce(() => {
|
||||
Object.assign(world_info, { globalSelect: selected_world_info })
|
||||
@ -44,6 +46,20 @@ const saveSettingsDebounced = debounce(() => {
|
||||
}, 1000);
|
||||
const sortFn = (a, b) => b.order - a.order;
|
||||
|
||||
export function getWorldInfoSettings() {
|
||||
return {
|
||||
world_info,
|
||||
world_info_depth,
|
||||
world_info_budget,
|
||||
world_info_recursive,
|
||||
world_info_overflow_alert,
|
||||
world_info_case_sensitive,
|
||||
world_info_match_whole_words,
|
||||
world_info_character_strategy,
|
||||
world_info_budget_cap,
|
||||
}
|
||||
}
|
||||
|
||||
const world_info_position = {
|
||||
before: 0,
|
||||
after: 1,
|
||||
@ -80,6 +96,8 @@ function setWorldInfoSettings(settings, data) {
|
||||
world_info_match_whole_words = Boolean(settings.world_info_match_whole_words);
|
||||
if (settings.world_info_character_strategy !== undefined)
|
||||
world_info_character_strategy = Number(settings.world_info_character_strategy);
|
||||
if (settings.world_info_budget_cap !== undefined)
|
||||
world_info_budget_cap = Number(settings.world_info_budget_cap);
|
||||
|
||||
// Migrate old settings
|
||||
if (world_info_budget > 100) {
|
||||
@ -113,6 +131,9 @@ function setWorldInfoSettings(settings, data) {
|
||||
$(`#world_info_character_strategy option[value='${world_info_character_strategy}']`).prop('selected', true);
|
||||
$("#world_info_character_strategy").val(world_info_character_strategy);
|
||||
|
||||
$("#world_info_budget_cap").val(world_info_budget_cap);
|
||||
$("#world_info_budget_cap_counter").text(world_info_budget_cap);
|
||||
|
||||
world_names = data.world_names?.length ? data.world_names : [];
|
||||
|
||||
// Add to existing selected WI if it exists
|
||||
@ -922,8 +943,14 @@ async function checkWorldInfo(chat, maxContext) {
|
||||
let failedProbabilityChecks = new Set();
|
||||
let allActivatedText = '';
|
||||
|
||||
const budget = Math.round(world_info_budget * maxContext / 100) || 1;
|
||||
console.debug(`Context size: ${maxContext}; WI budget: ${budget} (${world_info_budget}%)`);
|
||||
let budget = Math.round(world_info_budget * maxContext / 100) || 1;
|
||||
|
||||
if (world_info_budget_cap > 0 && budget > world_info_budget_cap) {
|
||||
console.debug(`Budget ${budget} exceeds cap ${world_info_budget_cap}, using cap`);
|
||||
budget = world_info_budget_cap;
|
||||
}
|
||||
|
||||
console.debug(`Context size: ${maxContext}; WI budget: ${budget} (max% = ${world_info_budget}%, cap = ${world_info_budget_cap})`);
|
||||
const sortedEntries = await getSortedEntries();
|
||||
|
||||
if (sortedEntries.length === 0) {
|
||||
@ -1515,6 +1542,12 @@ jQuery(() => {
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#world_info_budget_cap').on('input', function () {
|
||||
world_info_budget_cap = Number($(this).val());
|
||||
$("#world_info_budget_cap_counter").text(world_info_budget_cap);
|
||||
saveSettingsDebounced();
|
||||
});
|
||||
|
||||
$('#world_button').on('click', async function () {
|
||||
const chid = $('#set_character_world').data('chid');
|
||||
|
||||
|
@ -2259,6 +2259,11 @@ grammarly-extension {
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.budget_cap_note {
|
||||
flex-basis: 100%;
|
||||
line-height: 0.1;
|
||||
}
|
||||
|
||||
#world_popup {
|
||||
min-height: 100px;
|
||||
min-width: 100px;
|
||||
|
Loading…
x
Reference in New Issue
Block a user