diff --git a/public/index.html b/public/index.html index 555fcc24a..060673853 100644 --- a/public/index.html +++ b/public/index.html @@ -2915,7 +2915,12 @@
+
+
+
diff --git a/public/script.js b/public/script.js index 96fc3b237..f0a34925f 100644 --- a/public/script.js +++ b/public/script.js @@ -2012,10 +2012,11 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, } // Extension added strings + //WI moved to top in order to allow it to hijack AN if necessary + let { worldInfoString, worldInfoBefore, worldInfoAfter } = getWorldInfoPrompt(chat2); let allAnchors = getAllExtensionPrompts(); const afterScenarioAnchor = getExtensionPrompt(extension_prompt_types.AFTER_SCENARIO); let zeroDepthAnchor = getExtensionPrompt(extension_prompt_types.IN_CHAT, 0, ' '); - let { worldInfoString, worldInfoBefore, worldInfoAfter } = getWorldInfoPrompt(chat2); // Moved here to not overflow the Poe context with added prompt bits if (main_api == 'poe') { diff --git a/public/scripts/extensions.js b/public/scripts/extensions.js index bf8be73a6..48b3be928 100644 --- a/public/scripts/extensions.js +++ b/public/scripts/extensions.js @@ -51,6 +51,7 @@ const extension_settings = { note: { default: '', chara: [], + wiAddition: [], }, caption: {}, expressions: {}, diff --git a/public/scripts/extensions/floating-prompt/index.js b/public/scripts/extensions/floating-prompt/index.js index b47004d0e..f24a34909 100644 --- a/public/scripts/extensions/floating-prompt/index.js +++ b/public/scripts/extensions/floating-prompt/index.js @@ -19,7 +19,7 @@ const DEFAULT_DEPTH = 4; const DEFAULT_POSITION = 1; const DEFAULT_INTERVAL = 1; -const metadata_keys = { +export const metadata_keys = { prompt: 'note_prompt', interval: 'note_interval', depth: 'note_depth', @@ -283,7 +283,10 @@ function onChatChanged() { $('#extension_floating_default_token_counter').text(tokenCounter3); } -(function () { +//for some reason exporting metadata_keys for WI usage caused this to throw errors +//"accessing eventSource before initialization" +//putting it on a 1ms Timeout solved this. +setTimeout(function () { function addExtensionsSettings() { const settingsHtml = `
@@ -399,4 +402,4 @@ function onChatChanged() { registerSlashCommand('freq', setNoteIntervalCommand, ['interval'], "(number) – sets an author's note insertion frequency", true, true); registerSlashCommand('pos', setNotePositionCommand, ['position'], "(chat or scenario) – sets an author's note position", true, true); eventSource.on(event_types.CHAT_CHANGED, onChatChanged); -})(); +}, 1); diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 22ecb8311..5738d5ec3 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1,6 +1,7 @@ -import { saveSettings, callPopup, substituteParams, getTokenCount, getRequestHeaders } from "../script.js"; +import { saveSettings, callPopup, substituteParams, getTokenCount, getRequestHeaders, chat_metadata } from "../script.js"; import { download, debounce, delay, initScrollHeight, resetScrollHeight } from "./utils.js"; import { getContext } from "./extensions.js"; +import { metadata_keys } from "./extensions/floating-prompt/index.js"; export { world_info, @@ -35,7 +36,9 @@ const saveSettingsDebounced = debounce(() => saveSettings(), 1000); const world_info_position = { before: 0, after: 1, - authorsnote: 2, + ANTop: 2, + ANBottom: 3, + }; function getWorldInfoPrompt(chat2) { @@ -592,8 +595,11 @@ function checkWorldInfo(chat) { const newEntries = [...activatedNow] .map((x) => world_info_data.entries[x]) .sort((a, b) => sortedEntries.indexOf(a) - sortedEntries.indexOf(b)); - + let ANInjectionTokens = 0; for (const entry of newEntries) { + let ANWithWI; + + let originalAN = context.extensionPrompts['2_floating_prompt'].value; if (entry.position === world_info_position.after) { worldInfoAfter = `${substituteParams( entry.content @@ -602,14 +608,20 @@ function checkWorldInfo(chat) { worldInfoBefore = `${substituteParams( entry.content )}\n${worldInfoBefore}`; - } else { - let originalAN = context.extensionPrompts['2_floating_prompt'].value; - let ANWithWI = originalAN + "\n" + entry.content; - context.extensionPrompts['2_floating_prompt'].value = ANWithWI; + + //WI must hijack AN to inject before the prompt is set. + } else if (entry.position === world_info_position.ANBottom) { + ANWithWI = originalAN + "\n" + entry.content; + ANInjectionTokens = ANInjectionTokens + getTokenCount(ANWithWI) - getTokenCount(originalAN); + context.setExtensionPrompt('2_floating_prompt', ANWithWI, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth]); + } else if (entry.position === world_info_position.ANTop) { + ANWithWI = entry.content + "\n" + originalAN; + ANInjectionTokens = ANInjectionTokens + getTokenCount(ANWithWI) - getTokenCount(originalAN); + context.setExtensionPrompt('2_floating_prompt', ANWithWI, chat_metadata[metadata_keys.position], chat_metadata[metadata_keys.depth]); } if ( - getTokenCount(worldInfoBefore + worldInfoAfter) >= world_info_budget + (getTokenCount(worldInfoBefore + worldInfoAfter) + ANInjectionTokens) >= world_info_budget ) { needsToScan = false; break;