DALLEImageGenerator
Generate images from text prompts using OpenAI's DALL-E model. The component accepts a text prompt, sends it to the DALL-E API, and returns the generated images along with any revised prompt OpenAI used.
Key Features
- Supports both DALL-E 2 and DALL-E 3 models.
- Configurable image quality (standard or HD) and size.
- Returns images as URLs or base64-encoded JSON strings.
- Returns the revised prompt OpenAI used for image generation.
- Compatible with
PromptBuilderfor dynamic prompt construction.
Configuration
To use this component, connect Haystack Platform with OpenAI first. For details, see Use OpenAI Models.
- Drag the
DALLEImageGeneratorcomponent onto the canvas from the Component Library. - Click the component to open the configuration panel.
- On the General tab:
- Select the model:
dall-e-2ordall-e-3.
- Select the model:
- Go to the Advanced tab to configure image quality, size, response format, API key, timeout, maximum retries, API base URL, organization ID, and HTTP client settings.
Connections
DALLEImageGenerator accepts a prompt string as input. It outputs a list of images (images) and the revised prompt (revised_prompt) OpenAI used for generation.
Typically, you connect a PromptBuilder to the DALLEImageGenerator's prompt input to build dynamic prompts. The images and revised_prompt outputs connect to an OutputAdapter or AnswerBuilder for further processing.
Usage Example
This pipeline uses DALLEImageGenerator to generate images based on a query:
components:
prompt_builder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: '{{query}}'
dalle_image_generator:
type: haystack.components.generators.openai_dalle.DALLEImageGenerator
init_parameters:
model: dall-e-3
quality: standard
size: 1024x1024
response_format: url
timeout: 60
answer_formatter:
type: haystack.components.converters.output_adapter.OutputAdapter
init_parameters:
template: |-
{% set ns = namespace(doc_string='') %}
{% set ns.doc_string = ns.doc_string + '## Query:\n' + query + '\n\n' %}
{% set ns.doc_string = ns.doc_string + '## OpenAIs Revised Prompt:\n' + revised_prompt + '\n\n' %}
{% set ns.doc_string = ns.doc_string + '' + '\n\n' %}
{% set answer = [ns.doc_string] %}
{{ answer }}
output_type: List[str]
answer_builder:
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
init_parameters: {}
connections:
- sender: prompt_builder.prompt
receiver: dalle_image_generator.prompt
- sender: dalle_image_generator.revised_prompt
receiver: answer_formatter.revised_prompt
- sender: dalle_image_generator.images
receiver: answer_formatter.images
- sender: answer_formatter.output
receiver: answer_builder.replies
- sender: prompt_builder.prompt
receiver: answer_builder.prompt
max_runs_per_component: 100
metadata: {}
inputs:
query:
- prompt_builder.query
- answer_formatter.query
- answer_builder.query
outputs:
answers: answer_builder.answers
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| prompt | str | The prompt to generate the image. | |
| size | Optional[Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']] | None | If provided, overrides the size provided during initialization. |
| quality | Optional[Literal['standard', 'hd']] | None | If provided, overrides the quality provided during initialization. |
| response_format | Optional[Optional[Literal['url', 'b64_json']]] | None | If provided, overrides the response format provided during initialization. |
Outputs
| Parameter | Type | Description |
|---|---|---|
| images | List[str] | A list of generated images. Depending on the response_format parameter, the images are URLs or base64-encoded JSON strings. |
| revised_prompt | str | The prompt OpenAI used to generate the image. OpenAI may revise the original prompt before generating the image. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| model | str | dall-e-3 | The model to use for image generation. Can be "dall-e-2" or "dall-e-3". |
| quality | Literal['standard', 'hd'] | standard | The quality of the generated image. Can be "standard" or "hd". |
| size | Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792'] | 1024x1024 | The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024 for dall-e-2. Must be one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models. |
| response_format | Literal['url', 'b64_json'] | url | The format of the response. Can be "url" or "b64_json". |
| api_key | Secret | Secret.from_env_var('OPENAI_API_KEY') | The OpenAI API key to connect to OpenAI. |
| api_base_url | Optional[str] | None | An optional base URL. |
| organization | Optional[str] | None | The Organization ID, defaults to None. |
| timeout | Optional[float] | None | Timeout for OpenAI Client calls. If not set, it is inferred from the OPENAI_TIMEOUT environment variable or set to 30. |
| max_retries | Optional[int] | None | Maximum retries to establish contact with OpenAI if it returns an internal error. If not set, it is inferred from the OPENAI_MAX_RETRIES environment variable or set to 5. |
| http_client_kwargs | Optional[Dict[str, Any]] | None | A dictionary of keyword arguments to configure a custom httpx.Clientor httpx.AsyncClient. For more information, see the HTTPX documentation. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
| prompt | str | The prompt to generate the image. | |
| size | Optional[Literal['256x256', '512x512', '1024x1024', '1792x1024', '1024x1792']] | None | If provided, overrides the size provided during initialization. |
| quality | Optional[Literal['standard', 'hd']] | None | If provided, overrides the quality provided during initialization. |
| response_format | Optional[Optional[Literal['url', 'b64_json']]] | None | If provided, overrides the response format provided during initialization. |
Was this page helpful?