Skip to content

Commit ef93928

Browse files
committed
feat(image-generator): add gpt-image-2 model support
1 parent ae20d1c commit ef93928

2 files changed

Lines changed: 111 additions & 11 deletions

File tree

apps/sim/blocks/blocks/image_generator.ts

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
88
description: 'Generate images',
99
authMode: AuthMode.ApiKey,
1010
longDescription:
11-
'Integrate Image Generator into the workflow. Can generate images using DALL-E 3 or GPT Image.',
11+
'Integrate Image Generator into the workflow. Can generate images using DALL-E 3, GPT Image 1, or GPT Image 2.',
1212
docsLink: 'https://docs.sim.ai/tools/image_generator',
1313
category: 'tools',
1414
integrationType: IntegrationType.AI,
@@ -22,7 +22,8 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
2222
type: 'dropdown',
2323
options: [
2424
{ label: 'DALL-E 3', id: 'dall-e-3' },
25-
{ label: 'GPT Image', id: 'gpt-image-1' },
25+
{ label: 'GPT Image 1', id: 'gpt-image-1' },
26+
{ label: 'GPT Image 2', id: 'gpt-image-2' },
2627
],
2728
value: () => 'dall-e-3',
2829
},
@@ -60,6 +61,22 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
6061
condition: { field: 'model', value: 'gpt-image-1' },
6162
dependsOn: ['model'],
6263
},
64+
{
65+
id: 'size',
66+
title: 'Size',
67+
type: 'dropdown',
68+
options: [
69+
{ label: 'Auto', id: 'auto' },
70+
{ label: '1024x1024 (Square)', id: '1024x1024' },
71+
{ label: '1536x1024 (Landscape)', id: '1536x1024' },
72+
{ label: '1024x1536 (Portrait)', id: '1024x1536' },
73+
{ label: '2048x2048 (2K Square)', id: '2048x2048' },
74+
{ label: '3840x2160 (4K Landscape)', id: '3840x2160' },
75+
],
76+
value: () => 'auto',
77+
condition: { field: 'model', value: 'gpt-image-2' },
78+
dependsOn: ['model'],
79+
},
6380
{
6481
id: 'quality',
6582
title: 'Quality',
@@ -72,6 +89,20 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
7289
condition: { field: 'model', value: 'dall-e-3' },
7390
dependsOn: ['model'],
7491
},
92+
{
93+
id: 'quality',
94+
title: 'Quality',
95+
type: 'dropdown',
96+
options: [
97+
{ label: 'Auto', id: 'auto' },
98+
{ label: 'Low', id: 'low' },
99+
{ label: 'Medium', id: 'medium' },
100+
{ label: 'High', id: 'high' },
101+
],
102+
value: () => 'auto',
103+
condition: { field: 'model', value: ['gpt-image-1', 'gpt-image-2'] },
104+
dependsOn: ['model'],
105+
},
75106
{
76107
id: 'style',
77108
title: 'Style',
@@ -97,6 +128,43 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
97128
condition: { field: 'model', value: 'gpt-image-1' },
98129
dependsOn: ['model'],
99130
},
131+
{
132+
id: 'background',
133+
title: 'Background',
134+
type: 'dropdown',
135+
options: [
136+
{ label: 'Auto', id: 'auto' },
137+
{ label: 'Opaque', id: 'opaque' },
138+
],
139+
value: () => 'auto',
140+
condition: { field: 'model', value: 'gpt-image-2' },
141+
dependsOn: ['model'],
142+
},
143+
{
144+
id: 'outputFormat',
145+
title: 'Output Format',
146+
type: 'dropdown',
147+
options: [
148+
{ label: 'PNG', id: 'png' },
149+
{ label: 'JPEG', id: 'jpeg' },
150+
{ label: 'WebP', id: 'webp' },
151+
],
152+
value: () => 'png',
153+
condition: { field: 'model', value: ['gpt-image-1', 'gpt-image-2'] },
154+
dependsOn: ['model'],
155+
},
156+
{
157+
id: 'moderation',
158+
title: 'Moderation',
159+
type: 'dropdown',
160+
options: [
161+
{ label: 'Auto', id: 'auto' },
162+
{ label: 'Low', id: 'low' },
163+
],
164+
value: () => 'auto',
165+
condition: { field: 'model', value: 'gpt-image-2' },
166+
dependsOn: ['model'],
167+
},
100168
{
101169
id: 'apiKey',
102170
title: 'API Key',
@@ -120,7 +188,7 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
120188
}
121189

