diff --git a/public/script.js b/public/script.js index a69307590..f2d13c81b 100644 --- a/public/script.js +++ b/public/script.js @@ -16,7 +16,7 @@ import { world_info_data, world_info_depth, world_info, - checkWorldInfo, + getWorldInfoPrompt, selectImportedWorldInfo, setWorldInfoSettings, deleteWorldInfo, @@ -55,7 +55,8 @@ import { setOpenAIOnlineStatus, generateOpenAIPromptCache, oai_settings, - is_get_status_openai + is_get_status_openai, + openai_msgs, } from "./scripts/openai.js"; import { @@ -900,18 +901,6 @@ function getExtensionPrompt() { return extension_prompt; } -function getWorldInfoPrompt(chat2) { - let worldInfoString = "", worldInfoBefore = "", worldInfoAfter = ""; - - if (world_info && world_info_data) { - const activatedWorldInfo = checkWorldInfo(chat2); - worldInfoBefore = activatedWorldInfo.worldInfoBefore; - worldInfoAfter = activatedWorldInfo.worldInfoAfter; - worldInfoString = worldInfoBefore + worldInfoAfter; - } - return { worldInfoString, worldInfoBefore, worldInfoAfter }; -} - function baseChatReplace(value, name1, name2) { if (value !== undefined && value.length > 0) { if (is_pygmalion) { @@ -1461,7 +1450,7 @@ async function Generate(type, automatic_trigger, force_name2) {//encode("dsfs"). if (main_api == 'openai') { - let prompt = prepareOpenAIMessages(name2, storyString); + let prompt = prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldInfoAfter, extension_prompt); sendOpenAIRequest(prompt).then(onSuccess).catch(onError); } else { diff --git a/public/scripts/openai.js b/public/scripts/openai.js index 9bb90de03..743140f34 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -163,7 +163,16 @@ function parseExampleIntoIndividual(messageExampleString) { return result; } -function prepareOpenAIMessages(name2, storyString) { +function formatWorldInfo(value) { + if (!value) { + return ''; + } + + // placeholder if we would want to apply some formatting + return `[Details of the fictional world the RP set in:\n${value}\n]`; +} + +function prepareOpenAIMessages(name2, storyString, worldInfoBefore, worldInfoAfter, extensionPrompt) { let this_max_context = oai_settings.openai_max_context; let nsfw_toggle_prompt = ""; let enhance_definitions_prompt = ""; @@ -181,10 +190,10 @@ function prepareOpenAIMessages(name2, storyString) { let whole_prompt = []; // If it's toggled, NSFW prompt goes first. if (oai_settings.nsfw_first) { - whole_prompt = [nsfw_toggle_prompt, oai_settings.main_prompt, enhance_definitions_prompt, "\n\n", storyString] + whole_prompt = [nsfw_toggle_prompt, oai_settings.main_prompt, enhance_definitions_prompt, "\n\n", formatWorldInfo(worldInfoBefore), storyString, formatWorldInfo(worldInfoAfter), extensionPrompt] } else { - whole_prompt = [oai_settings.main_prompt, nsfw_toggle_prompt, enhance_definitions_prompt, "\n\n", storyString] + whole_prompt = [oai_settings.main_prompt, nsfw_toggle_prompt, enhance_definitions_prompt, "\n\n", formatWorldInfo(worldInfoBefore), storyString, formatWorldInfo(worldInfoAfter), extensionPrompt] } // Join by a space and replace placeholders with real user/char names diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index bafddbfb5..02dcb37ba 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -13,6 +13,7 @@ export { deleteWorldInfo, selectImportedWorldInfo, setWorldInfoSettings, + getWorldInfoPrompt, } let world_info = null; @@ -30,6 +31,18 @@ const world_info_position = { after: 1, }; +function getWorldInfoPrompt(chat2) { + let worldInfoString = "", worldInfoBefore = "", worldInfoAfter = ""; + + if (world_info && world_info_data) { + const activatedWorldInfo = checkWorldInfo(chat2); + worldInfoBefore = activatedWorldInfo.worldInfoBefore; + worldInfoAfter = activatedWorldInfo.worldInfoAfter; + worldInfoString = worldInfoBefore + worldInfoAfter; + } + return { worldInfoString, worldInfoBefore, worldInfoAfter }; +} + function setWorldInfoSettings(settings, data) { if (settings.world_info_depth !== undefined) world_info_depth = Number(settings.world_info_depth);