World Info: Add example messages insertion point

Allow insertion above and below mesExamples (also known as the
"examples of dialogue") box.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2024-05-07 21:55:26 -04:00
parent 4a70e68c22
commit 01aacb9280
3 changed files with 81 additions and 30 deletions

View File

@@ -333,8 +333,15 @@ const world_info_position = {
ANTop: 2,
ANBottom: 3,
atDepth: 4,
EMTop: 5,
EMBottom: 6,
};
export const wi_anchor_position = {
before: 0,
after: 1,
}
const worldInfoCache = {};
/**
@@ -342,7 +349,7 @@ const worldInfoCache = {};
* @param {string[]} chat The chat messages to scan.
* @param {number} maxContext The maximum context size of the generation.
* @param {boolean} isDryRun If true, the function will not emit any events.
* @typedef {{worldInfoString: string, worldInfoBefore: string, worldInfoAfter: string, worldInfoDepth: any[]}} WIPromptResult
* @typedef {{worldInfoString: string, worldInfoBefore: string, worldInfoAfter: string, worldInfoExamples: any[], worldInfoDepth: any[]}} WIPromptResult
* @returns {Promise<WIPromptResult>} The world info string and depth.
*/
async function getWorldInfoPrompt(chat, maxContext, isDryRun) {
@@ -362,6 +369,7 @@ async function getWorldInfoPrompt(chat, maxContext, isDryRun) {
worldInfoString,
worldInfoBefore,
worldInfoAfter,
worldInfoExamples: activatedWorldInfo.EMEntries,
worldInfoDepth: activatedWorldInfo.WIDepthEntries,
};
}
@@ -2277,7 +2285,7 @@ export async function getSortedEntries() {
* Performs a scan on the chat and returns the world info activated.
* @param {string[]} chat The chat messages to scan.
* @param {number} maxContext The maximum context size of the generation.
* @typedef {{ worldInfoBefore: string, worldInfoAfter: string, WIDepthEntries: any[], allActivatedEntries: Set<any> }} WIActivated
* @typedef {{ worldInfoBefore: string, worldInfoAfter: string, EMEntries: any[], WIDepthEntries: any[], allActivatedEntries: Set<any> }} WIActivated
* @returns {Promise<WIActivated>} The world info activated.
*/
async function checkWorldInfo(chat, maxContext) {
@@ -2514,11 +2522,13 @@ async function checkWorldInfo(chat, maxContext) {
// Forward-sorted list of entries for joining
const WIBeforeEntries = [];
const WIAfterEntries = [];
const EMEntries = [];
const ANTopEntries = [];
const ANBottomEntries = [];
const WIDepthEntries = [];
// Appends from insertion order 999 to 1. Use unshift for this purpose
// TODO (kingbri): Change to use WI Anchor positioning instead of separate top/bottom arrays
[...allActivatedEntries].sort(sortFn).forEach((entry) => {
switch (entry.position) {
case world_info_position.before:
@@ -2527,6 +2537,16 @@ async function checkWorldInfo(chat, maxContext) {
case world_info_position.after:
WIAfterEntries.unshift(substituteParams(entry.content));
break;
case world_info_position.EMTop:
EMEntries.unshift(
{position: wi_anchor_position.before, content: entry.content}
);
break;
case world_info_position.EMBottom:
EMEntries.unshift(
{position: wi_anchor_position.after, content: entry.content}
);
break;
case world_info_position.ANTop:
ANTopEntries.unshift(entry.content);
break;
@@ -2562,7 +2582,7 @@ async function checkWorldInfo(chat, maxContext) {
buffer.cleanExternalActivations();
return { worldInfoBefore, worldInfoAfter, WIDepthEntries, allActivatedEntries };
return { worldInfoBefore, worldInfoAfter, EMEntries, WIDepthEntries, allActivatedEntries };
}
/**