LiveSessionFutures

@PublicPreviewAPI
public abstract class LiveSessionFutures


Wrapper class providing Java compatible methods for LiveSession.

See also
LiveSession

Summary

Nested types

public static class LiveSessionFutures.Companion

Public methods

abstract @NonNull ListenableFuture<Unit>

Closes the client session.

static final @NonNull LiveSessionFutures
abstract @NonNull Publisher<@NonNull LiveContentResponse>

Receives responses from the model for both streaming and standard requests.

abstract @NonNull ListenableFuture<Unit>
send(@NonNull Content content)

Sends data to the model.

abstract @NonNull ListenableFuture<Unit>

Sends text to the model.

abstract @NonNull ListenableFuture<Unit>

Sends function calling responses to the model.

abstract @NonNull ListenableFuture<Unit>

Streams client data to the model.

abstract @NonNull ListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation()

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation.

abstract @NonNull ListenableFuture<Unit>
startAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

abstract @NonNull ListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
stopAudioConversation()

Stops the audio conversation with the Gemini Server.

abstract void

Stops receiving from the model.

Public methods

close

public abstract @NonNull ListenableFuture<Unitclose()

Closes the client session.

Once a LiveSession is closed, it can not be reopened; you'll need to start a new LiveSession.

See also
stopReceiving

from

public static final @NonNull LiveSessionFutures from(@NonNull LiveSession session)
Returns
@NonNull LiveSessionFutures

a LiveSessionFutures created around the provided LiveSession

receive

public abstract @NonNull Publisher<@NonNull LiveContentResponsereceive()

Receives responses from the model for both streaming and standard requests.

Call close to stop receiving responses from the model.

Returns
@NonNull Publisher<@NonNull LiveContentResponse>

A Publisher which will emit LiveContentResponse from the model.

Throws
com.google.firebase.vertexai.type.SessionAlreadyReceivingException com.google.firebase.vertexai.type.SessionAlreadyReceivingException

when the session is already receiving.

See also
stopReceiving

send

public abstract @NonNull ListenableFuture<Unitsend(@NonNull Content content)

Sends data to the model.

Calling this after startAudioConversation will play the response audio immediately.

Parameters
@NonNull Content content

Client Content to be sent to the model.

send

public abstract @NonNull ListenableFuture<Unitsend(@NonNull String text)

Sends text to the model.

Calling this after startAudioConversation will play the response audio immediately.

Parameters
@NonNull String text

Text to be sent to the model.

sendFunctionResponse

public abstract @NonNull ListenableFuture<UnitsendFunctionResponse(
    @NonNull List<@NonNull FunctionResponsePart> functionList
)

Sends function calling responses to the model.

Parameters
@NonNull List<@NonNull FunctionResponsePart> functionList

The list of FunctionResponsePart instances indicating the function response from the client.

sendMediaStream

public abstract @NonNull ListenableFuture<UnitsendMediaStream(@NonNull List<@NonNull MediaData> mediaChunks)

Streams client data to the model.

Calling this after startAudioConversation will play the response audio immediately.

Parameters
@NonNull List<@NonNull MediaData> mediaChunks

The list of MediaData instances representing the media data to be sent.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNull ListenableFuture<UnitstartAudioConversation()

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation.

startAudioConversation

public abstract @NonNull ListenableFuture<UnitstartAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

Parameters
Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler

A callback function that is invoked whenever the model receives a function call.

stopAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNull ListenableFuture<UnitstopAudioConversation()

Stops the audio conversation with the Gemini Server.

This only needs to be called after a previous call to startAudioConversation.

If there is no audio conversation currently active, this function does nothing.

stopReceiving

public abstract void stopReceiving()

Stops receiving from the model.

If this function is called during an ongoing audio conversation, the model's response will not be received, and no audio will be played; the live session object will no longer receive data from the server.

To resume receiving data, you must either handle it directly using receive, or indirectly by using startAudioConversation.

See also
close