From 008ac9d47e7b817f37dd0fd6d0ddce4917c19789 Mon Sep 17 00:00:00 2001 From: Deathspike Date: Fri, 15 Dec 2023 15:30:02 +0100 Subject: [PATCH 01/11] Add SD character-prefixed free-mode --- .../extensions/stable-diffusion/index.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index 9a57bcd8e..8e4305d6b 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -58,6 +58,7 @@ const generationMode = { CHARACTER_MULTIMODAL: 8, USER_MULTIMODAL: 9, FACE_MULTIMODAL: 10, + CHARACTER_FREE: 11, }; const multimodalMap = { @@ -1563,6 +1564,10 @@ function getGenerationType(prompt) { mode = multimodalMap[mode]; } + if (mode === generationMode.FREE && /^char\s/.test(prompt)) { + mode = generationMode.CHARACTER_FREE; + } + return mode; } @@ -1718,6 +1723,9 @@ async function getPrompt(generationType, message, trigger, quietPrompt) { case generationMode.USER_MULTIMODAL: prompt = await generateMultimodalPrompt(generationType, quietPrompt); break; + case generationMode.CHARACTER_FREE: + prompt = generateFreeCharacterPrompt(trigger); + break; default: prompt = await generatePrompt(quietPrompt); break; @@ -1730,6 +1738,41 @@ async function getPrompt(generationType, message, trigger, quietPrompt) { return prompt; } +/** + * Generates a free prompt with a character-specific prompt prefix. + * @param {string} trigger - The prompt to use for the image generation. + * @returns {string} + */ +function generateFreeCharacterPrompt(trigger) { + const context = getContext(); + + const getCharacterPrefix = () => { + const key = getLastCharacterKey(); + const value = (extension_settings.sd.character_prompts[key] || '').trim(); + return value ? value + ' ' : ''; + }; + + const getLastCharacterKey = () => { + if (typeof this_chid !== 'undefined') { + return getCharaFilename(this_chid); + } + for (let i = context.chat.length - 1; i >= 0; i--) { + const message = context.chat[i]; + if (context.is_user || message.is_system) { + continue; + } else if (typeof message.original_avatar === 'string') { + return message.original_avatar.replace(/\.[^/.]+$/, ''); + } + } + throw new Error('No usable messages found.'); + }; + + const prefix = getCharacterPrefix(); + const pieces = trigger.split(/\s+/g); + const prompt = pieces.slice(1).join(' '); + return (prefix + prompt).trim(); +} + /** * Generates a prompt using multimodal captioning. * @param {number} generationType - The type of image generation to perform. From 8aa18142876bff24ac7052a358a0e5c2c3ebd047 Mon Sep 17 00:00:00 2001 From: Deathspike Date: Fri, 15 Dec 2023 19:34:29 +0100 Subject: [PATCH 02/11] Fix SD character-prefixed free-mode user detection --- public/scripts/extensions/stable-diffusion/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index 8e4305d6b..751815f94 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -1758,7 +1758,7 @@ function generateFreeCharacterPrompt(trigger) { } for (let i = context.chat.length - 1; i >= 0; i--) { const message = context.chat[i]; - if (context.is_user || message.is_system) { + if (message.is_user || message.is_system) { continue; } else if (typeof message.original_avatar === 'string') { return message.original_avatar.replace(/\.[^/.]+$/, ''); From 9b9026b12e7464f05d0409bb20ee8882b78a4f61 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 16 Dec 2023 01:35:28 +0200 Subject: [PATCH 03/11] Add toggle for compact input area (mobile) --- public/css/mobile-styles.css | 4 ++++ public/index.html | 4 ++++ public/scripts/power-user.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/public/css/mobile-styles.css b/public/css/mobile-styles.css index d62534876..ebcd5eda2 100644 --- a/public/css/mobile-styles.css +++ b/public/css/mobile-styles.css @@ -1,5 +1,9 @@ /*will apply to anything 1000px or less. this catches ipads, horizontal phones, and vertical phones)*/ @media screen and (max-width: 1000px) { + #send_form.compact #leftSendForm, #send_form.compact #rightSendForm { + flex-wrap: nowrap; + width: unset; + } .bg_button { font-size: 15px; diff --git a/public/index.html b/public/index.html index b0d21d081..7456a65b5 100644 --- a/public/index.html +++ b/public/index.html @@ -2972,6 +2972,10 @@ Message Token Count +