Skip to content

Commit d8dd0bf

Browse files
committed
Merge branch 'bidi' into rl.bidi.receiveddata
2 parents c0ae8c0 + 1df7e48 commit d8dd0bf

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

firebase-vertexai/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ package com.google.firebase.vertexai.java {
127127
public abstract class LiveSessionFutures {
128128
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> close();
129129
method public static final com.google.firebase.vertexai.java.LiveSessionFutures from(com.google.firebase.vertexai.type.LiveSession session);
130-
method public abstract com.google.common.util.concurrent.ListenableFuture<org.reactivestreams.Publisher<com.google.firebase.vertexai.type.LiveContentResponse>> receive(java.util.List<com.google.firebase.vertexai.type.ContentModality> outputModalities);
130+
method public abstract org.reactivestreams.Publisher<com.google.firebase.vertexai.type.LiveContentResponse> receive(java.util.List<com.google.firebase.vertexai.type.ContentModality> outputModalities);
131131
method public abstract org.reactivestreams.Publisher<java.util.List<com.google.firebase.vertexai.type.FunctionCallPart>> receiveAudioConversationFunctionCalls();
132132
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> send(com.google.firebase.vertexai.type.Content content);
133133
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> send(String text);

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/LiveGenerativeModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ internal constructor(
8383
* Returns a LiveSession object using which you could send/receive messages from the server
8484
* @return LiveSession object created
8585
* @throws [BidiServerHandshakeFailed] if the handshake with the server failed.
86+
* @throws [ClosedReceiveChannelException] if the channel was closed by the server.
8687
*/
8788
public suspend fun connect(): LiveSession {
8889
val clientMessage =

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ internal constructor(
129129

130130
/**
131131
* Receives all function call responses from the server for the audio conversation feature.
132+
* This can be called only after calling [startAudioConversation] function.
132133
*
133134
* @return A [Flow] which will emit list of [FunctionCallPart] as they are returned by the model.
134135
*/
@@ -196,10 +197,11 @@ internal constructor(
196197

197198
/**
198199
* Starts an audio conversation with the Gemini server, which can only be stopped using
199-
* stopAudioConversation.
200+
* [stopAudioConversation].
200201
*/
201202
public suspend fun startAudioConversation() {
202203
if (isRecording) {
204+
Log.w(TAG, "startAudioConversation called after the recording has already started.")
203205
return
204206
}
205207
functionCallChannel = Channel()
@@ -210,10 +212,13 @@ internal constructor(
210212
CoroutineScope(backgroundDispatcher).launch { sendAudioDataToServer() }
211213
fillServerResponseAudioQueue()
212214
playServerResponseAudio()
215+
// This delay is necessary to ensure that all threads have started.
213216
delay(1000)
214217
}
215218

216-
/** Stops the audio conversation with the Gemini Server. */
219+
/** Stops the audio conversation with the Gemini Server. This needs to be called only after
220+
* calling [startAudioConversation]
221+
* */
217222
public fun stopAudioConversation() {
218223
stopReceiving()
219224
isRecording = false
@@ -239,7 +244,8 @@ internal constructor(
239244
}
240245

241246
/**
242-
* Receives responses from the server for both streaming and standard requests.
247+
* Receives responses from the server for both streaming and standard requests. Call
248+
* [stopReceiving] to stop receiving responses from the server.
243249
*
244250
* @param outputModalities The list of output formats to receive from the server.
245251
*
@@ -298,7 +304,7 @@ internal constructor(
298304
)
299305
continue
300306
} catch (e: Exception) {
301-
Log.i(TAG, "Failed to decode function calling: ${e.message}")
307+
Log.w(TAG, "Failed to decode function calling: ${e.message}")
302308
}
303309
}
304310
}
@@ -319,7 +325,8 @@ internal constructor(
319325
}
320326

321327
/**
322-
* Streams client data to the server.
328+
* Streams client data to the server. Calling this after [startAudioConversation] will play the
329+
* response audio immediately.
323330
*
324331
* @param mediaChunks The list of [MediaData] instances representing the media data to be sent.
325332
*/
@@ -332,7 +339,8 @@ internal constructor(
332339
}
333340

334341
/**
335-
* Sends data to the server
342+
* Sends data to the server. Calling this after [startAudioConversation] will play the response
343+
* audio immediately.
336344
*
337345
* @param content Client [Content] to be sent to the server.
338346
*/
@@ -343,7 +351,8 @@ internal constructor(
343351
}
344352

345353
/**
346-
* Sends text to the server
354+
* Sends text to the server. Calling this after [startAudioConversation] will play the response
355+
* audio immediately.
347356
*
348357
* @param text Text to be sent to the server.
349358
*/

0 commit comments

Comments
 (0)