This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Represents an active, real-time, bidirectional conversation with the model.
This class should only be instantiated by calling LiveGenerativeModel.connect().
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the LiveSession
class.
Signature:
export declare class LiveSession
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
inConversation | boolean | (Public Preview) Indicates whether this Live session is being controlled by an AudioConversationController . |
|
isClosed | boolean | (Public Preview) Indicates whether this Live session is closed. |
Methods
Method | Modifiers | Description |
---|---|---|
close() | (Public Preview) Closes this session. All methods on this session will throw an error once this resolves. | |
receive() | (Public Preview) Yields messages received from the server. This can only be used by one consumer at a time. | |
send(request, turnComplete) | (Public Preview) Sends content to the server. | |
sendMediaChunks(mediaChunks) | (Public Preview) Sends realtime input to the server. | |
sendMediaStream(mediaChunkStream) | (Public Preview) Sends a stream of GenerativeContentBlob. |
LiveSession.inConversation
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Indicates whether this Live session is being controlled by an AudioConversationController
.
Signature:
inConversation: boolean;
LiveSession.isClosed
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Indicates whether this Live session is closed.
Signature:
isClosed: boolean;
LiveSession.close()
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Closes this session. All methods on this session will throw an error once this resolves.
Signature:
close(): Promise<void>;
Returns:
Promise<void>
LiveSession.receive()
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Yields messages received from the server. This can only be used by one consumer at a time.
Signature:
receive(): AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation>;
Returns:
AsyncGenerator<LiveServerContent | LiveServerToolCall | LiveServerToolCallCancellation>
An AsyncGenerator
that yields server messages as they arrive.
Exceptions
If the session is already closed, or if we receive a response that we don't support.
LiveSession.send()
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Sends content to the server.
Signature:
send(request: string | Array<string | Part>, turnComplete?: boolean): Promise<void>;
Parameters
Parameter | Type | Description |
---|---|---|
request | string | Array<string | Part> | The message to send to the model. |
turnComplete | boolean | Indicates if the turn is complete. Defaults to false. |
Returns:
Promise<void>
Exceptions
If this session has been closed.
LiveSession.sendMediaChunks()
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Sends realtime input to the server.
Signature:
sendMediaChunks(mediaChunks: GenerativeContentBlob[]): Promise<void>;
Parameters
Parameter | Type | Description |
---|---|---|
mediaChunks | GenerativeContentBlob[] | The media chunks to send. |
Returns:
Promise<void>
Exceptions
If this session has been closed.
LiveSession.sendMediaStream()
This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Sends a stream of GenerativeContentBlob.
Signature:
sendMediaStream(mediaChunkStream: ReadableStream<GenerativeContentBlob>): Promise<void>;
Parameters
Parameter | Type | Description |
---|---|---|
mediaChunkStream | ReadableStream<GenerativeContentBlob> | The stream of GenerativeContentBlob to send. |
Returns:
Promise<void>
Exceptions
If this session has been closed.