mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-26 17:07:46 +01:00
Replace magic numbers with named constants
This commit is contained in:
parent
2411006fdb
commit
1838ca1994
@ -2593,7 +2593,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
|
|||||||
// Add all depth WI entries to prompt
|
// Add all depth WI entries to prompt
|
||||||
worldInfoDepth.forEach((e) => {
|
worldInfoDepth.forEach((e) => {
|
||||||
const joinedEntries = e.entries.join("\n");
|
const joinedEntries = e.entries.join("\n");
|
||||||
setExtensionPrompt(`customDepthWI-${e.depth}`, joinedEntries, 1, e.depth)
|
setExtensionPrompt(`customDepthWI-${e.depth}`, joinedEntries, extension_prompt_types.IN_CHAT, e.depth)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (main_api === 'openai') {
|
if (main_api === 'openai') {
|
||||||
|
@ -52,6 +52,8 @@ let updateEditor = (navigation) => { navigation; };
|
|||||||
// Do not optimize. updateEditor is a function that is updated by the displayWorldEntries with new data.
|
// Do not optimize. updateEditor is a function that is updated by the displayWorldEntries with new data.
|
||||||
const worldInfoFilter = new FilterHelper(() => updateEditor());
|
const worldInfoFilter = new FilterHelper(() => updateEditor());
|
||||||
|
|
||||||
|
const DEFAULT_DEPTH = 4;
|
||||||
|
|
||||||
export function getWorldInfoSettings() {
|
export function getWorldInfoSettings() {
|
||||||
return {
|
return {
|
||||||
world_info,
|
world_info,
|
||||||
@ -72,7 +74,6 @@ const world_info_position = {
|
|||||||
ANTop: 2,
|
ANTop: 2,
|
||||||
ANBottom: 3,
|
ANBottom: 3,
|
||||||
atDepth: 4,
|
atDepth: 4,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const worldInfoCache = {};
|
const worldInfoCache = {};
|
||||||
@ -683,7 +684,7 @@ function getWorldEntry(name, data, entry) {
|
|||||||
// depth
|
// depth
|
||||||
const depthInput = template.find('input[name="depth"]');
|
const depthInput = template.find('input[name="depth"]');
|
||||||
depthInput.data("uid", entry.uid);
|
depthInput.data("uid", entry.uid);
|
||||||
depthInput.on("input", function() {
|
depthInput.on("input", function () {
|
||||||
const uid = $(this).data("uid");
|
const uid = $(this).data("uid");
|
||||||
const value = Number($(this).val());
|
const value = Number($(this).val());
|
||||||
|
|
||||||
@ -691,10 +692,10 @@ function getWorldEntry(name, data, entry) {
|
|||||||
setOriginalDataValue(data, uid, "depth", data.entries[uid].depth);
|
setOriginalDataValue(data, uid, "depth", data.entries[uid].depth);
|
||||||
saveWorldInfo(name, data);
|
saveWorldInfo(name, data);
|
||||||
});
|
});
|
||||||
depthInput.val(entry.depth ?? 4).trigger("input");
|
depthInput.val(entry.depth ?? DEFAULT_DEPTH).trigger("input");
|
||||||
|
|
||||||
// Hide by default unless depth is specified
|
// Hide by default unless depth is specified
|
||||||
if (entry.position === 4) {
|
if (entry.position === world_info_position.atDepth) {
|
||||||
depthInput.parent().hide();
|
depthInput.parent().hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -762,7 +763,7 @@ function getWorldEntry(name, data, entry) {
|
|||||||
const uid = $(this).data("uid");
|
const uid = $(this).data("uid");
|
||||||
const value = Number($(this).val());
|
const value = Number($(this).val());
|
||||||
data.entries[uid].position = !isNaN(value) ? value : 0;
|
data.entries[uid].position = !isNaN(value) ? value : 0;
|
||||||
if (value === 4) {
|
if (value === world_info_position.atDepth) {
|
||||||
depthInput.parent().show();
|
depthInput.parent().show();
|
||||||
} else {
|
} else {
|
||||||
depthInput.parent().hide();
|
depthInput.parent().hide();
|
||||||
@ -1276,7 +1277,7 @@ async function checkWorldInfo(chat, maxContext) {
|
|||||||
ANBottomEntries.unshift(entry.content);
|
ANBottomEntries.unshift(entry.content);
|
||||||
break;
|
break;
|
||||||
case world_info_position.atDepth:
|
case world_info_position.atDepth:
|
||||||
const existingDepthIndex = WIDepthEntries.findIndex((e) => e.depth === entry.depth ?? 4);
|
const existingDepthIndex = WIDepthEntries.findIndex((e) => e.depth === entry.depth ?? DEFAULT_DEPTH);
|
||||||
if (existingDepthIndex !== -1) {
|
if (existingDepthIndex !== -1) {
|
||||||
WIDepthEntries[existingDepthIndex].entries.unshift(entry.content);
|
WIDepthEntries[existingDepthIndex].entries.unshift(entry.content);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user