Fix SD prompt generation

This commit is contained in:
SillyLossy
2023-05-13 21:36:40 +03:00
parent 6c2a52dfff
commit 36803cf473
2 changed files with 14 additions and 8 deletions

View File

@ -1994,6 +1994,13 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
const isBottom = j === mesSend.length - 1; const isBottom = j === mesSend.length - 1;
mesSendString += mesSend[j]; mesSendString += mesSend[j];
// Add quiet generation prompt at depth 0
if (isBottom && quiet_prompt && quiet_prompt.length) {
const name = is_pygmalion ? 'You' : name1;
const quietAppend = isInstruct ? formatInstructModeChat(name, quiet_prompt, true) : `\n${name}: ${quiet_prompt}`;
mesSendString += quietAppend;
}
if (isInstruct && isBottom && tokens_already_generated === 0) { if (isInstruct && isBottom && tokens_already_generated === 0) {
const name = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2; const name = isImpersonate ? (is_pygmalion ? 'You' : name1) : name2;
mesSendString += formatInstructModePrompt(name, isImpersonate); mesSendString += formatInstructModePrompt(name, isImpersonate);
@ -2149,11 +2156,6 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject,
} }
} }
// Add quiet generation prompt at depth 0
if (quiet_prompt && quiet_prompt.length) {
finalPromt += `\n${quiet_prompt}`;
}
finalPromt = finalPromt.replace(/\r/gm, ''); finalPromt = finalPromt.replace(/\r/gm, '');
if (power_user.collapse_newlines) { if (power_user.collapse_newlines) {

View File

@ -237,7 +237,9 @@ function getQuietPrompt(mode, trigger) {
function processReply(str) { function processReply(str) {
str = str.replaceAll('"', '') str = str.replaceAll('"', '')
str = str.replaceAll('“', '') str = str.replaceAll('“', '')
str = str.replaceAll('\n', ' ') str = str.replaceAll('\n', ', ')
str = str.replace(/[^a-zA-Z0-9,:]+/g, ' ') // Replace everything except alphanumeric characters and commas with spaces
str = str.replace(/\s+/g, ' '); // Collapse multiple whitespaces into one
str = str.trim(); str = str.trim();
return str; return str;
@ -259,7 +261,7 @@ async function generatePicture(_, trigger) {
const prompt = processReply(await new Promise( const prompt = processReply(await new Promise(
async function promptPromise(resolve, reject) { async function promptPromise(resolve, reject) {
try { try {
await context.generate('quiet', { resolve, reject, quiet_prompt }); await context.generate('quiet', { resolve, reject, quiet_prompt, force_name2: true, });
} }
catch { catch {
reject(); reject();
@ -269,6 +271,8 @@ async function generatePicture(_, trigger) {
context.deactivateSendButtons(); context.deactivateSendButtons();
hideSwipeButtons(); hideSwipeButtons();
console.log('Processed Stable Diffusion prompt:', prompt);
const url = new URL(getApiUrl()); const url = new URL(getApiUrl());
url.pathname = '/api/image'; url.pathname = '/api/image';
const result = await fetch(url, { const result = await fetch(url, {
@ -295,7 +299,7 @@ async function generatePicture(_, trigger) {
sendMessage(prompt, base64Image); sendMessage(prompt, base64Image);
} }
} catch (err) { } catch (err) {
console.error(err); console.trace(err);
throw new Error('SD prompt text generation failed.') throw new Error('SD prompt text generation failed.')
} }
finally { finally {