Normalize SD prompt strings

9f170979767282de625d32659dfbb6bf0ea01a49

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +6 -0Showing whitespace changes
public/scripts/extensions/stable-diffusion/index.js+6 -0
@@ -2178,6 +2178,11 @@ function getQuietPrompt(mode, trigger) {
2178 return stringFormat(extension_settings.sd.prompts[mode], trigger);2178 return stringFormat(extension_settings.sd.prompts[mode], trigger);
2179}2179}
21802180
2181/**
2182 * Sanitizes generated prompt for image generation.
2183 * @param {string} str String to process
2184 * @returns {string} Processed reply
2185 */
2181function processReply(str) {2186function processReply(str) {
2182 if (!str) {2187 if (!str) {
2183 return '';2188 return '';
@@ -2187,6 +2192,7 @@ function processReply(str) {
2187 str = str.replaceAll('“', '');2192 str = str.replaceAll('“', '');
2188 str = str.replaceAll('.', ',');2193 str = str.replaceAll('.', ',');
2189 str = str.replaceAll('\n', ', ');2194 str = str.replaceAll('\n', ', ');
2195 str = str.normalize('NFD');
2190 str = str.replace(/[^a-zA-Z0-9,:_(){}<>[\]\-']+/g, ' ');2196 str = str.replace(/[^a-zA-Z0-9,:_(){}<>[\]\-']+/g, ' ');
2191 str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one2197 str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one
2192 str = str.trim();2198 str = str.trim();