Skip to main content

GoogleGenAIChatGenerator

Complete chats using Google's Gemini models through the Google Gen AI SDK.

Basic Information

  • Type: haystack_integrations.components.generators.google_genai.chat.chat_generator.GoogleGenAIChatGenerator
  • Components it can connect with:
    • ChatPromptBuilder: GoogleGenAIChatGenerator receives a rendered prompt from ChatPromptBuilder.
    • DeepsetAnswerBuilder: GoogleGenAIChatGenerator sends the generated replies to DeepsetAnswerBuilder through OutputAdapter (see Usage Examples below).

Inputs

ParameterTypeDefaultDescription
messagesList[ChatMessage]A list of ChatMessage instances representing the input messages.
generation_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for the model. For details, see model documentation.
safety_settingsOptional[List[Dict[str, Any]]]NoneSafety settings for content filtering. If provided, it will override the default settings.
streaming_callbackOptional[StreamingCallbackT]NoneA callback function that is called when a new token is received from the stream.
toolsOptional[Union[List[Tool], Toolset]]NoneA list of Tool objects or a Toolset that the model can use.

Outputs

ParameterTypeDefaultDescription
repliesList[ChatMessage]A list containing the generated ChatMessage responses.

Overview

GoogleGenAIChatGenerator provides an interface to Google's Gemini models through the new google-genai SDK, supporting models like gemini-2.0-flash and other Gemini variants.

Authorization

You need Google Studio API key to use this component. Connect deepset to your Google AI Studio account on the Integrations page.

Connection Instructions

  1. Click your profile icon in the top right corner and choose Integrations.
    Integrations menu screenshot
  2. Click Connect next to the provider.
  3. Enter your API key and submit it.

Usage Example

Initializing the Component

components:
GoogleGenAIChatGenerator:
type: haystack_integrations.components.generators.google_genai.chat.chat_generator.GoogleGenAIChatGenerator
init_parameters:

Parameters

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
api_keySecretSecret.from_env_var(['GOOGLE_API_KEY', 'GEMINI_API_KEY'], strict=False)Google API key, defaults to the GOOGLE_API_KEY and GEMINI_API_KEY environment variables. Not needed if using Vertex AI with Application Default Credentials. Go to Google AI Studio for a Gemini API key. Go to Google Cloud Vertex AI for a Vertex AI API key.
apiLiteral['gemini', 'vertex']geminiThe API to use. Either "gemini" for the Gemini Developer API or "vertex" for Vertex AI.
vertex_ai_projectOptional[str]NoneGoogle Cloud project ID for Vertex AI. Required when using Vertex AI with Application Default Credentials.
vertex_ai_locationOptional[str]NoneGoogle Cloud location for Vertex AI (for example, "us-central1", "europe-west1"). Required when using Vertex AI with Application Default Credentials.
modelstrgemini-2.0-flashName of the model to use (for example, "gemini-2.0-flash")
generation_kwargsOptional[Dict[str, Any]]NoneConfiguration for generation (temperature, max_tokens, , and more).
safety_settingsOptional[List[Dict[str, Any]]]NoneSafety settings for content filtering.
streaming_callbackOptional[StreamingCallbackT]NoneA callback function that is called when a new token is received from the stream.
toolsOptional[Union[List[Tool], Toolset]]NoneA list of Tool objects or a Toolset that the model can use. Each tool should have a unique name.

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.

ParameterTypeDefaultDescription
messagesList[ChatMessage]A list of ChatMessage instances representing the input messages.
generation_kwargsOptional[Dict[str, Any]]NoneConfiguration for generation.
safety_settingsOptional[List[Dict[str, Any]]]NoneSafety settings for content filtering.
streaming_callbackOptional[StreamingCallbackT]NoneA callback function that is called when a new token is received from the stream.
toolsOptional[Union[List[Tool], Toolset]]NoneA list of Tool objects or a Toolset that the model can use.