Normalize SD prompt strings

This commit is contained in:
Cohee 2024-07-13 12:20:13 +03:00
parent 31dbb5144e
commit 9f17097976
1 changed files with 6 additions and 0 deletions

View File

@ -2178,6 +2178,11 @@ function getQuietPrompt(mode, trigger) {
return stringFormat(extension_settings.sd.prompts[mode], trigger);
}
/**
* Sanitizes generated prompt for image generation.
* @param {string} str String to process
* @returns {string} Processed reply
*/
function processReply(str) {
if (!str) {
return '';
@ -2187,6 +2192,7 @@ function processReply(str) {
str = str.replaceAll('“', '');
str = str.replaceAll('.', ',');
str = str.replaceAll('\n', ', ');
str = str.normalize('NFD');
str = str.replace(/[^a-zA-Z0-9,:_(){}<>[\]\-']+/g, ' ');
str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one
str = str.trim();