Add Extension Hook for Stable Diffusion Prompt Processing (#4167) * Update index.js * Update index.js * Update script.js * Use a named constant in event emit --------- Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -496,6 +496,7 @@ export const event_types = { | ||
| 496 | 496 | GENERATION_STARTED: 'generation_started', |
| 497 | 497 | GENERATION_STOPPED: 'generation_stopped', |
| 498 | 498 | GENERATION_ENDED: 'generation_ended', |
| 499 | + SD_PROMPT_PROCESSING: 'sd_prompt_processing', | |
| 499 | 500 | EXTENSIONS_FIRST_LOAD: 'extensions_first_load', |
| 500 | 501 | EXTENSION_SETTINGS_LOADED: 'extension_settings_loaded', |
| 501 | 502 | SETTINGS_LOADED: 'settings_loaded', |
| @@ -2468,9 +2468,14 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 2468 | 2468 | const combineNegatives = (prefix) => { negativePromptPrefix = combinePrefixes(negativePromptPrefix, prefix); }; |
| 2469 | 2469 | |
| 2470 | 2470 | // generate the text prompt for the image |
| 2471 | 2471 | constlet prompt = await getPrompt(generationType, message, trigger, quietPrompt, combineNegatives); |
| 2472 | 2472 | console.log('Processed image prompt:', prompt); |
| 2473 | 2473 | |
| 2474 | + // Extension hook for prompt processing | |
| 2475 | + const eventData = { prompt, generationType, message, trigger }; | |
| 2476 | + await eventSource.emit(event_types.SD_PROMPT_PROCESSING, eventData); | |
| 2477 | + prompt = eventData.prompt; // Allow extensions to modify the prompt | |
| 2478 | + | |
| 2474 | 2479 | $(stopButton).show(); |
| 2475 | 2480 | eventSource.once(CUSTOM_STOP_EVENT, stopListener); |
| 2476 | 2481 | |