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.
| @@ -1145,6 +1145,13 @@ const REFERENCE_IMAGE_PLACEHOLDER = /"%reference[-_]image%"/i; | ||
| 1145 | 1145 | let pendingReferenceImage = null; |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
| 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 | +/** | |
| 1148 | 1155 | * Returns library entries that have an uploaded image. |
| 1149 | 1156 | * @returns {{tag: string, description: string, path: string}[]} Valid reference images. |
| 1150 | 1157 | */ |
| @@ -1414,6 +1421,13 @@ async function resolveReferenceImageForGeneration(prompt) { | ||
| 1414 | 1421 | pendingReferenceImage = images[0]; |
| 1415 | 1422 | return pendingReferenceImage; |
| 1416 | 1423 | } |
| 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 | + } | |
| 1417 | 1431 | try { |
| 1418 | 1432 | pendingReferenceImage = await selectReferenceImageWithLlm(prompt, images) ?? images[0]; |
| 1419 | 1433 | } catch (error) { |
| @@ -4241,6 +4255,10 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP | ||
| 4241 | 4255 | const isCharChat = this_chid !== undefined && !selected_group; |
| 4242 | 4256 | const ignoreNoCharForSwipe = initiator === initiators.swipe && isCharChat; |
| 4243 | 4257 | |
| 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 | + | |
| 4244 | 4262 | const skipCharPrefix = !ignoreNoCharForSwipe && noCharPrefix.includes(generationType); |
| 4245 | 4263 | |
| 4246 | 4264 | /** |