Allow "none" position for extension prompt injects
| @@ -7,7 +7,8 @@ | |||
| 7 | background-color: green; | 7 | background-color: green; |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | .extensions_block input[type="checkbox"] { | 10 | .extensions_block input[type="checkbox"], |
| 11 | .extensions_block input[type="radio"] { | ||
| 11 | margin-left: 10px; | 12 | margin-left: 10px; |
| 12 | margin-right: 10px; | 13 | margin-right: 10px; |
| 13 | } | 14 | } |
| @@ -570,6 +570,7 @@ export const system_message_types = { | |||
| 570 | * @enum {number} Extension prompt types | 570 | * @enum {number} Extension prompt types |
| 571 | */ | 571 | */ |
| 572 | export const extension_prompt_types = { | 572 | export const extension_prompt_types = { |
| 573 | NONE: -1, | ||
| 573 | IN_PROMPT: 0, | 574 | IN_PROMPT: 0, |
| 574 | IN_CHAT: 1, | 575 | IN_CHAT: 1, |
| 575 | BEFORE_PROMPT: 2, | 576 | BEFORE_PROMPT: 2, |
| @@ -14,6 +14,7 @@ import { | |||
| 14 | substituteParamsExtended, | 14 | substituteParamsExtended, |
| 15 | generateRaw, | 15 | generateRaw, |
| 16 | getMaxContextSize, | 16 | getMaxContextSize, |
| 17 | setExtensionPrompt, | ||
| 17 | } from '../../../script.js'; | 18 | } from '../../../script.js'; |
| 18 | import { is_group_generating, selected_group } from '../../group-chats.js'; | 19 | import { is_group_generating, selected_group } from '../../group-chats.js'; |
| 19 | import { loadMovingUIState } from '../../power-user.js'; | 20 | import { loadMovingUIState } from '../../power-user.js'; |
| @@ -73,6 +74,7 @@ const defaultSettings = { | |||
| 73 | template: defaultTemplate, | 74 | template: defaultTemplate, |
| 74 | position: extension_prompt_types.IN_PROMPT, | 75 | position: extension_prompt_types.IN_PROMPT, |
| 75 | role: extension_prompt_roles.SYSTEM, | 76 | role: extension_prompt_roles.SYSTEM, |
| 77 | scan: false, | ||
| 76 | depth: 2, | 78 | depth: 2, |
| 77 | promptWords: 200, | 79 | promptWords: 200, |
| 78 | promptMinWords: 25, | 80 | promptMinWords: 25, |
| @@ -122,6 +124,7 @@ function loadSettings() { | |||
| 122 | $(`input[name="memory_prompt_builder"][value="${extension_settings.memory.prompt_builder}"]`).prop('checked', true).trigger('input'); | 124 | $(`input[name="memory_prompt_builder"][value="${extension_settings.memory.prompt_builder}"]`).prop('checked', true).trigger('input'); |
| 123 | $('#memory_override_response_length').val(extension_settings.memory.overrideResponseLength).trigger('input'); | 125 | $('#memory_override_response_length').val(extension_settings.memory.overrideResponseLength).trigger('input'); |
| 124 | $('#memory_max_messages_per_request').val(extension_settings.memory.maxMessagesPerRequest).trigger('input'); | 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 | switchSourceControls(extension_settings.memory.source); | 128 | switchSourceControls(extension_settings.memory.source); |
| 126 | } | 129 | } |
| 127 | 130 | ||
| @@ -279,6 +282,13 @@ function onMemoryPositionChange(e) { | |||
| 279 | saveSettingsDebounced(); | 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 | function onMemoryPromptWordsForceInput() { | 292 | function onMemoryPromptWordsForceInput() { |
| 283 | const value = $(this).val(); | 293 | const value = $(this).val(); |
| 284 | extension_settings.memory.promptForceWords = Number(value); | 294 | extension_settings.memory.promptForceWords = Number(value); |
| @@ -800,8 +810,7 @@ function reinsertMemory() { | |||
| 800 | * @param {number|null} index Index of the chat message to save the summary to. If null, the pre-last message is used. | 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 | function setMemoryContext(value, saveToMessage, index = null) { | 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 | $('#memory_contents').val(value); | 814 | $('#memory_contents').val(value); |
| 806 | 815 | ||
| 807 | const summaryLog = value | 816 | const summaryLog = value |
| @@ -809,6 +818,7 @@ function setMemoryContext(value, saveToMessage, index = null) { | |||
| 809 | : 'Summary has no content'; | 818 | : 'Summary has no content'; |
| 810 | console.debug(summaryLog); | 819 | console.debug(summaryLog); |
| 811 | 820 | ||
| 821 | const context = getContext(); | ||
| 812 | if (saveToMessage && context.chat.length) { | 822 | if (saveToMessage && context.chat.length) { |
| 813 | const idx = index ?? context.chat.length - 2; | 823 | const idx = index ?? context.chat.length - 2; |
| 814 | const mes = context.chat[idx < 0 ? 0 : idx]; | 824 | const mes = context.chat[idx < 0 ? 0 : idx]; |
| @@ -894,6 +904,7 @@ function setupListeners() { | |||
| 894 | $('#memory_prompt_words_auto').off('click').on('click', onPromptForceWordsAutoClick); | 904 | $('#memory_prompt_words_auto').off('click').on('click', onPromptForceWordsAutoClick); |
| 895 | $('#memory_override_response_length').off('click').on('input', onOverrideResponseLengthInput); | 905 | $('#memory_override_response_length').off('click').on('input', onOverrideResponseLengthInput); |
| 896 | $('#memory_max_messages_per_request').off('click').on('input', onMaxMessagesPerRequestInput); | 906 | $('#memory_max_messages_per_request').off('click').on('input', onMaxMessagesPerRequestInput); |
| 907 | $('#memory_include_wi_scan').off('input').on('input', onMemoryIncludeWIScanInput); | ||
| 897 | $('#summarySettingsBlockToggle').off('click').on('click', function () { | 908 | $('#summarySettingsBlockToggle').off('click').on('click', function () { |
| 898 | console.log('saw settings button click'); | 909 | console.log('saw settings button click'); |
| 899 | $('#summarySettingsBlock').slideToggle(200, 'swing'); //toggleClass("hidden"); | 910 | $('#summarySettingsBlock').slideToggle(200, 'swing'); //toggleClass("hidden"); |
| @@ -109,8 +109,17 @@ | |||
| 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> | 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 | </div> | 110 | </div> |
| 111 | <label for="memory_position" data-i18n="ext_sum_injection_position">Injection Position</label> | 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 | <div class="radio_group"> | 116 | <div class="radio_group"> |
| 113 | <label> | 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 | <input type="radio" name="memory_position" value="2" /> | 123 | <input type="radio" name="memory_position" value="2" /> |
| 115 | <span data-i18n="Before Main Prompt / Story String">Before Main Prompt / Story String</span> | 124 | <span data-i18n="Before Main Prompt / Story String">Before Main Prompt / Story String</span> |
| 116 | </label> | 125 | </label> |
| @@ -1356,7 +1356,7 @@ export function initDefaultSlashCommands() { | |||
| 1356 | enumProvider: commonEnumProviders.injects, | 1356 | enumProvider: commonEnumProviders.injects, |
| 1357 | }), | 1357 | }), |
| 1358 | new SlashCommandNamedArgument( | 1358 | new SlashCommandNamedArgument( |
| 1359 | 'position', 'injection position', [ARGUMENT_TYPE.STRING], false, false, 'after', ['before', 'after', 'chat'], | 1359 | 'position', 'injection position', [ARGUMENT_TYPE.STRING], false, false, 'after', ['before', 'after', 'chat', 'none'], |
| 1360 | ), | 1360 | ), |
| 1361 | new SlashCommandNamedArgument( | 1361 | new SlashCommandNamedArgument( |
| 1362 | 'depth', 'injection depth', [ARGUMENT_TYPE.NUMBER], false, false, '4', | 1362 | 'depth', 'injection depth', [ARGUMENT_TYPE.NUMBER], false, false, '4', |
| @@ -1384,7 +1384,7 @@ export function initDefaultSlashCommands() { | |||
| 1384 | 'text', [ARGUMENT_TYPE.STRING], false, | 1384 | 'text', [ARGUMENT_TYPE.STRING], false, |
| 1385 | ), | 1385 | ), |
| 1386 | ], | 1386 | ], |
| 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" (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).', | 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 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ | 1389 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 1390 | name: 'listinjects', | 1390 | name: 'listinjects', |
| @@ -1486,6 +1486,7 @@ function injectCallback(args, value) { | |||
| 1486 | 'before': extension_prompt_types.BEFORE_PROMPT, | 1486 | 'before': extension_prompt_types.BEFORE_PROMPT, |
| 1487 | 'after': extension_prompt_types.IN_PROMPT, | 1487 | 'after': extension_prompt_types.IN_PROMPT, |
| 1488 | 'chat': extension_prompt_types.IN_CHAT, | 1488 | 'chat': extension_prompt_types.IN_CHAT, |
| 1489 | 'none': extension_prompt_types.NONE, | ||
| 1489 | }; | 1490 | }; |
| 1490 | const roles = { | 1491 | const roles = { |
| 1491 | 'system': extension_prompt_roles.SYSTEM, | 1492 | 'system': extension_prompt_roles.SYSTEM, |