Skip to content

Commit bc5e50e

Browse files
authored
Merge pull request elizaOS#839 from tsubasakong/main
feat: Add Custom System Prompt Support for plugin-image-generation
2 parents 911984a + b629d75 commit bc5e50e

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

packages/core/src/generation.ts

+3
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ export async function generateText({
5555
context,
5656
modelClass,
5757
stop,
58+
customSystemPrompt,
5859
}: {
5960
runtime: IAgentRuntime;
6061
context: string;
6162
modelClass: string;
6263
stop?: string[];
64+
customSystemPrompt?: string;
6365
}): Promise<string> {
6466
if (!context) {
6567
console.error("generateText context is empty");
@@ -456,6 +458,7 @@ export async function generateText({
456458
model: heurist.languageModel(model),
457459
prompt: context,
458460
system:
461+
customSystemPrompt ??
459462
runtime.character.system ??
460463
settings.SYSTEM_PROMPT ??
461464
undefined,

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

+57-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { elizaLogger } from "@elizaos/core";
1+
import { elizaLogger, generateText } from "@elizaos/core";
22
import {
33
Action,
44
HandlerCallback,
55
IAgentRuntime,
66
Memory,
77
Plugin,
88
State,
9+
ModelClass
910
} from "@elizaos/core";
1011
import { generateImage } from "@elizaos/core";
11-
1212
import fs from "fs";
1313
import path from "path";
1414
import { validateImageGenConfig } from "./environment";
@@ -122,14 +122,65 @@ const imageGeneration: Action = {
122122
const userId = runtime.agentId;
123123
elizaLogger.log("User ID:", userId);
124124

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.
127153
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);
128181
const imageSettings = runtime.character?.settings?.imageSettings || {};
129182
elizaLogger.log("Image settings:", imageSettings);
130183

131-
// TODO: Generate a prompt for the image
132-
133184
const res: { image: string; caption: string }[] = [];
134185

135186
elizaLogger.log("Generating image with prompt:", imagePrompt);

0 commit comments

Comments
 (0)