Skip to content

Commit 2deb3a0

Browse files
author
Tom Daniel
committed
make image generation prompt a config
1 parent 5d70650 commit 2deb3a0

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

.env.example

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ POST_INTERVAL_MAX= #180 #Default
3838
#USE IMAGE GEN
3939
IMAGE_GEN= #TRUE
4040

41+
#Generation Prompts
42+
SYSTEM_PROMPT= #Leave blank for empty system prompt or defined in character config
43+
IMAGE_GENERATION_PROMPT= #Leave blank for default image generation prompt or defined in character config
44+
4145
#Leave blank to use local embeddings
4246
USE_OPENAI_EMBEDDING= #TRUE
4347

packages/core/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ export type Character = {
332332
id?: UUID; // optional UUID which can be passed down to identify the character
333333
name: string;
334334
system?: string;
335+
imageGenerationPrompt?: string;
335336
modelProvider: ModelProviderName;
336337
imageModelProvider?: ModelProviderName;
337338
modelEndpointOverride?: string;

packages/plugin-image-generation/src/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Plugin,
1111
State,
1212
} from "@ai16z/eliza";
13-
import { generateCaption, generateImage } from "@ai16z/eliza";
13+
import { generateCaption, generateImage, settings } from "@ai16z/eliza";
1414

