Skip to content

Commit 85d37f1

Browse files
authored
refactor: condense dall-e instructions, add style parameter (danny-avila#1148)
1 parent f7a9a74 commit 85d37f1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

api/app/clients/tools/structured/DALLE3.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ class DALLE3 extends Tool {
1515
let config = { apiKey };
1616
this.openai = new OpenAI(config);
1717
this.name = 'dalle';
18-
this.description = `Use DALLE to create images from text descriptions:
19-
.
20-
- Ensure prompts are detailed and specify the image type and size.
21-
- Describe human features explicitly to promote diversity without bias.`;
18+
this.description = `Use DALLE to create images from text descriptions.
19+
- It requires prompts to be in English, detailed, and to specify image type and human features for diversity.
20+
- Only one image is produced per call, without repeating or listing descriptions outside the "prompts" field.
21+
- Maintains the original intent of the description, with parameters for image style, quality, and size to tailor the output.`;
2222
this.description_for_model = `// Whenever a description of an image is given, generate prompts (following these rules), and use dalle to create the image. If the user does not ask for a specific number of images, default to creating 2 prompts to send to dalle that are written to be as diverse as possible. All prompts sent to dalle must abide by the following policies:
2323
// 1. Prompts must be in English. Translate to English if needed.
2424
// 2. Only one image can be created per function call.
@@ -29,8 +29,6 @@ class DALLE3 extends Tool {
2929
// - Your choices should be grounded in reality. For example, all of a given OCCUPATION should not be the same gender or race. Additionally, focus on creating diverse, inclusive, and exploratory scenes via the properties you choose during rewrites. Make choices that may be insightful or unique sometimes.
3030
// - Use "various" or "diverse" ONLY IF the description refers to groups of more than 3 people. Do not change the number of people requested in the original description.
3131
// - Don't alter memes, fictional character origins, or unseen people. Maintain the original prompt's intent and prioritize quality.
32-
// - Do not create any imagery that would be offensive.
33-
// - For scenarios where bias has been traditionally an issue, make sure that key traits such as gender and race are specified and in an unbiased way -- for example, prompts that contain references to specific occupations.
3432
// The prompt must intricately describe every part of the image in concrete, objective detail. THINK about what the end goal of the description is, and extrapolate that to what would make satisfying images.
3533
// All descriptions sent to dalle should be a paragraph of text that is extremely descriptive and detailed. Each should be more than 3 sentences long.`;
3634
this.schema = z.object({
@@ -40,6 +38,11 @@ class DALLE3 extends Tool {
4038
.describe(
4139
'A text description of the desired image, following the rules, up to 4000 characters.',
4240
),
41+
style: z
42+
.enum(['vivid', 'natural'])
43+
.describe(
44+
'Must be one of `vivid` or `natural`. `vivid` generates hyper-real and dramatic images, `natural` produces more natural, less hyper-real looking images',
45+
),
4346
quality: z
4447
.enum(['hd', 'standard'])
4548
.describe('The quality of the generated image. Only `hd` and `standard` are supported.'),
@@ -75,13 +78,14 @@ class DALLE3 extends Tool {
7578
}
7679

7780
async _call(data) {
78-
const { prompt, quality = 'standard', size = '1024x1024' } = data;
81+
const { prompt, quality = 'standard', size = '1024x1024', style = 'vivid' } = data;
7982
if (!prompt) {
8083
throw new Error('Missing required field: prompt');
8184
}
8285
const resp = await this.openai.images.generate({
8386
model: 'dall-e-3',
8487
quality,
88+
style,
8589
size,
8690
prompt: this.replaceUnwantedChars(prompt),
8791
n: 1,

0 commit comments

Comments
 (0)