Add {{lastGenerationType}} macro

b08cdffc64d6ba2a0b317a38d2928796531ef034

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +23 -2Ignore whitespace
public/script.js+2 -1
@@ -242,7 +242,7 @@ import { BulkEditOverlay, CharacterContextMenu } from './scripts/BulkEditOverlay
242import { loadFeatherlessModels, loadMancerModels, loadOllamaModels, loadTogetherAIModels, loadInfermaticAIModels, loadOpenRouterModels, loadVllmModels, loadAphroditeModels, loadDreamGenModels, initTextGenModels, loadTabbyModels } from './scripts/textgen-models.js';242import { loadFeatherlessModels, loadMancerModels, loadOllamaModels, loadTogetherAIModels, loadInfermaticAIModels, loadOpenRouterModels, loadVllmModels, loadAphroditeModels, loadDreamGenModels, initTextGenModels, loadTabbyModels } from './scripts/textgen-models.js';
243import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, decodeStyleTags, encodeStyleTags, isExternalMediaAllowed, getCurrentEntityId, preserveNeutralChat, restoreNeutralChat } from './scripts/chats.js';243import { appendFileContent, hasPendingFileAttachment, populateFileAttachment, decodeStyleTags, encodeStyleTags, isExternalMediaAllowed, getCurrentEntityId, preserveNeutralChat, restoreNeutralChat } from './scripts/chats.js';
244import { initPresetManager } from './scripts/preset-manager.js';244import { initPresetManager } from './scripts/preset-manager.js';
245import { MacrosParser, evaluateMacros, getLastMessageId } from './scripts/macros.js';245import { MacrosParser, evaluateMacros, getLastMessageId, initMacros } from './scripts/macros.js';
246import { currentUser, setUserControls } from './scripts/user.js';246import { currentUser, setUserControls } from './scripts/user.js';
247import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup, fixToastrForDialogs } from './scripts/popup.js';247import { POPUP_RESULT, POPUP_TYPE, Popup, callGenericPopup, fixToastrForDialogs } from './scripts/popup.js';
248import { renderTemplate, renderTemplateAsync } from './scripts/templates.js';248import { renderTemplate, renderTemplateAsync } from './scripts/templates.js';
@@ -957,6 +957,7 @@ async function firstLoadInit() {
957 initDynamicStyles();957 initDynamicStyles();
958 initTags();958 initTags();
959 initBookmarks();959 initBookmarks();
960 initMacros();
960 await getUserAvatars(true, user_avatar);961 await getUserAvatars(true, user_avatar);
961 await getCharacters();962 await getCharacters();
962 await getBackgrounds();963 await getBackgrounds();
public/scripts/macros.js+20 -1
@@ -1,5 +1,5 @@
1import { Handlebars, moment, seedrandom, droll } from '../lib.js';1import { Handlebars, moment, seedrandom, droll } from '../lib.js';
2import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams } from '../script.js';2import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams, eventSource, event_types } from '../script.js';
3import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';3import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';
4import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';4import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
5import { getInstructMacros } from './instruct-mode.js';5import { getInstructMacros } from './instruct-mode.js';
@@ -521,3 +521,22 @@ export function evaluateMacros(content, env, postProcessFn) {
521521
522 return content;522 return content;
523}523}
524
525export function initMacros() {
526 function initLastGenerationType() {
527 let lastGenerationType = '';
528
529 MacrosParser.registerMacro('lastGenerationType', () => lastGenerationType);
530
531 eventSource.on(event_types.GENERATION_STARTED, (type, _params, isDryRun) => {
532 if (isDryRun) return;
533 lastGenerationType = type || 'normal';
534 });
535
536 eventSource.on(event_types.CHAT_CHANGED, () => {
537 lastGenerationType = '';
538 });
539 }
540
541 initLastGenerationType();
542}
public/scripts/templates/macros.html+1 -0
@@ -8,6 +8,7 @@
8 <li><tt>&lcub;&lcub;noop&rcub;&rcub;</tt> – <span data-i18n="help_macros_4">no operation, just an empty string.</span></li>8 <li><tt>&lcub;&lcub;noop&rcub;&rcub;</tt> – <span data-i18n="help_macros_4">no operation, just an empty string.</span></li>
9 <li><tt>&lcub;&lcub;original&rcub;&rcub;</tt> – <span data-i18n="help_macros_5">global prompts defined in API settings. Only valid in Advanced Definitions prompt overrides.</span></li>9 <li><tt>&lcub;&lcub;original&rcub;&rcub;</tt> – <span data-i18n="help_macros_5">global prompts defined in API settings. Only valid in Advanced Definitions prompt overrides.</span></li>
10 <li><tt>&lcub;&lcub;input&rcub;&rcub;</tt> – <span data-i18n="help_macros_6">the user input</span></li>10 <li><tt>&lcub;&lcub;input&rcub;&rcub;</tt> – <span data-i18n="help_macros_6">the user input</span></li>
11 <li><tt>&lcub;&lcub;lastGenerationType&rcub;&rcub;</tt> - <span>the type of the last queued generation request. Empty if no generations were performed yet or the active chat was switched. Possible values: "normal", "impersonate", "regenerate", "quiet", "swipe", "continue".</span></li>
11 <li><tt>&lcub;&lcub;charPrompt&rcub;&rcub;</tt> – <span data-i18n="help_macros_7">the Character's Main Prompt override</span></li>12 <li><tt>&lcub;&lcub;charPrompt&rcub;&rcub;</tt> – <span data-i18n="help_macros_7">the Character's Main Prompt override</span></li>
12 <li><tt>&lcub;&lcub;charInstruction&rcub;&rcub;</tt> – <span data-i18n="help_macros_8">the Character's Post-History Instructions override</span></li>13 <li><tt>&lcub;&lcub;charInstruction&rcub;&rcub;</tt> – <span data-i18n="help_macros_8">the Character's Post-History Instructions override</span></li>
13 <li><tt>&lcub;&lcub;description&rcub;&rcub;</tt> – <span data-i18n="help_macros_9">the Character's Description</span></li>14 <li><tt>&lcub;&lcub;description&rcub;&rcub;</tt> – <span data-i18n="help_macros_9">the Character's Description</span></li>