Stable Diffusion: never re-run reference image selection on swipe The reference image is selected once, together with the image prompt. Swipes reuse the prompt, so they now also always reuse the selection: if no stored selection exists (e.g. after a page reload), a swipe falls back to the first library image instead of asking the LLM again.

6d112755c32328608e0aa05943d069b69f5221e1

permissionBRICK <40219477+permissionBRICK@users.noreply.github.com>

1 files changed, +18 -0Showing whitespace changes
public/scripts/extensions/stable-diffusion/index.js+18 -0
@@ -1145,6 +1145,13 @@ const REFERENCE_IMAGE_PLACEHOLDER = /"%reference[-_]image%"/i;
11451145let pendingReferenceImage = null;
11461146
11471147/**
1148+ * Whether the current generation may run an LLM reference-image selection.
1149+ * Swipes reuse the prompt, so they must also reuse the reference selection
1150+ * instead of asking the LLM again.
1151+ */
1152+let referenceSelectionAllowed = true;
1153+
1154+/**
11481155 * Returns library entries that have an uploaded image.
11491156 * @returns {{tag: string, description: string, path: string}[]} Valid reference images.
11501157 */
@@ -1414,6 +1421,13 @@ async function resolveReferenceImageForGeneration(prompt) {
14141421 pendingReferenceImage = images[0];
14151422 return pendingReferenceImage;
14161423 }
1424+ if (!referenceSelectionAllowed) {
1425+ // Swipe without a stored selection (e.g. after a page reload): don't ask
1426+ // the LLM again, just fall back to the first library image.
1427+ console.log('SD: swipe regeneration - reusing the reference image without a new LLM selection');
1428+ pendingReferenceImage = images[0];
1429+ return pendingReferenceImage;
1430+ }
14171431 try {
14181432 pendingReferenceImage = await selectReferenceImageWithLlm(prompt, images) ?? images[0];
14191433 } catch (error) {
@@ -4241,6 +4255,10 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP
42414255 const isCharChat = this_chid !== undefined && !selected_group;
42424256 const ignoreNoCharForSwipe = initiator === initiators.swipe && isCharChat;
42434257
4258+ // Swipes reuse the existing prompt, so the reference-image selection must be
4259+ // reused as well - never re-run the LLM selection for a swipe.
4260+ referenceSelectionAllowed = initiator !== initiators.swipe;
4261+
42444262 const skipCharPrefix = !ignoreNoCharForSwipe && noCharPrefix.includes(generationType);
42454263
42464264 /**