New exports

0e41db615e54c2f0dd87e3366b44850a5071d184

bmen25124 <bmen25124@gmail.com>

5 files changed, +36 -20Showing whitespace changes
public/scripts/instruct-mode.js+9 -6
@@ -398,23 +398,26 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
398398/**
399399 * Formats instruct mode system prompt.
400400 * @param {string} systemPrompt System prompt string.
401+ * @param {InstructSettings} customInstruct Custom instruct mode settings.
401402 * @returns {string} Formatted instruct mode system prompt.
402403 */
403404export function formatInstructModeSystemPrompt(systemPrompt, customInstruct = null) {
404405 if (!systemPrompt) {
405406 return '';
406407 }
407408
408- const separator = power_user.instruct.wrap ? '\n' : '';
409+ const instruct = customInstruct ?? power_user.instruct;
410+
411+ const separator = instruct.wrap ? '\n' : '';
409412
410413 if (power_user.instruct.system_sequence_prefix) {
411414 // TODO: Replace with a proper 'System' prompt entity name input
412415 const prefix = power_user.instruct.system_sequence_prefix.replace(/{{name}}/gi, 'System');
413416 systemPrompt = prefix + separator + systemPrompt;
414417 }
415418
416419 if (power_user.instruct.system_sequence_suffix) {
417420 systemPrompt = systemPrompt + separator + power_user.instruct.system_sequence_suffix;
418421 }
419422
420423 return systemPrompt;
public/scripts/openai.js+7 -5
@@ -705,16 +705,18 @@ export function parseExampleIntoIndividual(messageExampleString, appendNamesForG
705705 return result;
706706}
707707
708-function formatWorldInfo(value) {
708+export function formatWorldInfo(value, { wiFormat = null } = {}) {
709709 if (!value) {
710710 return '';
711711 }
712712
713- if (!oai_settings.wi_format.trim()) {
713+ const format = wiFormat || oai_settings.wi_format;
714+
715+ if (!format.trim()) {
714716 return value;
715717 }
716718
717719 return stringFormat(oai_settings.wi_formatformat, value);
718720}
719721
720722/**
@@ -952,7 +954,7 @@ async function populateDialogueExamples(prompts, chatCompletion, messageExamples
952954 * @param {number} position - Prompt position in the extensions object.
953955 * @returns {string|false} - The prompt position for prompt collection.
954956 */
955957export function getPromptPosition(position) {
956958 if (position == extension_prompt_types.BEFORE_PROMPT) {
957959 return 'start';
958960 }
@@ -969,7 +971,7 @@ function getPromptPosition(position) {
969971 * @param {number} role Role of the prompt.
970972 * @returns {string} Mapped role.
971973 */
972974export function getPromptRole(role) {
973975 switch (role) {
974976 case extension_prompt_roles.SYSTEM:
975977 return 'system';
public/scripts/power-user.js+10 -4
@@ -1985,15 +1985,21 @@ export function fuzzySearchGroups(searchValue, fuzzySearchCaches = null) {
19851985/**
19861986 * Renders a story string template with the given parameters.
19871987 * @param {object} params Template parameters.
1988+ * @param {object} [options] Additional options.
1989+ * @param {string} [options.customStoryString] Custom story string template.
1990+ * @param {InstructSettings} [options.customInstructSettings] Custom instruct settings.
19881991 * @returns {string} The rendered story string.
19891992 */
1990-export function renderStoryString(params) {
1993+export function renderStoryString(params, { customStoryString = null, customInstructSettings = null } = {}) {
19911994 try {
1995+ const storyString = customStoryString ?? power_user.context.story_string;
1996+ const instructSettings = customInstructSettings ?? power_user.instruct;
1997+
19921998 // Validate and log possible warnings/errors
19931999 validateStoryString(power_user.context.story_stringstoryString, params);
19942000
19952001 // compile the story string template into a function, with no HTML escaping
19962002 const compiledTemplate = Handlebars.compile(power_user.context.story_stringstoryString, { noEscape: true });
19972003
19982004 // render the story string template with the given params
19992005 let output = compiledTemplate(params);
@@ -2006,7 +2012,7 @@ export function renderStoryString(params) {
20062012
20072013 // add a newline to the end of the story string if it doesn't have one
20082014 if (output.length > 0 && !output.endsWith('\n')) {
20092015 if (!power_user.instructinstructSettings.enabled || power_user.instructinstructSettings.wrap) {
20102016 output += '\n';
20112017 }
20122018 }
public/scripts/st-context.js+4 -1
@@ -49,6 +49,7 @@ import {
4949 clearChat,
5050 unshallowCharacter,
5151 deleteLastMessage,
52+ getCharacterCardFields,
5253} from '../script.js';
5354import {
5455 extension_settings,
@@ -78,7 +79,7 @@ import { ToolManager } from './tool-calling.js';
7879import { accountStorage } from './util/AccountStorage.js';
7980import { timestampToMoment, uuidv4 } from './utils.js';
8081import { getGlobalVariable, getLocalVariable, setGlobalVariable, setLocalVariable } from './variables.js';
8182import { convertCharacterBook, getWorldInfoPrompt, loadWorldInfo, saveWorldInfo, updateWorldInfoList } from './world-info.js';
8283import { ChatCompletionService, TextCompletionService } from './custom-request.js';
8384import { ConnectionManagerRequestService } from './extensions/shared.js';
8485import { updateReasoningUI, parseReasoningFromString } from './reasoning.js';
@@ -189,6 +190,7 @@ export function getContext() {
189190 textCompletionSettings: textgenerationwebui_settings,
190191 powerUserSettings: power_user,
191192 getCharacters,
193+ getCharacterCardFields,
192194 uuidv4,
193195 humanizedDateTime,
194196 updateMessageBlock,
@@ -207,6 +209,7 @@ export function getContext() {
207209 saveWorldInfo,
208210 updateWorldInfoList,
209211 convertCharacterBook,
212+ getWorldInfoPrompt,
210213 CONNECT_API_MAP,
211214 getTextGenServer,
212215 extractMessageFromData,
public/scripts/world-info.js+6 -4
@@ -756,7 +756,7 @@ export const worldInfoCache = new StructuredCloneMap({ cloneOnGet: true, cloneOn
756756 * @param {string[]} chat The chat messages to scan, in reverse order.
757757 * @param {number} maxContext The maximum context size of the generation.
758758 * @param {boolean} isDryRun If true, the function will not emit any events.
759759 * @typedef {{worldInfoString: string, worldInfoBefore: string, worldInfoAfter: string, worldInfoExamples: any[], worldInfoDepth: any[], anBefore: any[], anAfter: any[]}} WIPromptResult
760760 * @returns {Promise<WIPromptResult>} The world info string and depth.
761761 */
762762export async function getWorldInfoPrompt(chat, maxContext, isDryRun) {
@@ -778,6 +778,8 @@ export async function getWorldInfoPrompt(chat, maxContext, isDryRun) {
778778 worldInfoAfter,
779779 worldInfoExamples: activatedWorldInfo.EMEntries ?? [],
780780 worldInfoDepth: activatedWorldInfo.WIDepthEntries ?? [],
781+ anBefore: activatedWorldInfo.ANBeforeEntries ?? [],
782+ anAfter: activatedWorldInfo.ANAfterEntries ?? [],
781783 };
782784}
783785
@@ -3862,7 +3864,7 @@ function parseDecorators(content) {
38623864 * @param {string[]} chat The chat messages to scan, in reverse order.
38633865 * @param {number} maxContext The maximum context size of the generation.
38643866 * @param {boolean} isDryRun Whether to perform a dry run.
38653867 * @typedef {{ worldInfoBefore: string, worldInfoAfter: string, EMEntries: any[], WIDepthEntries: any[], ANBeforeEntries: any[], ANAfterEntries: any[], allActivatedEntries: Set<any> }} WIActivated
38663868 * @returns {Promise<WIActivated>} The world info activated.
38673869 */
38683870export async function checkWorldInfo(chat, maxContext, isDryRun) {
@@ -3906,7 +3908,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
39063908 timedEffects.checkTimedEffects();
39073909
39083910 if (sortedEntries.length === 0) {
39093911 return { worldInfoBefore: '', worldInfoAfter: '', WIDepthEntries: [], EMEntries: [], ANBeforeEntries: [], ANAfterEntries: [], allActivatedEntries: new Set() };
39103912 }
39113913
39123914 /** @type {number[]} Represents the delay levels for entries that are delayed until recursion */
@@ -4355,7 +4357,7 @@ export async function checkWorldInfo(chat, maxContext, isDryRun) {
43554357 console.log(`[WI] ${isDryRun ? 'Hypothetically adding' : 'Adding'} ${allActivatedEntries.size} entries to prompt`, Array.from(allActivatedEntries.values()));
43564358 console.debug(`[WI] --- DONE${isDryRun ? ' (DRY RUN)' : ''} ---`);
43574359
43584360 return { worldInfoBefore, worldInfoAfter, EMEntries, WIDepthEntries, ANBeforeEntries: ANTopEntries, ANAfterEntries: ANBottomEntries, allActivatedEntries: new Set(allActivatedEntries.values()) };
43594361}
43604362
43614363/**