ImageGen: Add a placeholder for {{prefixedPrompt}} in the message template

Closes #2946
This commit is contained in:
Cohee 2024-10-09 03:44:22 +03:00
parent de57123e62
commit 10f51f5d90

View File

@ -2309,14 +2309,14 @@ async function generatePicture(initiator, args, trigger, message, callback) {
if (generationType == generationMode.BACKGROUND) { if (generationType == generationMode.BACKGROUND) {
const callbackOriginal = callback; const callbackOriginal = callback;
callback = async function (prompt, imagePath, generationType) { callback = async function (prompt, imagePath, generationType, _negativePromptPrefix, _initiator, prefixedPrompt) {
const imgUrl = `url("${encodeURI(imagePath)}")`; const imgUrl = `url("${encodeURI(imagePath)}")`;
eventSource.emit(event_types.FORCE_SET_BACKGROUND, { url: imgUrl, path: imagePath }); eventSource.emit(event_types.FORCE_SET_BACKGROUND, { url: imgUrl, path: imagePath });
if (typeof callbackOriginal === 'function') { if (typeof callbackOriginal === 'function') {
await callbackOriginal(prompt, imagePath, generationType, negativePromptPrefix, initiator); await callbackOriginal(prompt, imagePath, generationType, negativePromptPrefix, initiator, prefixedPrompt);
} else { } else {
await sendMessage(prompt, imagePath, generationType, negativePromptPrefix, initiator); await sendMessage(prompt, imagePath, generationType, negativePromptPrefix, initiator, prefixedPrompt);
} }
}; };
} }
@ -2646,8 +2646,8 @@ async function sendGenerationRequest(generationType, prompt, additionalNegativeP
const filename = `${characterName}_${humanizedDateTime()}`; const filename = `${characterName}_${humanizedDateTime()}`;
const base64Image = await saveBase64AsFile(result.data, characterName, filename, result.format); const base64Image = await saveBase64AsFile(result.data, characterName, filename, result.format);
callback callback
? await callback(prompt, base64Image, generationType, additionalNegativePrefix, initiator) ? await callback(prompt, base64Image, generationType, additionalNegativePrefix, initiator, prefixedPrompt)
: await sendMessage(prompt, base64Image, generationType, additionalNegativePrefix, initiator); : await sendMessage(prompt, base64Image, generationType, additionalNegativePrefix, initiator, prefixedPrompt);
return base64Image; return base64Image;
} }
@ -3435,12 +3435,13 @@ async function onComfyDeleteWorkflowClick() {
* @param {number} generationType Generation type of the image * @param {number} generationType Generation type of the image
* @param {string} additionalNegativePrefix Additional negative prompt used for the image generation * @param {string} additionalNegativePrefix Additional negative prompt used for the image generation
* @param {string} initiator The initiator of the image generation * @param {string} initiator The initiator of the image generation
* @param {string} prefixedPrompt Prompt with an attached specific prefix
*/ */
async function sendMessage(prompt, image, generationType, additionalNegativePrefix, initiator) { async function sendMessage(prompt, image, generationType, additionalNegativePrefix, initiator, prefixedPrompt) {
const context = getContext(); const context = getContext();
const name = context.groupId ? systemUserName : context.name2; const name = context.groupId ? systemUserName : context.name2;
const template = extension_settings.sd.prompts[generationMode.MESSAGE] || '{{prompt}}'; const template = extension_settings.sd.prompts[generationMode.MESSAGE] || '{{prompt}}';
const messageText = substituteParamsExtended(template, { char: name, prompt: prompt }); const messageText = substituteParamsExtended(template, { char: name, prompt: prompt, prefixedPrompt: prefixedPrompt });
const message = { const message = {
name: name, name: name,
is_user: false, is_user: false,