122190
const model = params.model || 'dall-e-3'
123-
const size = params.size || (model === 'gpt-image-1' ? 'auto' : '1024x1024')
191+
const size = params.size || (model === 'dall-e-3' ? '1024x1024' : 'auto')
124192
const baseParams = {
125193
prompt: params.prompt,
126194
model,
@@ -138,7 +206,18 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
138206
if (model === 'gpt-image-1') {
139207
return {
140208
...baseParams,
209+
...(params.quality && { quality: params.quality }),
210+
...(params.background && { background: params.background }),
211+
...(params.outputFormat && { outputFormat: params.outputFormat }),
212+
}
213+
}
214+
if (model === 'gpt-image-2') {
215+
return {
216+
...baseParams,
217+
...(params.quality && { quality: params.quality }),
141218
...(params.background && { background: params.background }),
219+
...(params.outputFormat && { outputFormat: params.outputFormat }),
220+
...(params.moderation && { moderation: params.moderation }),
142221
}
143222
}
144223

@@ -153,6 +232,8 @@ export const ImageGeneratorBlock: BlockConfig<DalleResponse> = {
153232
quality: { type: 'string', description: 'Image quality level' },
154233
style: { type: 'string', description: 'Image style' },
155234
background: { type: 'string', description: 'Background type' },
235+
outputFormat: { type: 'string', description: 'Output image format (png, jpeg, webp)' },
236+
moderation: { type: 'string', description: 'Moderation level (auto or low)' },
156237
apiKey: { type: 'string', description: 'OpenAI API key' },
157238
},
158239
outputs: {

apps/sim/tools/openai/image.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const imageTool: ToolConfig = {
1616
type: 'string',
1717
required: true,
1818
visibility: 'user-only',
19-
description: 'The model to use (gpt-image-1 or dall-e-3)',
19+
description: 'The model to use (dall-e-3, gpt-image-1, or gpt-image-2)',
2020
},
2121
prompt: {
2222
type: 'string',
@@ -28,25 +28,39 @@ export const imageTool: ToolConfig = {
2828
type: 'string',
2929
required: true,
3030
visibility: 'user-or-llm',
31-
description: 'The size of the generated images (1024x1024, 1024x1792, or 1792x1024)',
31+
description:
32+
'Image size. dall-e-3: 1024x1024, 1024x1792, or 1792x1024. gpt-image-1: auto, 1024x1024, 1536x1024, or 1024x1536. gpt-image-2: auto or any size with edges ≤3840px and multiples of 16 (e.g. 1024x1024, 1536x1024, 1024x1536, 2048x2048, 3840x2160).',
3233
},
3334
quality: {
3435
type: 'string',
3536
required: false,
3637
visibility: 'user-or-llm',
37-
description: 'The quality of the image (standard or hd)',
38+
description: 'Quality. dall-e-3: standard|hd. gpt-image-1/gpt-image-2: auto|low|medium|high',
3839
},
3940
style: {
4041
type: 'string',
4142
required: false,
4243
visibility: 'user-or-llm',
43-
description: 'The style of the image (vivid or natural)',
44+
description: 'The style of the image (vivid or natural), only for dall-e-3',
4445
},
4546
background: {
4647
type: 'string',
4748
required: false,
4849
visibility: 'user-or-llm',
49-
description: 'The background color, only for gpt-image-1',
50+
description:
51+
'Background. gpt-image-1: auto|transparent|opaque. gpt-image-2: auto|opaque (transparent not supported)',
52+
},
53+
outputFormat: {
54+
type: 'string',
55+
required: false,
56+
visibility: 'user-or-llm',
57+
description: 'Output image format (png, jpeg, webp), only for gpt-image-1 and gpt-image-2',
58+
},
59+
moderation: {
60+
type: 'string',
61+
required: false,
62+
visibility: 'user-or-llm',
63+
description: 'Moderation level (auto or low), only for gpt-image-2',
5064
},
5165
n: {
5266
type: 'number',
@@ -73,15 +87,20 @@ export const imageTool: ToolConfig = {
7387
const body: BaseImageRequestBody = {
7488
model: params.model,
7589
prompt: params.prompt,
76-
size: params.size || '1024x1024',
90+
size: params.size || (params.model === 'dall-e-3' ? '1024x1024' : 'auto'),
7791
n: params.n ? Number(params.n) : 1,
7892
}
7993

8094
if (params.model === 'dall-e-3') {
8195
if (params.quality) body.quality = params.quality
8296
if (params.style) body.style = params.style
83-
} else if (params.model === 'gpt-image-1') {
97+
} else if (params.model === 'gpt-image-1' || params.model === 'gpt-image-2') {
98+
if (params.quality) body.quality = params.quality
8499
if (params.background) body.background = params.background
100+
if (params.outputFormat) body.output_format = params.outputFormat
101+
if (params.model === 'gpt-image-2' && params.moderation) {
102+
body.moderation = params.moderation
103+
}
85104
}
86105

87106
return body
@@ -111,7 +130,7 @@ export const imageTool: ToolConfig = {
111130
} else if (data.data?.[0]?.b64_json) {
112131
base64Image = data.data[0].b64_json
113132
logger.info(
114-
'Found base64 encoded image in response for GPT-Image-1',
133+
`Found base64 encoded image in response for ${modelName}`,
115134
`length: ${base64Image.length}`
116135
)
117136
} else {

0 commit comments

Comments
 (0)