Skip to content

Commit aaa742e

Browse files
committed
update
1 parent 87df72c commit aaa742e

File tree

1 file changed

+13
-4
lines changed
  • firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal constructor(
3333
private val playBackQueue = ConcurrentLinkedQueue<ByteArray>()
3434
private var startedReceiving = false
3535
private var receiveChannel: Channel<Frame> = Channel()
36+
private var functionCallChannel: Channel<List<FunctionCallPart>> = Channel()
3637

3738
@Serializable
3839
internal data class ClientContent(
@@ -51,7 +52,7 @@ internal constructor(
5152
)
5253
@Serializable
5354
internal data class ToolResponse(
54-
val functionResponses: List<FunctionResponsePart.Internal.FunctionResponse>
55+
val functionResponses: List<FunctionResponsePart.Internal.FunctionResponse>
5556
)
5657

5758
@Serializable
@@ -70,10 +71,14 @@ internal constructor(
7071

7172
@Serializable internal data class ToolCall(val functionCalls: List<FunctionCallPart.Internal.FunctionCall>)
7273

73-
public suspend fun startAudioConversation() {
74+
public fun receiveFunctionCalls(): Flow<List<FunctionCallPart>> {
75+
return functionCallChannel.receiveAsFlow()
76+
}
77+
public suspend fun startAudioConversation(){
7478
if (isRecording) {
7579
return
7680
}
81+
functionCallChannel = Channel()
7782
println("Started Receiving")
7883
isRecording = true
7984
audioHelper = AudioHelper()
@@ -124,6 +129,9 @@ internal constructor(
124129
if (it.status == Status.INTERRUPTED) {
125130
while (!playBackQueue.isEmpty()) playBackQueue.poll()
126131
} else if(it.status == Status.NORMAL) {
132+
if(!it.functionCalls.isNullOrEmpty()) {
133+
functionCallChannel.send(it.functionCalls)
134+
}
127135
playBackQueue.add(it.data!!.parts[0].asInlineDataPartOrNull()!!.inlineData)
128136
}
129137
}
@@ -217,7 +225,7 @@ internal constructor(
217225
}
218226

219227
public suspend fun sendFunctionResponse(
220-
functionList: List<FunctionResponsePart>
228+
functionList: List<FunctionResponsePart>
221229
) {
222230
val jsonString = Json.encodeToString(ToolResponseSetup(ToolResponse(functionList.map{it.toInternalFunctionCall()})))
223231
session?.send(Frame.Text(jsonString))
@@ -249,11 +257,12 @@ internal constructor(
249257
session?.send(Frame.Text(jsonString))
250258
}
251259
public suspend fun send(text: String){
252-
send(Content.Builder().text(text).build())
260+
send(Content.Builder().text(text).build())
253261

254262
}
255263

256264
public suspend fun close() {
257265
session?.close()
258266
}
259267
}
268+

0 commit comments

Comments
 (0)