diff --git a/apps/sim/blocks/blocks/image_generator.ts b/apps/sim/blocks/blocks/image_generator.ts index 6963cd604fd..953cce252bb 100644 --- a/apps/sim/blocks/blocks/image_generator.ts +++ b/apps/sim/blocks/blocks/image_generator.ts @@ -8,7 +8,7 @@ export const ImageGeneratorBlock: BlockConfig = { description: 'Generate images', authMode: AuthMode.ApiKey, longDescription: - 'Integrate Image Generator into the workflow. Can generate images using DALL-E 3 or GPT Image.', + 'Integrate Image Generator into the workflow. Can generate images using DALL-E 3, GPT Image 1, or GPT Image 2.', docsLink: 'https://docs.sim.ai/tools/image_generator', category: 'tools', integrationType: IntegrationType.AI, @@ -22,7 +22,8 @@ export const ImageGeneratorBlock: BlockConfig = { type: 'dropdown', options: [ { label: 'DALL-E 3', id: 'dall-e-3' }, - { label: 'GPT Image', id: 'gpt-image-1' }, + { label: 'GPT Image 1', id: 'gpt-image-1' }, + { label: 'GPT Image 2', id: 'gpt-image-2' }, ], value: () => 'dall-e-3', }, @@ -60,6 +61,22 @@ export const ImageGeneratorBlock: BlockConfig = { condition: { field: 'model', value: 'gpt-image-1' }, dependsOn: ['model'], }, + { + id: 'size', + title: 'Size', + type: 'dropdown', + options: [ + { label: 'Auto', id: 'auto' }, + { label: '1024x1024 (Square)', id: '1024x1024' }, + { label: '1536x1024 (Landscape)', id: '1536x1024' }, + { label: '1024x1536 (Portrait)', id: '1024x1536' }, + { label: '2048x2048 (2K Square)', id: '2048x2048' }, + { label: '3840x2160 (4K Landscape)', id: '3840x2160' }, + ], + value: () => 'auto', + condition: { field: 'model', value: 'gpt-image-2' }, + dependsOn: ['model'], + }, { id: 'quality', title: 'Quality', @@ -72,6 +89,20 @@ export const ImageGeneratorBlock: BlockConfig = { condition: { field: 'model', value: 'dall-e-3' }, dependsOn: ['model'], }, + { + id: 'quality', + title: 'Quality', + type: 'dropdown', + options: [ + { label: 'Auto', id: 'auto' }, + { label: 'Low', id: 'low' }, + { label: 'Medium', id: 'medium' }, + { label: 'High', id: 'high' }, + ], + value: () => 'auto', + condition: { field: 'model', value: ['gpt-image-1', 'gpt-image-2'] }, + dependsOn: ['model'], + }, { id: 'style', title: 'Style', @@ -97,6 +128,43 @@ export const ImageGeneratorBlock: BlockConfig = { condition: { field: 'model', value: 'gpt-image-1' }, dependsOn: ['model'], }, + { + id: 'background', + title: 'Background', + type: 'dropdown', + options: [ + { label: 'Auto', id: 'auto' }, + { label: 'Opaque', id: 'opaque' }, + ], + value: () => 'auto', + condition: { field: 'model', value: 'gpt-image-2' }, + dependsOn: ['model'], + }, + { + id: 'outputFormat', + title: 'Output Format', + type: 'dropdown', + options: [ + { label: 'PNG', id: 'png' }, + { label: 'JPEG', id: 'jpeg' }, + { label: 'WebP', id: 'webp' }, + ], + value: () => 'png', + condition: { field: 'model', value: ['gpt-image-1', 'gpt-image-2'] }, + dependsOn: ['model'], + }, + { + id: 'moderation', + title: 'Moderation', + type: 'dropdown', + options: [ + { label: 'Auto', id: 'auto' }, + { label: 'Low', id: 'low' }, + ], + value: () => 'auto', + condition: { field: 'model', value: 'gpt-image-2' }, + dependsOn: ['model'], + }, { id: 'apiKey', title: 'API Key', @@ -120,7 +188,7 @@ export const ImageGeneratorBlock: BlockConfig = { } const model = params.model || 'dall-e-3' - const size = params.size || (model === 'gpt-image-1' ? 'auto' : '1024x1024') + const size = params.size || (model === 'dall-e-3' ? '1024x1024' : 'auto') const baseParams = { prompt: params.prompt, model, @@ -138,7 +206,18 @@ export const ImageGeneratorBlock: BlockConfig = { if (model === 'gpt-image-1') { return { ...baseParams, + ...(params.quality && { quality: params.quality }), + ...(params.background && { background: params.background }), + ...(params.outputFormat && { outputFormat: params.outputFormat }), + } + } + if (model === 'gpt-image-2') { + return { + ...baseParams, + ...(params.quality && { quality: params.quality }), ...(params.background && { background: params.background }), + ...(params.outputFormat && { outputFormat: params.outputFormat }), + ...(params.moderation && { moderation: params.moderation }), } } @@ -153,6 +232,8 @@ export const ImageGeneratorBlock: BlockConfig = { quality: { type: 'string', description: 'Image quality level' }, style: { type: 'string', description: 'Image style' }, background: { type: 'string', description: 'Background type' }, + outputFormat: { type: 'string', description: 'Output image format (png, jpeg, webp)' }, + moderation: { type: 'string', description: 'Moderation level (auto or low)' }, apiKey: { type: 'string', description: 'OpenAI API key' }, }, outputs: { diff --git a/apps/sim/tools/openai/image.ts b/apps/sim/tools/openai/image.ts index 2e857d153f6..1c844639c78 100644 --- a/apps/sim/tools/openai/image.ts +++ b/apps/sim/tools/openai/image.ts @@ -16,7 +16,7 @@ export const imageTool: ToolConfig = { type: 'string', required: true, visibility: 'user-only', - description: 'The model to use (gpt-image-1 or dall-e-3)', + description: 'The model to use (dall-e-3, gpt-image-1, or gpt-image-2)', }, prompt: { type: 'string', @@ -34,19 +34,33 @@ export const imageTool: ToolConfig = { type: 'string', required: false, visibility: 'user-or-llm', - description: 'The quality of the image (standard or hd)', + description: + 'Quality. dall-e-3: standard|hd. gpt-image-1/gpt-image-2: auto|low|medium|high', }, style: { type: 'string', required: false, visibility: 'user-or-llm', - description: 'The style of the image (vivid or natural)', + description: 'The style of the image (vivid or natural), only for dall-e-3', }, background: { type: 'string', required: false, visibility: 'user-or-llm', - description: 'The background color, only for gpt-image-1', + description: + 'Background. gpt-image-1: auto|transparent|opaque. gpt-image-2: auto|opaque (transparent not supported)', + }, + outputFormat: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Output image format (png, jpeg, webp), only for gpt-image-1 and gpt-image-2', + }, + moderation: { + type: 'string', + required: false, + visibility: 'user-or-llm', + description: 'Moderation level (auto or low), only for gpt-image-2', }, n: { type: 'number', @@ -73,15 +87,20 @@ export const imageTool: ToolConfig = { const body: BaseImageRequestBody = { model: params.model, prompt: params.prompt, - size: params.size || '1024x1024', + size: params.size || (params.model === 'dall-e-3' ? '1024x1024' : 'auto'), n: params.n ? Number(params.n) : 1, } if (params.model === 'dall-e-3') { if (params.quality) body.quality = params.quality if (params.style) body.style = params.style - } else if (params.model === 'gpt-image-1') { + } else if (params.model === 'gpt-image-1' || params.model === 'gpt-image-2') { + if (params.quality) body.quality = params.quality if (params.background) body.background = params.background + if (params.outputFormat) body.output_format = params.outputFormat + if (params.model === 'gpt-image-2' && params.moderation) { + body.moderation = params.moderation + } } return body @@ -111,7 +130,7 @@ export const imageTool: ToolConfig = { } else if (data.data?.[0]?.b64_json) { base64Image = data.data[0].b64_json logger.info( - 'Found base64 encoded image in response for GPT-Image-1', + `Found base64 encoded image in response for ${modelName}`, `length: ${base64Image.length}` ) } else {