ImageGen: Configurable tool prompt description, encode response URI

303df1087adfcc07fc259d10cdcf3c9dc3492b69

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +13 -6Showing whitespace changes
public/scripts/extensions/stable-diffusion/index.js+13 -6
@@ -67,6 +67,7 @@ const initiators = {
6767};
6868
6969const generationMode = {
70+ TOOL: -2,
7071 MESSAGE: -1,
7172 CHARACTER: 0,
7273 USER: 1,
@@ -89,6 +90,7 @@ const multimodalMap = {
8990};
9091
9192const modeLabels = {
93+ [generationMode.TOOL]: 'Function Tool Prompt Description',
9294 [generationMode.MESSAGE]: 'Chat Message Template',
9395 [generationMode.CHARACTER]: 'Character ("Yourself")',
9496 [generationMode.FACE]: 'Portrait ("Your Face")',
@@ -126,8 +128,12 @@ const messageTrigger = {
126128};
127129
128130const promptTemplates = {
129131 // Not really a prompt template, rather an outcome message template and function tool prompt
130132 [generationMode.MESSAGE]: '[{{char}} sends a picture that contains: {{prompt}}].',
133+ [generationMode.TOOL]: [
134+ 'The text prompt used to generate the image.',
135+ 'Must represent an exhaustive description of the desired image that will allow an artist or a photographer to perfectly recreate it.',
136+ ].join(' '),
131137 [generationMode.CHARACTER]: 'In the next response I want you to provide only a detailed comma-delimited list of keywords and phrases which describe {{char}}. The list must include all of the following items in this order: name, species and race, gender, age, clothing, occupation, physical features and appearances. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase \'full body portrait,\'',
132138 //face-specific prompt
133139 [generationMode.FACE]: 'In the next response I want you to provide only a detailed comma-delimited list of keywords and phrases which describe {{char}}. The list must include all of the following items in this order: name, species and race, gender, age, facial features and expressions, occupation, hair and hair accessories (if any), what they are wearing on their upper body (if anything). Do not describe anything below their neck. Do not include descriptions of non-visual qualities such as personality, movements, scents, mental traits, or anything which could not be seen in a still photograph. Do not write in full sentences. Prefix your description with the phrase \'close up facial portrait,\'',
@@ -533,6 +539,9 @@ function addPromptTemplates() {
533539 .on('click', () => {
534540 textarea.val(promptTemplates[name]);
535541 extension_settings.sd.prompts[name] = promptTemplates[name];
542+ if (String(name) === String(generationMode.TOOL)) {
543+ registerFunctionTool();
544+ }
536545 saveSettingsDebounced();
537546 });
538547 const container = $('<div></div>')
@@ -3857,10 +3866,7 @@ function registerFunctionTool() {
38573866 properties: {
38583867 prompt: {
38593868 type: 'string',
3860- description: [
3869+ description: extension_settings.sd.prompts[generationMode.TOOL] || promptTemplates[generationMode.TOOL],
3861- 'The text prompt used to generate the image.',
3862- 'Must represent an exhaustive description of the desired image that will allow an artist or a photographer to perfectly recreate it.',
3863- ].join(' '),
38643870 },
38653871 },
38663872 required: [
@@ -3871,7 +3877,8 @@ function registerFunctionTool() {
38713877 if (!isValidState()) throw new Error('Image generation is not configured.');
38723878 if (!args) throw new Error('Missing arguments');
38733879 if (!args.prompt) throw new Error('Missing prompt');
38743880 returnconst url = await generatePicture(initiators.tool, {}, args.prompt);
3881+ return encodeURI(url);
38753882 },
38763883 formatMessage: () => 'Generating an image...',
38773884 });