ImageGen: Configurable tool prompt description, encode response URI

303df1087adfcc07fc259d10cdcf3c9dc3492b69

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

1 files changed, +13 -6Ignore whitespace
public/scripts/extensions/stable-diffusion/index.js+13 -6
@@ -67,6 +67,7 @@ const initiators = {
67};67};
6868
69const generationMode = {69const generationMode = {
70 TOOL: -2,
70 MESSAGE: -1,71 MESSAGE: -1,
71 CHARACTER: 0,72 CHARACTER: 0,
72 USER: 1,73 USER: 1,
@@ -89,6 +90,7 @@ const multimodalMap = {
89};90};
9091
91const modeLabels = {92const modeLabels = {
93 [generationMode.TOOL]: 'Function Tool Prompt Description',
92 [generationMode.MESSAGE]: 'Chat Message Template',94 [generationMode.MESSAGE]: 'Chat Message Template',
93 [generationMode.CHARACTER]: 'Character ("Yourself")',95 [generationMode.CHARACTER]: 'Character ("Yourself")',
94 [generationMode.FACE]: 'Portrait ("Your Face")',96 [generationMode.FACE]: 'Portrait ("Your Face")',
@@ -126,8 +128,12 @@ const messageTrigger = {
126};128};
127129
128const promptTemplates = {130const promptTemplates = {
129 // Not really a prompt template, rather an outcome message template131 // Not really a prompt template, rather an outcome message template and function tool prompt
130 [generationMode.MESSAGE]: '[{{char}} sends a picture that contains: {{prompt}}].',132 [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(' '),
131 [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,\'',137 [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,\'',
132 //face-specific prompt138 //face-specific prompt
133 [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,\'',139 [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() {
533 .on('click', () => {539 .on('click', () => {
534 textarea.val(promptTemplates[name]);540 textarea.val(promptTemplates[name]);
535 extension_settings.sd.prompts[name] = promptTemplates[name];541 extension_settings.sd.prompts[name] = promptTemplates[name];
542 if (String(name) === String(generationMode.TOOL)) {
543 registerFunctionTool();
544 }
536 saveSettingsDebounced();545 saveSettingsDebounced();
537 });546 });
538 const container = $('<div></div>')547 const container = $('<div></div>')
@@ -3857,10 +3866,7 @@ function registerFunctionTool() {
3857 properties: {3866 properties: {
3858 prompt: {3867 prompt: {
3859 type: 'string',3868 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(' '),
3864 },3870 },
3865 },3871 },
3866 required: [3872 required: [
@@ -3871,7 +3877,8 @@ function registerFunctionTool() {
3871 if (!isValidState()) throw new Error('Image generation is not configured.');3877 if (!isValidState()) throw new Error('Image generation is not configured.');
3872 if (!args) throw new Error('Missing arguments');3878 if (!args) throw new Error('Missing arguments');
3873 if (!args.prompt) throw new Error('Missing prompt');3879 if (!args.prompt) throw new Error('Missing prompt');
3874 return generatePicture(initiators.tool, {}, args.prompt);3880 const url = await generatePicture(initiators.tool, {}, args.prompt);
3881 return encodeURI(url);
3875 },3882 },
3876 formatMessage: () => 'Generating an image...',3883 formatMessage: () => 'Generating an image...',
3877 });3884 });