1515
import fs from "fs";
1616
import path from "path";
@@ -31,6 +31,8 @@ About {{agentName}}:
3131
Write a two sentence image description that considers the <user_message> and may also include {{adjective}} about {{topic}} (without mentioning {{topic}} directly), from the perspective of {{agentName}}. Try to write something totally different than previous posts. Do not add commentary or acknowledge this request, just write the description of the image to be generated.
3232
Your response should not contain any questions. Brief, concise statements only. No emojis. Use \\n\\n (double spaces) between statements.`;
3333

34+
const imageGenerationPrompt = "You are an AI assistant specialized in crafting effective prompts for image generation. Your task is to analyze a user's message and create a comprehensive, natural-language prompt that will guide an image generation algorithm to produce high-quality, visually appealing images.\n\nBegin by analyzing the content of the user's message. Follow these steps:\n\n1. List out key elements from the user's message, categorizing them to ensure comprehensive coverage:\n * Topic: The main subject or scene with specific details\n * Material: The medium or style (e.g., digital painting, 3D render)\n * Style: The artistic direction (e.g., fantasy, vaporwave)\n * Artist: Specific artists to influence the visual style\n * Webpage Influence: Art platforms like ArtStation or DeviantArt for quality enhancement\n * Sharpness: Terms like \"sharp focus\" or \"highly detailed\" for clarity\n * Extra Details: Descriptors to enhance atmosphere (e.g., cinematic, dystopian)\n * Shade and Color: Color-related keywords to control mood (e.g., moody lighting)\n * Lighting and Brightness: Specific lighting styles (e.g., dramatic shadows)\n * Camera Angle: Perspective and framing (e.g., close-up, wide shot, aerial view)\n * Composition: Layout guidance (e.g., rule of thirds, centered, dynamic)\n * Time Period: Temporal context if relevant\n * Cultural Elements: Any specific cultural influences\n * Textures: Surface quality descriptions\n * Weather/Atmosphere: Environmental conditions if applicable\n * Negative Prompts: Elements to exclude from the image\n\n2. Brainstorm complementary elements that would enhance the user's vision:\n * Suggest fitting artists and styles if not specified\n * Consider atmospheric elements that would strengthen the concept\n * Identify potential technical aspects that would improve the result\n * Note any elements that should be avoided to maintain the desired look\n\n3. Construct your final prompt by:\n * Leading with the most important scene/subject details from the user's message\n * Incorporating all relevant technical and stylistic elements\n * Grouping related concepts together naturally\n * Maintaining clear, flowing language throughout\n * Adding complementary details that enhance but don't alter the core concept\n * Concluding with negative prompts separated by a \"Negative:\" marker\n\nRemember:\n- Preserve ALL specific details from the user's original message\n- Don't force details into a rigid template\n- Create a cohesive, readable description\n- Keep the focus on the user's core concept while enhancing it with technical and artistic refinements\n\nYour output should contain ONLY the final prompt text, with no additional explanations, tags, or formatting.";
35+
3436
export function saveBase64Image(base64Data: string, filename: string): string {
3537
// Create generatedImages directory if it doesn't exist
3638
const imageDir = path.join(process.cwd(), "generatedImages");
@@ -119,7 +121,7 @@ const imageGeneration: Action = {
119121

120122
const agentImagePrompt = await generateText({
121123
runtime,
122-
context: `${agentContext}\n\n<user message>${message.content.text}</user message>`,
124+
context: `${agentContext}\n\n<user_message>${message.content.text}</user_message>`,
123125
modelClass: ModelClass.SMALL,
124126
});
125127

@@ -130,7 +132,8 @@ const imageGeneration: Action = {
130132
const userId = runtime.agentId;
131133
elizaLogger.log("User ID:", userId);
132134

133-
const context = `You are an AI assistant specialized in crafting effective prompts for image generation. Your task is to analyze a user's message and create a comprehensive, natural-language prompt that will guide an image generation algorithm to produce high-quality, visually appealing images.\n\nHere is the user's message:\n<user_message> ${agentImagePrompt} </user_message>\n\nBegin by analyzing the content of the user's message. Follow these steps:\n\n1. List out key elements from the user's message, categorizing them to ensure comprehensive coverage:\n * Topic: The main subject or scene with specific details\n * Material: The medium or style (e.g., digital painting, 3D render)\n * Style: The artistic direction (e.g., fantasy, vaporwave)\n * Artist: Specific artists to influence the visual style\n * Webpage Influence: Art platforms like ArtStation or DeviantArt for quality enhancement\n * Sharpness: Terms like "sharp focus" or "highly detailed" for clarity\n * Extra Details: Descriptors to enhance atmosphere (e.g., cinematic, dystopian)\n * Shade and Color: Color-related keywords to control mood (e.g., moody lighting)\n * Lighting and Brightness: Specific lighting styles (e.g., dramatic shadows)\n * Camera Angle: Perspective and framing (e.g., close-up, wide shot, aerial view)\n * Composition: Layout guidance (e.g., rule of thirds, centered, dynamic)\n * Time Period: Temporal context if relevant\n * Cultural Elements: Any specific cultural influences\n * Textures: Surface quality descriptions\n * Weather/Atmosphere: Environmental conditions if applicable\n * Negative Prompts: Elements to exclude from the image\n\n2. Brainstorm complementary elements that would enhance the user's vision:\n * Suggest fitting artists and styles if not specified\n * Consider atmospheric elements that would strengthen the concept\n * Identify potential technical aspects that would improve the result\n * Note any elements that should be avoided to maintain the desired look\n\n3. Construct your final prompt by:\n * Leading with the most important scene/subject details from the user's message\n * Incorporating all relevant technical and stylistic elements\n * Grouping related concepts together naturally\n * Maintaining clear, flowing language throughout\n * Adding complementary details that enhance but don't alter the core concept\n * Concluding with negative prompts separated by a "Negative:" marker\n\nRemember:\n- Preserve ALL specific details from the user's original message\n- Don't force details into a rigid template\n- Create a cohesive, readable description\n- Keep the focus on the user's core concept while enhancing it with technical and artistic refinements\n\nYour output should contain ONLY the final prompt text, with no additional explanations, tags, or formatting.`;
135+
const context = runtime.character.system ??
136+
settings.SYSTEM_PROMPT ?? imageGenerationPrompt + `\n\nHere is the user's message:\n<user_message> ${agentImagePrompt} </user_message>`;
134137

135138
const imagePrompt = await generateText({
136139
runtime,

0 commit comments

Comments
 (0)