Normalize SD prompt strings
| @@ -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 | } |
| 2180 | 2180 | ||
| 2181 | /** | ||
| 2182 | * Sanitizes generated prompt for image generation. | ||
| 2183 | * @param {string} str String to process | ||
| 2184 | * @returns {string} Processed reply | ||
| 2185 | */ | ||
| 2181 | function processReply(str) { | 2186 | function 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 one | 2197 | str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one |
| 2192 | str = str.trim(); | 2198 | str = str.trim(); |