Realtime Chat
[BETA] Modules concerning the realtime chat modules to interact with realtime chat models.
GoogleRealtimeChat(model_name, api_key=None, credentials_path=None, project_id=None, location='us-central1')
Bases: BaseRealtimeChat
[BETA] A realtime chat module to interact with Gemini Live models.
Warning
The 'GoogleRealtimeChat' class is currently in beta and may be subject to changes in the future. It is intended only for quick prototyping in local environments. Please avoid using it in production environments.
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
str
|
The name of the language model. |
client_params |
dict[str, Any]
|
The Google client instance init parameters. |
Basic usage
The GoogleRealtimeChat can be used as started as follows:
realtime_chat = GoogleRealtimeChat(model_name="gemini-live-2.5-flash-preview")
await realtime_chat.invoke()
Custom IO streamers
The GoogleRealtimeChat can be used with custom IO streamers.
input_streamers = [KeyboardInputStreamer(), LinuxMicInputStreamer()]
output_streamers = [ConsoleOutputStreamer(), LinuxSpeakerOutputStreamer()]
realtime_chat = GoogleRealtimeChat(model_name="gemini-live-2.5-flash-preview")
await realtime_chat.start(input_streamers=input_streamers, output_streamers=output_streamers)
In the above example, we added a capability to use a Linux system microphone and speaker, allowing realtime audio input and output to the model.
Authentication
The GoogleRealtimeChat can use either Google Gen AI or Google Vertex AI.
Google Gen AI is recommended for quick prototyping and development. It requires a Gemini API key for authentication.
Usage example:
realtime_chat = GoogleRealtimeChat(
model_name="gemini-live-2.5-flash-preview",
api_key="your_api_key"
)
Google Vertex AI is recommended to build production-ready applications. It requires a service account JSON file for authentication.
Usage example:
realtime_chat = GoogleRealtimeChat(
model_name="gemini-live-2.5-flash-preview",
credentials_path="path/to/service_account.json"
)
If neither api_key nor credentials_path is provided, Google Gen AI will be used by default.
The GOOGLE_API_KEY environment variable will be used for authentication.
Initializes a new instance of the GoogleRealtimeChat class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name |
str
|
The name of the model to use. |
required |
api_key |
str | None
|
Required for Google Gen AI authentication. Cannot be used together
with |
None
|
credentials_path |
str | None
|
Required for Google Vertex AI authentication. Path to the service
account credentials JSON file. Cannot be used together with |
None
|
project_id |
str | None
|
The Google Cloud project ID for Vertex AI. Only used when authenticating
with |
None
|
location |
str
|
The location of the Google Cloud project for Vertex AI. Only used when
authenticating with |
'us-central1'
|
Note
If neither api_key nor credentials_path is provided, Google Gen AI will be used by default.
The GOOGLE_API_KEY environment variable will be used for authentication.
start(input_streamers=None, output_streamers=None, post_output_audio_delay=DEFAULT_POST_OUTPUT_AUDIO_DELAY)
async
Starts the realtime conversation using the provided input and output streamers.
This method is used to start the realtime conversation using a GoogleIOStreamer.
The streamers are responsible for handling the input and output of the conversation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_streamers |
list[BaseInputStreamer] | None
|
The input streamers to use.
Defaults to None, in which case a |
None
|
output_streamers |
list[BaseOutputStreamer] | None
|
The output streamers to use.
Defaults to None, in which case a |
None
|
post_output_audio_delay |
float
|
The delay in seconds to post the output audio. Defaults to 0.5 seconds. |
DEFAULT_POST_OUTPUT_AUDIO_DELAY
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the |
ValueError
|
If the |
Exception
|
If the conversation fails to process. |