Allow "none" position for extension prompt injects
| @@ -7,7 +7,8 @@ | ||
| 7 | 7 | background-color: green; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | .extensions_block input[type="checkbox"] {, |
| 11 | +.extensions_block input[type="radio"] { | |
| 11 | 12 | margin-left: 10px; |
| 12 | 13 | margin-right: 10px; |
| 13 | 14 | } |
| @@ -570,6 +570,7 @@ export const system_message_types = { | ||
| 570 | 570 | * @enum {number} Extension prompt types |
| 571 | 571 | */ |
| 572 | 572 | export const extension_prompt_types = { |
| 573 | + NONE: -1, | |
| 573 | 574 | IN_PROMPT: 0, |
| 574 | 575 | IN_CHAT: 1, |
| 575 | 576 | BEFORE_PROMPT: 2, |
| @@ -14,6 +14,7 @@ import { | ||
| 14 | 14 | substituteParamsExtended, |
| 15 | 15 | generateRaw, |
| 16 | 16 | getMaxContextSize, |
| 17 | + setExtensionPrompt, | |
| 17 | 18 | } from '../../../script.js'; |
| 18 | 19 | import { is_group_generating, selected_group } from '../../group-chats.js'; |
| 19 | 20 | import { loadMovingUIState } from '../../power-user.js'; |
| @@ -73,6 +74,7 @@ const defaultSettings = { | ||
| 73 | 74 | template: defaultTemplate, |
| 74 | 75 | position: extension_prompt_types.IN_PROMPT, |
| 75 | 76 | role: extension_prompt_roles.SYSTEM, |
| 77 | + scan: false, | |
| 76 | 78 | depth: 2, |
| 77 | 79 | promptWords: 200, |
| 78 | 80 | promptMinWords: 25, |
| @@ -122,6 +124,7 @@ function loadSettings() { | ||
| 122 | 124 | $(`input[name="memory_prompt_builder"][value="${extension_settings.memory.prompt_builder}"]`).prop('checked', true).trigger('input'); |
| 123 | 125 | $('#memory_override_response_length').val(extension_settings.memory.overrideResponseLength).trigger('input'); |
| 124 | 126 | $('#memory_max_messages_per_request').val(extension_settings.memory.maxMessagesPerRequest).trigger('input'); |
| 127 | + $('#memory_include_wi_scan').prop('checked', extension_settings.memory.scan).trigger('input'); | |
| 125 | 128 | switchSourceControls(extension_settings.memory.source); |
| 126 | 129 | } |
| 127 | 130 | |
| @@ -279,6 +282,13 @@ function onMemoryPositionChange(e) { | ||
| 279 | 282 | saveSettingsDebounced(); |
| 280 | 283 | } |
| 281 | 284 | |
| 285 | +function onMemoryIncludeWIScanInput() { | |
| 286 | + const value = !!$(this).prop('checked'); | |
| 287 | + extension_settings.memory.scan = value; | |
| 288 | + reinsertMemory(); | |
| 289 | + saveSettingsDebounced(); | |
| 290 | +} | |
| 291 | + | |
| 282 | 292 | function onMemoryPromptWordsForceInput() { |
| 283 | 293 | const value = $(this).val(); |
| 284 | 294 | extension_settings.memory.promptForceWords = Number(value); |
| @@ -800,8 +810,7 @@ function reinsertMemory() { | ||
| 800 | 810 | * @param {number|null} index Index of the chat message to save the summary to. If null, the pre-last message is used. |
| 801 | 811 | */ |
| 802 | 812 | function setMemoryContext(value, saveToMessage, index = null) { |
| 803 | - const context = getContext(); | |
| 813 | + setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_settings.memory.position, extension_settings.memory.depth, extension_settings.memory.scan, extension_settings.memory.role); | |
| 804 | - context.setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_settings.memory.position, extension_settings.memory.depth, false, extension_settings.memory.role); | |
| 805 | 814 | $('#memory_contents').val(value); |
| 806 | 815 | |
| 807 | 816 | const summaryLog = value |
| @@ -809,6 +818,7 @@ function setMemoryContext(value, saveToMessage, index = null) { | ||
| 809 | 818 | : 'Summary has no content'; |
| 810 | 819 | console.debug(summaryLog); |
| 811 | 820 | |
| 821 | + const context = getContext(); | |
| 812 | 822 | if (saveToMessage && context.chat.length) { |
| 813 | 823 | const idx = index ?? context.chat.length - 2; |
| 814 | 824 | const mes = context.chat[idx < 0 ? 0 : idx]; |
| @@ -894,6 +904,7 @@ function setupListeners() { | ||
| 894 | 904 | $('#memory_prompt_words_auto').off('click').on('click', onPromptForceWordsAutoClick); |
| 895 | 905 | $('#memory_override_response_length').off('click').on('input', onOverrideResponseLengthInput); |
| 896 | 906 | $('#memory_max_messages_per_request').off('click').on('input', onMaxMessagesPerRequestInput); |
| 907 | + $('#memory_include_wi_scan').off('input').on('input', onMemoryIncludeWIScanInput); | |
| 897 | 908 | $('#summarySettingsBlockToggle').off('click').on('click', function () { |
| 898 | 909 | console.log('saw settings button click'); |
| 899 | 910 | $('#summarySettingsBlock').slideToggle(200, 'swing'); //toggleClass("hidden"); |
| @@ -109,8 +109,17 @@ | ||
| 109 | 109 | <textarea id="memory_template" class="text_pole textarea_compact" rows="2" data-i18n="[placeholder]ext_sum_memory_template_placeholder" placeholder="{{summary}} will resolve to the current summary contents."></textarea> |
| 110 | 110 | </div> |
| 111 | 111 | <label for="memory_position" data-i18n="ext_sum_injection_position">Injection Position</label> |
| 112 | + <label class="checkbox_label" for="memory_include_wi_scan" data-i18n="[title]ext_sum_include_wi_scan_desc" title="Include the latest summary in the WI scan."> | |
| 113 | + <input id="memory_include_wi_scan" type="checkbox" /> | |
| 114 | + <span data-i18n="ext_sum_include_wi_scan">Include in World Info Scanning</span> | |
| 115 | + </label> | |
| 112 | 116 | <div class="radio_group"> |
| 113 | 117 | <label> |
| 118 | + <input type="radio" name="memory_position" value="-1" /> | |
| 119 | + <span data-i18n="None (not injected)">None (not injected)</span> | |
| 120 | + <i class="fa-solid fa-info-circle" title="The summary will not be injected into the prompt. You can still access it via the {{summary}} macro." data-i18n="[title]ext_sum_injection_position_none"></i> | |
| 121 | + </label> | |
| 122 | + <label> | |
| 114 | 123 | <input type="radio" name="memory_position" value="2" /> |
| 115 | 124 | <span data-i18n="Before Main Prompt / Story String">Before Main Prompt / Story String</span> |
| 116 | 125 | </label> |
| @@ -1356,7 +1356,7 @@ export function initDefaultSlashCommands() { | ||
| 1356 | 1356 | enumProvider: commonEnumProviders.injects, |
| 1357 | 1357 | }), |
| 1358 | 1358 | new SlashCommandNamedArgument( |
| 1359 | 1359 | 'position', 'injection position', [ARGUMENT_TYPE.STRING], false, false, 'after', ['before', 'after', 'chat', 'none'], |
| 1360 | 1360 | ), |
| 1361 | 1361 | new SlashCommandNamedArgument( |
| 1362 | 1362 | 'depth', 'injection depth', [ARGUMENT_TYPE.NUMBER], false, false, '4', |
| @@ -1384,7 +1384,7 @@ export function initDefaultSlashCommands() { | ||
| 1384 | 1384 | 'text', [ARGUMENT_TYPE.STRING], false, |
| 1385 | 1385 | ), |
| 1386 | 1386 | ], |
| 1387 | 1387 | helpString: 'Injects a text into the LLM prompt for the current chat. Requires a unique injection ID. Positions: "before" main prompt, "after" main prompt, in-"chat", hidden with "none" (default: after). Depth: injection depth for the prompt (default: 4). Role: role for in-chat injections (default: system). Scan: include injection content into World Info scans (default: false). Hidden injects in "none" position are not inserted into the prompt but can be used for triggering WI entries.', |
| 1388 | 1388 | })); |
| 1389 | 1389 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 1390 | 1390 | name: 'listinjects', |
| @@ -1486,6 +1486,7 @@ function injectCallback(args, value) { | ||
| 1486 | 1486 | 'before': extension_prompt_types.BEFORE_PROMPT, |
| 1487 | 1487 | 'after': extension_prompt_types.IN_PROMPT, |
| 1488 | 1488 | 'chat': extension_prompt_types.IN_CHAT, |
| 1489 | + 'none': extension_prompt_types.NONE, | |
| 1489 | 1490 | }; |
| 1490 | 1491 | const roles = { |
| 1491 | 1492 | 'system': extension_prompt_roles.SYSTEM, |