|
1 |
| -import { elizaLogger } from "@elizaos/core"; |
| 1 | +import { elizaLogger, generateText } from "@elizaos/core"; |
2 | 2 | import {
|
3 | 3 | Action,
|
4 | 4 | HandlerCallback,
|
5 | 5 | IAgentRuntime,
|
6 | 6 | Memory,
|
7 | 7 | Plugin,
|
8 | 8 | State,
|
| 9 | + ModelClass |
9 | 10 | } from "@elizaos/core";
|
10 | 11 | import { generateImage } from "@elizaos/core";
|
11 |
| - |
12 | 12 | import fs from "fs";
|
13 | 13 | import path from "path";
|
14 | 14 | import { validateImageGenConfig } from "./environment";
|
@@ -122,14 +122,65 @@ const imageGeneration: Action = {
|
122 | 122 | const userId = runtime.agentId;
|
123 | 123 | elizaLogger.log("User ID:", userId);
|
124 | 124 |
|
125 |
| - const imagePrompt = message.content.text; |
126 |
| - elizaLogger.log("Image prompt received:", imagePrompt); |
| 125 | + const CONTENT = message.content.text; |
| 126 | + const IMAGE_SYSTEM_PROMPT = `You are an expert in writing prompts for AI art generation. You excel at creating detailed and creative visual descriptions. Incorporating specific elements naturally. Always aim for clear, descriptive language that generates a creative picture. Your output should only contain the description of the image contents, but NOT an instruction like "create an image that..."`; |
| 127 | + const STYLE = "futuristic with vibrant colors"; |
| 128 | + |
| 129 | + const IMAGE_PROMPT_INPUT = `You are tasked with generating an image prompt based on a content and a specified style. |
| 130 | + Your goal is to create a detailed and vivid image prompt that captures the essence of the content while incorporating an appropriate subject based on your analysis of the content.\n\nYou will be given the following inputs:\n<content>\n${CONTENT}\n</content>\n\n<style>\n${STYLE}\n</style>\n\nA good image prompt consists of the following elements:\n\n |
| 131 | +
|
| 132 | +1. Main subject |
| 133 | +2. Detailed description |
| 134 | +3. Style |
| 135 | +4. Lighting |
| 136 | +5. Composition |
| 137 | +6. Quality modifiers |
| 138 | +
|
| 139 | +To generate the image prompt, follow these steps:\n\n1. Analyze the content text carefully, identifying key themes, emotions, and visual elements mentioned or implied. |
| 140 | +\n\n |
| 141 | +
|
| 142 | +2. Determine the most appropriate main subject by: |
| 143 | + - Identifying concrete objects or persons mentioned in the content |
| 144 | + - Analyzing the central theme or message |
| 145 | + - Considering metaphorical representations of abstract concepts |
| 146 | + - Selecting a subject that best captures the content's essence |
| 147 | +
|
| 148 | +3. Determine an appropriate environment or setting based on the content's context and your chosen subject. |
| 149 | +
|
| 150 | +4. Decide on suitable lighting that enhances the mood or atmosphere of the scene. |
| 151 | +
|
| 152 | +5. Choose a color palette that reflects the content's tone and complements the subject. |
127 | 153 |
|
| 154 | +6. Identify the overall mood or emotion conveyed by the content. |
| 155 | +
|
| 156 | +7. Plan a composition that effectively showcases the subject and captures the content's essence. |
| 157 | +
|
| 158 | +8. Incorporate the specified style into your description, considering how it affects the overall look and feel of the image. |
| 159 | +
|
| 160 | +9. Use concrete nouns and avoid abstract concepts when describing the main subject and elements of the scene. |
| 161 | +
|
| 162 | +Construct your image prompt using the following structure:\n\n |
| 163 | +1. Main subject: Describe the primary focus of the image based on your analysis |
| 164 | +2. Environment: Detail the setting or background |
| 165 | +3. Lighting: Specify the type and quality of light in the scene |
| 166 | +4. Colors: Mention the key colors and their relationships |
| 167 | +5. Mood: Convey the overall emotional tone |
| 168 | +6. Composition: Describe how elements are arranged in the frame |
| 169 | +7. Style: Incorporate the given style into the description |
| 170 | +
|
| 171 | +Ensure that your prompt is detailed, vivid, and incorporates all the elements mentioned above while staying true to the content and the specified style. LIMIT the image prompt 50 words or less. \n\nWrite a prompt. Only include the prompt and nothing else.`; |
| 172 | + |
| 173 | + const imagePrompt = await generateText({ |
| 174 | + runtime, |
| 175 | + context: IMAGE_PROMPT_INPUT, |
| 176 | + modelClass: ModelClass.MEDIUM, |
| 177 | + customSystemPrompt: IMAGE_SYSTEM_PROMPT, |
| 178 | + }); |
| 179 | + |
| 180 | + elizaLogger.log("Image prompt received:", imagePrompt); |
128 | 181 | const imageSettings = runtime.character?.settings?.imageSettings || {};
|
129 | 182 | elizaLogger.log("Image settings:", imageSettings);
|
130 | 183 |
|
131 |
| - // TODO: Generate a prompt for the image |
132 |
| - |
133 | 184 | const res: { image: string; caption: string }[] = [];
|
134 | 185 |
|
135 | 186 | elizaLogger.log("Generating image with prompt:", imagePrompt);
|
|
0 commit comments