VertexAIImageGenerator
Generate images using Google Vertex AI generative model.
Key Features
- Generates images from text prompts using the Vertex AI image generation model.
- Supports an optional negative prompt to exclude elements from the output.
- Authenticates using Google Cloud Application Default Credentials.
- Returns generated images as a list of
ByteStreamobjects.
Configuration
This component authenticates using Google Cloud Application Default Credentials (ADCs). For more information, see the official Google documentation.
Create secrets for GCP_PROJECT_ID and optionally GCP_DEFAULT_REGION. For detailed instructions on creating secrets, see Create Secrets.
- Drag the
VertexAIImageGeneratorcomponent onto the canvas from the Component Library. - Click the component to open the configuration panel.
- On the General tab:
- Enter the model name (for example,
imagegeneration).
- Enter the model name (for example,
- Go to the Advanced tab to configure the project ID, location, and additional model kwargs.
Connections
VertexAIImageGenerator accepts a text prompt as input and an optional negative_prompt. It outputs a list of ByteStream objects (images), each containing a generated image.
Typically, you connect PromptBuilder to the prompt input to build dynamic prompts from a query.
Usage Example
This pipeline uses VertexAIImageGenerator to generate images from text prompts:
components:
VertexAIImageGenerator:
type: haystack_integrations.components.generators.google_vertex.image_generator.VertexAIImageGenerator
init_parameters:
project_id:
model: imagegeneration
location:
PromptBuilder:
type: haystack.components.builders.prompt_builder.PromptBuilder
init_parameters:
template: "Generate an image described in the query.\n\nQuery: {{ query }}"
required_variables: "\\n"
variables:
max_runs_per_component: 100
metadata: {}
connections:
- sender: PromptBuilder.prompt
receiver: VertexAIImageGenerator.prompt
inputs:
query:
- PromptBuilder.query
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| prompt | str | The prompt to generate images from. | |
| negative_prompt | Optional[str] | None | A description of what you want to omit in the generated images. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| images | List[ByteStream] | A list of ByteStream objects, each containing an image. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| project_id | Optional[str] | None | ID of the GCP project to use. By default, it is set during Google Cloud authentication. |
| model | str | imagegeneration | Name of the model to use. |
| location | Optional[str] | None | The default location to use when making API calls. If not set, uses us-central-1. |
| kwargs | Any | Additional keyword arguments to pass to the model. See the ImageGenerationModel.generate_images() 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 images from. | |
| negative_prompt | Optional[str] | None | A description of what you want to omit in the generated images. |
Was this page helpful?