Prompt Manager: Make main/PHI/aux injectable (#4829)

0b5b3f089ebdf5965c4295bc02b2b9065fca7a03

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

Signed
2 files changed, +35 -55Ignore whitespace
public/scripts/PromptManager.js+1 -9
@@ -579,10 +579,6 @@ class PromptManager {
579 const sourceName = this.promptSources[promptId];579 const sourceName = this.promptSources[promptId];
580 entrySource.textContent = sourceName;580 entrySource.textContent = sourceName;
581 }581 }
582
583 if (!this.systemPrompts.includes(promptId)) {
584 injectionPositionField.removeAttribute('disabled');
585 }
586 };582 };
587583
588 // Append prompt to selected character584 // Append prompt to selected character
@@ -1399,10 +1395,6 @@ class PromptManager {
1399 entrySource.textContent = sourceName;1395 entrySource.textContent = sourceName;
1400 }1396 }
14011397
1402 if (this.systemPrompts.includes(prompt.identifier)) {
1403 injectionPositionField.setAttribute('disabled', 'disabled');
1404 }
1405
1406 const resetPromptButton = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_reset');1398 const resetPromptButton = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_reset');
1407 if (true === prompt.system_prompt) {1399 if (true === prompt.system_prompt) {
1408 resetPromptButton.style.display = 'block';1400 resetPromptButton.style.display = 'block';
@@ -1757,7 +1749,7 @@ class PromptManager {
1757 ${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}1749 ${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}
1758 ${this.isPromptInspectionAllowed(prompt) ? `<a title="${encodedName}" class="prompt-manager-inspect-action">${encodedName}</a>` : `<span title="${encodedName}">${encodedName}</span>`}1750 ${this.isPromptInspectionAllowed(prompt) ? `<a title="${encodedName}" class="prompt-manager-inspect-action">${encodedName}</a>` : `<span title="${encodedName}">${encodedName}</span>`}
1759 ${roleIcon ? `<span data-role="${escapeHtml(prompt.role)}" class="fa-xs fa-solid ${roleIcon}" title="${roleTitle}"></span>` : ''}1751 ${roleIcon ? `<span data-role="${escapeHtml(prompt.role)}" class="fa-xs fa-solid ${roleIcon}" title="${roleTitle}"></span>` : ''}
1760 ${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${escapeHtml(prompt.injection_depth)}</small>` : ''}1752 ${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${escapeHtml(prompt.injection_depth.toString())}</small>` : ''}
1761 ${isOverriddenPrompt ? '<small class="fa-solid fa-address-card prompt-manager-overridden" title="Pulled from a character card"></small>' : ''}1753 ${isOverriddenPrompt ? '<small class="fa-solid fa-address-card prompt-manager-overridden" title="Pulled from a character card"></small>' : ''}
1762 </span>1754 </span>
1763 <span>1755 <span>
public/scripts/openai.js+34 -46
@@ -1117,60 +1117,48 @@ async function populateChatCompletion(prompts, chatCompletion, { bias, quietProm
1117 // Bias1117 // Bias
1118 if (bias && bias.trim().length) await addToChatCompletion('bias');1118 if (bias && bias.trim().length) await addToChatCompletion('bias');
11191119
1120 // Tavern Extras - Summary1120 const injectToMain = async (/** @type {Prompt} */ prompt, /** @type {string|number} */ position) => {
1121 if (prompts.has('summary')) {1121 if (chatCompletion.has('main')) {
1122 const summary = prompts.get('summary');1122 const message = await Message.fromPromptAsync(prompt);
11231123 chatCompletion.insert(message, 'main', position);
1124 if (summary.position) {1124 } else {
1125 const message = await Message.fromPromptAsync(summary);1125 // Convert the relative prompt to an injection and place it relative to main prompt
1126 chatCompletion.insert(message, 'main', summary.position);1126 // Keeping prompts in the same order bucket will squash them together during in-chat injection
1127 }1127 const indexOfMain = absolutePrompts.findIndex(p => p.identifier === 'main');
1128 }1128 if (indexOfMain >= 0) {
11291129 const main = absolutePrompts[indexOfMain];
1130 // Authors Note1130 const promptCopy = new Prompt(prompt);
1131 if (prompts.has('authorsNote')) {1131 promptCopy.role = main.role;
1132 const authorsNote = prompts.get('authorsNote');1132 promptCopy.injection_position = main.injection_position;
11331133 promptCopy.injection_depth = main.injection_depth;
1134 if (authorsNote.position) {1134 promptCopy.injection_order = main.injection_order;
1135 const message = await Message.fromPromptAsync(authorsNote);1135 const newIndex = position === 'end' ? indexOfMain + 1 : indexOfMain;
1136 chatCompletion.insert(message, 'main', authorsNote.position);1136 absolutePrompts.splice(newIndex, 0, promptCopy);
1137 }1137 }
1138 }
1139
1140 // Vectors Memory
1141 if (prompts.has('vectorsMemory')) {
1142 const vectorsMemory = prompts.get('vectorsMemory');
1143
1144 if (vectorsMemory.position) {
1145 const message = await Message.fromPromptAsync(vectorsMemory);
1146 chatCompletion.insert(message, 'main', vectorsMemory.position);
1147 }
1148 }
1149
1150 // Vectors Data Bank
1151 if (prompts.has('vectorsDataBank')) {
1152 const vectorsDataBank = prompts.get('vectorsDataBank');
1153
1154 if (vectorsDataBank.position) {
1155 const message = await Message.fromPromptAsync(vectorsDataBank);
1156 chatCompletion.insert(message, 'main', vectorsDataBank.position);
1157 }1138 }
1158 }1139 };
11591140
1160 // Smart Context (ChromaDB)1141 const knownPrompts = [
1161 if (prompts.has('smartContext')) {1142 'summary',
1162 const smartContext = prompts.get('smartContext');1143 'authorsNote',
1144 'vectorsMemory',
1145 'vectorsDataBank',
1146 'smartContext',
1147 ];
11631148
1164 if (smartContext.position) {1149 // Known relative extension prompts
1165 const message = await Message.fromPromptAsync(smartContext);1150 for (const key of knownPrompts) {
1166 chatCompletion.insert(message, 'main', smartContext.position);1151 if (prompts.has(key)) {
1152 const prompt = prompts.get(key);
1153 if (prompt.position) {
1154 await injectToMain(prompt, prompt.position);
1155 }
1167 }1156 }
1168 }1157 }
11691158
1170 // Other relative extension prompts1159 // Other relative extension prompts
1171 for (const prompt of prompts.collection.filter(p => p.extension && p.position)) {1160 for (const prompt of prompts.collection.filter(p => p.extension && p.position)) {
1172 const message = await Message.fromPromptAsync(prompt);1161 await injectToMain(prompt, prompt.position);
1173 chatCompletion.insert(message, 'main', prompt.position);
1174 }1162 }
11751163
1176 // Pre-allocation of tokens for tool data1164 // Pre-allocation of tokens for tool data