Preserve prompt cache shape in keepalives
| @@ -4218,6 +4218,7 @@ function removeLastMessage() { | ||
| 4218 | 4218 | * @property {string} [quietName] Name to use for the quiet prompt (defaults to "System:") |
| 4219 | 4219 | * @property {number} [depth] Recursion depth for the generation. Used to prevent infinite loops in tool calls. |
| 4220 | 4220 | * @property {JsonSchema} [jsonSchema] JSON schema to use for the structured generation. Usually requires a special instruction. |
| 4221 | + * @property {boolean} [squashSystemMessages] Apply the configured system-message squashing during a dry run. | |
| 4221 | 4222 | */ |
| 4222 | 4223 | |
| 4223 | 4224 | /** |
| @@ -4228,7 +4229,7 @@ function removeLastMessage() { | ||
| 4228 | 4229 | * @param {boolean} dryRun Whether to actually generate a message or just assemble the prompt |
| 4229 | 4230 | * @returns {Promise<any>} Returns a promise that resolves when the text is done generating. |
| 4230 | 4231 | */ |
| 4231 | 4232 | export async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName, jsonSchema = null, depth = 0, squashSystemMessages = false } = {}, dryRun = false) { |
| 4232 | 4233 | console.log('Generate entered'); |
| 4233 | 4234 | setGenerationProgress(0); |
| 4234 | 4235 | generation_started = new Date(); |
| @@ -5240,6 +5241,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 5240 | 5241 | jailbreakPromptOverride: jailbreak, |
| 5241 | 5242 | messages: oaiMessages, |
| 5242 | 5243 | messageExamples: oaiMessageExamples, |
| 5244 | + squashSystemMessages, | |
| 5243 | 5245 | }, dryRun); |
| 5244 | 5246 | generate_data = { prompt: prompt }; |
| 5245 | 5247 | |
| @@ -209,7 +209,9 @@ async function prepareKeepaliveRequest() { | ||
| 209 | 209 | eventSource.on(event_types.GENERATE_AFTER_DATA, captureData); |
| 210 | 210 | setExtensionPrompt(KEEPALIVE_INJECT_ID, extension_settings[MODULE].message, extension_prompt_types.IN_CHAT, 0, false, extension_prompt_roles.USER); |
| 211 | 211 | try { |
| 212 | - await Generate('quiet', { quiet_prompt: '', force_name2: true }, true); | |
| 212 | + // A normal live request applies the user's system-message squashing after prompt assembly. | |
| 213 | + // Opt into the same final transform here so provider cache keys see identical boundaries. | |
| 214 | + await Generate('quiet', { quiet_prompt: '', force_name2: true, squashSystemMessages: true }, true); | |
| 213 | 215 | } finally { |
| 214 | 216 | setExtensionPrompt(KEEPALIVE_INJECT_ID, '', extension_prompt_types.IN_CHAT, 0, false, extension_prompt_roles.USER); |
| 215 | 217 | eventSource.removeListener(event_types.GENERATE_AFTER_DATA, captureData); |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | "js": "index.js", |
| 7 | 7 | "css": "", |
| 8 | 8 | "author": "SillyTavern", |
| 9 | 9 | "version": "1.1.12", |
| 10 | 10 | "homePage": "https://github.com/SillyTavern/SillyTavern", |
| 11 | 11 | "hooks": { |
| 12 | 12 | "activate": "init" |
| @@ -1528,6 +1528,7 @@ async function preparePromptsForChatCompletion({ scenario, charPersonality, name | ||
| 1528 | 1528 | * @param {object} content.extensionPrompts - An array of additional prompts. |
| 1529 | 1529 | * @param {object[]} content.messages - An array of messages to be used as chat history. |
| 1530 | 1530 | * @param {string[]} content.messageExamples - An array of messages to be used as dialogue examples. |
| 1531 | + * @param {boolean} [content.squashSystemMessages] Apply configured system-message squashing during a dry run. | |
| 1531 | 1532 | * @param dryRun - Whether this is a live call or not. |
| 1532 | 1533 | * @returns {Promise<(any[]|boolean)[]>} An array where the first element is the prepared chat and the second element is a boolean flag. |
| 1533 | 1534 | */ |
| @@ -1548,6 +1549,7 @@ export async function prepareOpenAIMessages({ | ||
| 1548 | 1549 | jailbreakPromptOverride, |
| 1549 | 1550 | messages, |
| 1550 | 1551 | messageExamples, |
| 1552 | + squashSystemMessages = false, | |
| 1551 | 1553 | }, dryRun) { |
| 1552 | 1554 | // Without a character selected, there is no way to accurately calculate tokens |
| 1553 | 1555 | if (!promptManager.activeCharacter && dryRun) return [null, false]; |
| @@ -1597,7 +1599,7 @@ export async function prepareOpenAIMessages({ | ||
| 1597 | 1599 | // Pass chat completion to prompt manager for inspection |
| 1598 | 1600 | promptManager.setChatCompletion(chatCompletion); |
| 1599 | 1601 | |
| 1600 | 1602 | if (oai_settings.squash_system_messages && (!dryRun ==|| falsesquashSystemMessages)) { |
| 1601 | 1603 | await chatCompletion.squashSystemMessages(); |
| 1602 | 1604 | } |
| 1603 | 1605 | |