mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-04-03 21:51:04 +02:00
Add SD character-prefixed free-mode
This commit is contained in:
parent
2e6ab8be46
commit
008ac9d47e
@ -58,6 +58,7 @@ const generationMode = {
|
|||||||
CHARACTER_MULTIMODAL: 8,
|
CHARACTER_MULTIMODAL: 8,
|
||||||
USER_MULTIMODAL: 9,
|
USER_MULTIMODAL: 9,
|
||||||
FACE_MULTIMODAL: 10,
|
FACE_MULTIMODAL: 10,
|
||||||
|
CHARACTER_FREE: 11,
|
||||||
};
|
};
|
||||||
|
|
||||||
const multimodalMap = {
|
const multimodalMap = {
|
||||||
@ -1563,6 +1564,10 @@ function getGenerationType(prompt) {
|
|||||||
mode = multimodalMap[mode];
|
mode = multimodalMap[mode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mode === generationMode.FREE && /^char\s/.test(prompt)) {
|
||||||
|
mode = generationMode.CHARACTER_FREE;
|
||||||
|
}
|
||||||
|
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1718,6 +1723,9 @@ async function getPrompt(generationType, message, trigger, quietPrompt) {
|
|||||||
case generationMode.USER_MULTIMODAL:
|
case generationMode.USER_MULTIMODAL:
|
||||||
prompt = await generateMultimodalPrompt(generationType, quietPrompt);
|
prompt = await generateMultimodalPrompt(generationType, quietPrompt);
|
||||||
break;
|
break;
|
||||||
|
case generationMode.CHARACTER_FREE:
|
||||||
|
prompt = generateFreeCharacterPrompt(trigger);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
prompt = await generatePrompt(quietPrompt);
|
prompt = await generatePrompt(quietPrompt);
|
||||||
break;
|
break;
|
||||||
@ -1730,6 +1738,41 @@ async function getPrompt(generationType, message, trigger, quietPrompt) {
|
|||||||
return prompt;
|
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.
|
* Generates a prompt using multimodal captioning.
|
||||||
* @param {number} generationType - The type of image generation to perform.
|
* @param {number} generationType - The type of image generation to perform.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user