Skip to content

Commit bf3c169

Browse files
committed
add comments
1 parent 5b468a5 commit bf3c169

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/LiveModelFutures.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,14 @@ import java.nio.channels.ClosedChannelException
3131
public abstract class LiveModelFutures internal constructor() {
3232

3333
/**
34-
* Creates and returns a LiveSession object using which you could send/receive messages from the
35-
* server
34+
* Returns a LiveSession object using which you could send/receive messages from the server
3635
* @return LiveSession object created. Returns null if the object cannot be created.
3736
* @throws [ClosedChannelException] if channel was closed before creating a websocket connection.
3837
*/
39-
public abstract fun connect(): ListenableFuture<LiveSession?>
38+
public abstract fun connect(): ListenableFuture<LiveSession>
4039

4140
private class FuturesImpl(private val model: LiveGenerativeModel) : LiveModelFutures() {
42-
override fun connect(): ListenableFuture<LiveSession?> {
41+
override fun connect(): ListenableFuture<LiveSession> {
4342
return SuspendToFutureAdapter.launchFuture { model.connect() }
4443
}
4544
}

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/LiveSessionFutures.kt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import com.google.common.util.concurrent.ListenableFuture
2121
import com.google.firebase.vertexai.GenerativeModel
2222
import com.google.firebase.vertexai.type.Content
2323
import com.google.firebase.vertexai.type.ContentModality
24+
import com.google.firebase.vertexai.type.FunctionCallPart
2425
import com.google.firebase.vertexai.type.FunctionResponsePart
2526
import com.google.firebase.vertexai.type.LiveContentResponse
2627
import com.google.firebase.vertexai.type.LiveSession
2728
import com.google.firebase.vertexai.type.MediaData
29+
import com.google.firebase.vertexai.type.SessionAlreadyReceivingException
2830
import kotlinx.coroutines.reactive.asPublisher
2931
import org.reactivestreams.Publisher
3032

@@ -34,35 +36,84 @@ import org.reactivestreams.Publisher
3436
* @see [GenerativeModel]
3537
*/
3638
public abstract class LiveSessionFutures internal constructor() {
39+
40+
/**
41+
* Starts an audio conversation with the Gemini server, which can only be stopped using
42+
* stopAudioConversation.
43+
*/
3744
public abstract fun startAudioConversation(): ListenableFuture<Unit>
3845

46+
/** Stops the audio conversation with the Gemini Server. */
3947
public abstract fun stopAudioConversation(): ListenableFuture<Unit>
4048

49+
/** Stop receiving from the server. */
4150
public abstract fun stopReceiving()
4251

52+
/**
53+
* Sends the function response from the client to the server.
54+
*
55+
* @param functionList The list of [FunctionResponsePart] instances indicating the function
56+
* response from the client.
57+
*/
4358
public abstract fun sendFunctionResponse(
4459
functionList: List<FunctionResponsePart>
4560
): ListenableFuture<Unit>
4661

62+
/**
63+
* Streams client data to the server.
64+
*
65+
* @param mediaChunks The list of [MediaData] instances representing the media data to be sent.
66+
*/
4767
public abstract fun sendMediaStream(mediaChunks: List<MediaData>): ListenableFuture<Unit>
4868

69+
/**
70+
* Sends data to the server
71+
*
72+
* @param content Client [Content] to be sent to the server.
73+
*/
4974
public abstract fun send(content: Content): ListenableFuture<Unit>
5075

76+
/**
77+
* Sends text to the server
78+
*
79+
* @param text Text to be sent to the server.
80+
*/
5181
public abstract fun send(text: String): ListenableFuture<Unit>
5282

83+
/** Closes the client session. */
5384
public abstract fun close(): ListenableFuture<Unit>
5485

86+
/**
87+
* Receives responses from the server for both streaming and standard requests.
88+
*
89+
* @param outputModalities The list of output formats to receive from the server.
90+
*
91+
* @return A [Publisher] which will emit [LiveContentResponse] as and when it receives it
92+
*
93+
* @throws [SessionAlreadyReceivingException] when the session is already receiving.
94+
*/
5595
public abstract fun receive(
5696
outputModalities: List<ContentModality>
5797
): ListenableFuture<Publisher<LiveContentResponse>>
5898

99+
/**
100+
* Receives all function call responses from the server for the audio conversation feature..
101+
*
102+
* @return A [Publisher] which will emit list of [FunctionCallPart] as they are returned by the
103+
* model.
104+
*/
105+
public abstract fun receiveAudioConversationFunctionCalls(): Publisher<List<FunctionCallPart>>
106+
59107
private class FuturesImpl(private val session: LiveSession) : LiveSessionFutures() {
60108

61109
override fun receive(
62110
outputModalities: List<ContentModality>
63111
): ListenableFuture<Publisher<LiveContentResponse>> =
64112
SuspendToFutureAdapter.launchFuture { session.receive(outputModalities).asPublisher() }
65113

114+
override fun receiveAudioConversationFunctionCalls(): Publisher<List<FunctionCallPart>> =
115+
session.receiveAudioConversationFunctionCalls().asPublisher()
116+
66117
override fun close(): ListenableFuture<Unit> =
67118
SuspendToFutureAdapter.launchFuture { session.close() }
68119

0 commit comments

Comments
 (0)