mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Update ext.macro calls in built-in extensions
This commit is contained in:
@ -2323,7 +2323,7 @@ export function scrollChatToBottom() {
|
|||||||
* @param {Record<string,any>} additionalMacro - Additional environment variables for substitution.
|
* @param {Record<string,any>} additionalMacro - Additional environment variables for substitution.
|
||||||
* @returns {string} The string with substituted parameters.
|
* @returns {string} The string with substituted parameters.
|
||||||
*/
|
*/
|
||||||
export function substituteParamsExtended(content, additionalMacro) {
|
export function substituteParamsExtended(content, additionalMacro = {}) {
|
||||||
return substituteParams(content, undefined, undefined, undefined, undefined, true, additionalMacro);
|
return substituteParams(content, undefined, undefined, undefined, undefined, true, additionalMacro);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7725,6 +7725,8 @@ window['SillyTavern'].getContext = function () {
|
|||||||
activateSendButtons,
|
activateSendButtons,
|
||||||
deactivateSendButtons,
|
deactivateSendButtons,
|
||||||
saveReply,
|
saveReply,
|
||||||
|
substituteParams,
|
||||||
|
substituteParamsExtended,
|
||||||
registerSlashCommand: registerSlashCommand,
|
registerSlashCommand: registerSlashCommand,
|
||||||
executeSlashCommands: executeSlashCommands,
|
executeSlashCommands: executeSlashCommands,
|
||||||
timestampToMoment: timestampToMoment,
|
timestampToMoment: timestampToMoment,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { getBase64Async, isTrueBoolean, saveBase64AsFile } from '../../utils.js';
|
import { getBase64Async, isTrueBoolean, saveBase64AsFile } from '../../utils.js';
|
||||||
import { getContext, getApiUrl, doExtrasFetch, extension_settings, modules, renderExtensionTemplateAsync } from '../../extensions.js';
|
import { getContext, getApiUrl, doExtrasFetch, extension_settings, modules, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||||
import { callPopup, getRequestHeaders, saveSettingsDebounced, substituteParams } from '../../../script.js';
|
import { callPopup, getRequestHeaders, saveSettingsDebounced, substituteParamsExtended } from '../../../script.js';
|
||||||
import { getMessageTimeStamp } from '../../RossAscends-mods.js';
|
import { getMessageTimeStamp } from '../../RossAscends-mods.js';
|
||||||
import { SECRET_KEYS, secret_state } from '../../secrets.js';
|
import { SECRET_KEYS, secret_state } from '../../secrets.js';
|
||||||
import { getMultimodalCaption } from '../shared.js';
|
import { getMultimodalCaption } from '../shared.js';
|
||||||
@ -95,7 +95,7 @@ async function sendCaptionedMessage(caption, image) {
|
|||||||
template += ' {{caption}}';
|
template += ' {{caption}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
let messageText = substituteParams(template).replace(/{{caption}}/i, caption);
|
let messageText = substituteParamsExtended(template, { caption: caption });
|
||||||
|
|
||||||
if (extension_settings.caption.refine_mode) {
|
if (extension_settings.caption.refine_mode) {
|
||||||
messageText = await callPopup(
|
messageText = await callPopup(
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { callPopup, eventSource, event_types, generateQuietPrompt, getRequestHeaders, online_status, saveSettingsDebounced, substituteParams } from '../../../script.js';
|
import { callPopup, eventSource, event_types, generateQuietPrompt, getRequestHeaders, online_status, saveSettingsDebounced, substituteParams, substituteParamsExtended } from '../../../script.js';
|
||||||
import { dragElement, isMobile } from '../../RossAscends-mods.js';
|
import { dragElement, isMobile } from '../../RossAscends-mods.js';
|
||||||
import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch, renderExtensionTemplateAsync } from '../../extensions.js';
|
import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch, renderExtensionTemplateAsync } from '../../extensions.js';
|
||||||
import { loadMovingUIState, power_user } from '../../power-user.js';
|
import { loadMovingUIState, power_user } from '../../power-user.js';
|
||||||
@ -1008,8 +1008,7 @@ async function getLlmPrompt(labels) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const labelsString = labels.map(x => `"${x}"`).join(', ');
|
const labelsString = labels.map(x => `"${x}"`).join(', ');
|
||||||
const prompt = substituteParams(String(extension_settings.expressions.llmPrompt))
|
const prompt = substituteParamsExtended(String(extension_settings.expressions.llmPrompt), { labels: labelsString });
|
||||||
.replace(/{{labels}}/gi, labelsString);
|
|
||||||
return prompt;
|
return prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
generateQuietPrompt,
|
generateQuietPrompt,
|
||||||
is_send_press,
|
is_send_press,
|
||||||
saveSettingsDebounced,
|
saveSettingsDebounced,
|
||||||
substituteParams,
|
substituteParamsExtended,
|
||||||
generateRaw,
|
generateRaw,
|
||||||
getMaxContextSize,
|
getMaxContextSize,
|
||||||
} from '../../../script.js';
|
} from '../../../script.js';
|
||||||
@ -43,8 +43,7 @@ const formatMemoryValue = function (value) {
|
|||||||
value = value.trim();
|
value = value.trim();
|
||||||
|
|
||||||
if (extension_settings.memory.template) {
|
if (extension_settings.memory.template) {
|
||||||
let result = extension_settings.memory.template.replace(/{{summary}}/i, value);
|
return substituteParamsExtended(extension_settings.memory.template, { summary: value });
|
||||||
return substituteParams(result);
|
|
||||||
} else {
|
} else {
|
||||||
return `Summary: ${value}`;
|
return `Summary: ${value}`;
|
||||||
}
|
}
|
||||||
@ -447,7 +446,7 @@ async function summarizeCallback(args, text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const source = args.source || extension_settings.memory.source;
|
const source = args.source || extension_settings.memory.source;
|
||||||
const prompt = substituteParams((resolveVariable(args.prompt) || extension_settings.memory.prompt)?.replace(/{{words}}/gi, extension_settings.memory.promptWords));
|
const prompt = substituteParamsExtended((resolveVariable(args.prompt) || extension_settings.memory.prompt), { words: extension_settings.memory.promptWords });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (source) {
|
switch (source) {
|
||||||
@ -534,7 +533,7 @@ async function summarizeChatMain(context, force, skipWIAN) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log('Summarizing chat, messages since last summary: ' + messagesSinceLastSummary, 'words since last summary: ' + wordsSinceLastSummary);
|
console.log('Summarizing chat, messages since last summary: ' + messagesSinceLastSummary, 'words since last summary: ' + wordsSinceLastSummary);
|
||||||
const prompt = extension_settings.memory.prompt?.replace(/{{words}}/gi, extension_settings.memory.promptWords);
|
const prompt = substituteParamsExtended(extension_settings.memory.prompt, { words: extension_settings.memory.promptWords });
|
||||||
|
|
||||||
if (!prompt) {
|
if (!prompt) {
|
||||||
console.debug('Summarization prompt is empty. Skipping summarization.');
|
console.debug('Summarization prompt is empty. Skipping summarization.');
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
setExtensionPrompt,
|
setExtensionPrompt,
|
||||||
substituteParams,
|
substituteParams,
|
||||||
generateRaw,
|
generateRaw,
|
||||||
|
substituteParamsExtended,
|
||||||
} from '../../../script.js';
|
} from '../../../script.js';
|
||||||
import {
|
import {
|
||||||
ModuleWorkerWrapper,
|
ModuleWorkerWrapper,
|
||||||
@ -441,7 +442,7 @@ async function injectDataBankChunks(queryText, collectionIds) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const insertedText = substituteParams(settings.file_template_db.replace(/{{text}}/i, textResult));
|
const insertedText = substituteParamsExtended(settings.file_template_db, { text: textResult });
|
||||||
setExtensionPrompt(EXTENSION_PROMPT_TAG_DB, insertedText, settings.file_position_db, settings.file_depth_db, settings.include_wi, settings.file_depth_role_db);
|
setExtensionPrompt(EXTENSION_PROMPT_TAG_DB, insertedText, settings.file_position_db, settings.file_depth_db, settings.include_wi, settings.file_depth_role_db);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Vectors: Failed to insert Data Bank chunks', error);
|
console.error('Vectors: Failed to insert Data Bank chunks', error);
|
||||||
@ -592,7 +593,7 @@ async function rearrangeChat(chat) {
|
|||||||
function getPromptText(queriedMessages) {
|
function getPromptText(queriedMessages) {
|
||||||
const queriedText = queriedMessages.map(x => collapseNewlines(`${x.name}: ${x.mes}`).trim()).join('\n\n');
|
const queriedText = queriedMessages.map(x => collapseNewlines(`${x.name}: ${x.mes}`).trim()).join('\n\n');
|
||||||
console.log('Vectors: relevant past messages found.\n', queriedText);
|
console.log('Vectors: relevant past messages found.\n', queriedText);
|
||||||
return substituteParams(settings.template.replace(/{{text}}/i, queriedText));
|
return substituteParamsExtended(settings.template, { text: queriedText });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user