Skip to content

Commit 6e9ec6f

Browse files
committed
update function calling stuff
1 parent 907feb0 commit 6e9ec6f

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

firebase-vertexai/api.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ package com.google.firebase.vertexai.java {
132132
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> send(String text);
133133
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> sendFunctionResponse(java.util.List<com.google.firebase.vertexai.type.FunctionResponsePart> functionList);
134134
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> sendMediaStream(java.util.List<com.google.firebase.vertexai.type.MediaData> mediaChunks);
135-
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> startAudioConversation(kotlin.jvm.functions.Function1<? super java.util.List<com.google.firebase.vertexai.type.FunctionCallPart>,? extends java.util.List<com.google.firebase.vertexai.type.FunctionResponsePart>>? functionCallsHandler);
135+
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> startAudioConversation(kotlin.jvm.functions.Function1<? super com.google.firebase.vertexai.type.FunctionCallPart,com.google.firebase.vertexai.type.FunctionResponsePart>? functionCallHandler);
136136
method public abstract com.google.common.util.concurrent.ListenableFuture<kotlin.Unit> stopAudioConversation();
137137
method public abstract void stopReceiving();
138138
field public static final com.google.firebase.vertexai.java.LiveSessionFutures.Companion Companion;
@@ -631,7 +631,7 @@ package com.google.firebase.vertexai.type {
631631
method public suspend Object? send(String text, kotlin.coroutines.Continuation<? super kotlin.Unit>);
632632
method public suspend Object? sendFunctionResponse(java.util.List<com.google.firebase.vertexai.type.FunctionResponsePart> functionList, kotlin.coroutines.Continuation<? super kotlin.Unit>);
633633
method public suspend Object? sendMediaStream(java.util.List<com.google.firebase.vertexai.type.MediaData> mediaChunks, kotlin.coroutines.Continuation<? super kotlin.Unit>);
634-
method public suspend Object? startAudioConversation(kotlin.jvm.functions.Function1<? super java.util.List<com.google.firebase.vertexai.type.FunctionCallPart>,? extends java.util.List<com.google.firebase.vertexai.type.FunctionResponsePart>>? functionCallsHandler = null, kotlin.coroutines.Continuation<? super kotlin.Unit>);
634+
method public suspend Object? startAudioConversation(kotlin.jvm.functions.Function1<? super com.google.firebase.vertexai.type.FunctionCallPart,com.google.firebase.vertexai.type.FunctionResponsePart>? functionCallHandler = null, kotlin.coroutines.Continuation<? super kotlin.Unit>);
635635
method public void stopAudioConversation();
636636
method public void stopReceiving();
637637
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public abstract class LiveSessionFutures internal constructor() {
4141
* Starts an audio conversation with the Gemini server, which can only be stopped using
4242
* stopAudioConversation.
4343
*
44-
* @param functionCallsHandler A callback function that is invoked whenever the server receives a
44+
* @param functionCallHandler A callback function that is invoked whenever the server receives a
4545
* function call.
4646
*/
4747
public abstract fun startAudioConversation(
48-
functionCallsHandler: ((List<FunctionCallPart>) -> List<FunctionResponsePart>)?
48+
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)?
4949
): ListenableFuture<Unit>
5050

5151
/** Stops the audio conversation with the Gemini Server. */
@@ -121,8 +121,8 @@ public abstract class LiveSessionFutures internal constructor() {
121121
SuspendToFutureAdapter.launchFuture { session.sendMediaStream(mediaChunks) }
122122

123123
override fun startAudioConversation(
124-
functionCallsHandler: ((List<FunctionCallPart>) -> List<FunctionResponsePart>)?
125-
) = SuspendToFutureAdapter.launchFuture { session.startAudioConversation(functionCallsHandler) }
124+
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)?
125+
) = SuspendToFutureAdapter.launchFuture { session.startAudioConversation(functionCallHandler) }
126126

127127
override fun stopAudioConversation() =
128128
SuspendToFutureAdapter.launchFuture { session.stopAudioConversation() }

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ internal constructor(
152152
}
153153

154154
private fun fillServerResponseAudioQueue(
155-
functionCallsHandler: ((List<FunctionCallPart>) -> List<FunctionResponsePart>)? = null
155+
functionCallsHandler: ((FunctionCallPart) -> FunctionResponsePart)? = null
156156
) {
157157
CoroutineScope(backgroundDispatcher).launch {
158158
receive(listOf(ContentModality.AUDIO)).collect {
@@ -164,7 +164,7 @@ internal constructor(
164164
while (!playBackQueue.isEmpty()) playBackQueue.poll()
165165
LiveContentResponse.Status.NORMAL ->
166166
if (!it.functionCalls.isNullOrEmpty() && functionCallsHandler != null) {
167-
sendFunctionResponse(functionCallsHandler(it.functionCalls))
167+
sendFunctionResponse(it.functionCalls.map(functionCallsHandler).toList())
168168
} else {
169169
val audioData = it.data?.parts?.get(0)?.asInlineDataPartOrNull()?.inlineData
170170
if (audioData != null) {
@@ -189,11 +189,11 @@ internal constructor(
189189
* Starts an audio conversation with the Gemini server, which can only be stopped using
190190
* [stopAudioConversation].
191191
*
192-
* @param functionCallsHandler A callback function that is invoked whenever the server receives a
192+
* @param functionCallHandler A callback function that is invoked whenever the server receives a
193193
* function call.
194194
*/
195195
public suspend fun startAudioConversation(
196-
functionCallsHandler: ((List<FunctionCallPart>) -> List<FunctionResponsePart>)? = null
196+
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)? = null
197197
) {
198198
if (isRecording) {
199199
Log.w(TAG, "startAudioConversation called after the recording has already started.")
@@ -204,7 +204,7 @@ internal constructor(
204204
audioHelper!!.setupAudioTrack()
205205
fillRecordedAudioQueue()
206206
CoroutineScope(backgroundDispatcher).launch { sendAudioDataToServer() }
207-
fillServerResponseAudioQueue(functionCallsHandler)
207+
fillServerResponseAudioQueue(functionCallHandler)
208208
playServerResponseAudio()
209209
}
210210

0 commit comments

Comments
 (0)