Skip to content

Commit 096bc4c

Browse files
committed
working
1 parent 889babc commit 096bc4c

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ internal constructor(
148148
//emit(LiveContentResponse(null, functionContent.toolCall.functionCalls.map { it.toPublic() as FunctionCallPart })))
149149
break
150150
} catch (_: Exception){ }
151-
if (receivedJson.contains("turnComplete")) {
152-
break
153-
}
154151

155152
try {
156153
if (receivedJson.contains("interrupted")) {
@@ -195,17 +192,16 @@ internal constructor(
195192
val jsonString =
196193
Json.encodeToString(
197194
ClientContentSetup(
198-
ClientContent(listOf(content.toInternal()), false)
195+
ClientContent(listOf(content.toInternal()), true)
199196
)
200197
)
201-
println(jsonString)
202198
session?.send(Frame.Text(jsonString))
203199
while (true) {
204200
try {
205201
val message = session?.incoming?.receive() ?: continue
206202
val receivedBytes = (message as Frame.Binary).readBytes()
207203
val receivedJson = receivedBytes.toString(Charsets.UTF_8)
208-
println(receivedJson)
204+
println(receivedBytes)
209205
try {
210206
val functionContent = Json.decodeFromString<ToolCallSetup>(receivedJson)
211207
emit(LiveContentResponse(null, false, functionContent.toolCall.functionCalls.map { FunctionCallPart(it.name, it.args!!) }))

firebase-vertexai/src/test/java/com/google/firebase/vertexai/LiveModelTesting.kt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,28 @@ class LiveModelTesting {
5757
)
5858
runBlocking{
5959
val session = generativeModel.connect()
60-
session!!.send("Tell me the status of the light of type tubelight", listOf(ContentModality.TEXT)).collect {
61-
println(it)
62-
if(!it.functionCalls.isNullOrEmpty()) {
63-
println("Entered??")
64-
val fetchWeatherCall = it.functionCalls!!.find { it.name == "fetchLight" }
65-
66-
val functionResponse = fetchWeatherCall?.let {
67-
// Alternatively, if your `Location` class is marked as @Serializable, you can use
68-
69-
val type = it.args["type"]!!.jsonPrimitive.content
70-
fetchWeather(type)
71-
}
72-
session!!.send(Content("function", listOf(FunctionResponsePart("fetchLight", functionResponse!!))), listOf(ContentModality.TEXT)).collect {
73-
x-> println(x.text)
74-
}
75-
}
60+
session!!.send("Tell me a story", listOf(ContentModality.TEXT)).collect {
61+
println(it.text)
7662
}
7763

64+
// session!!.send("Tell me the status of the light ", listOf(ContentModality.TEXT)).collect {
65+
// println(it)
66+
// if(!it.functionCalls.isNullOrEmpty()) {
67+
// println("Entered??")
68+
// val fetchWeatherCall = it.functionCalls!!.find { it.name == "fetchLight" }
69+
//
70+
// val functionResponse = fetchWeatherCall?.let {
71+
// // Alternatively, if your `Location` class is marked as @Serializable, you can use
72+
//
73+
// val type = it.args["type"]!!.jsonPrimitive.content
74+
// fetchWeather(type)
75+
// }
76+
// session!!.send(Content("function", listOf(FunctionResponsePart("fetchLight", functionResponse!!))), listOf(ContentModality.TEXT)).collect {
77+
// x-> println(x.text)
78+
// }
79+
// }
80+
// }
81+
7882

7983
}
8084

0 commit comments

Comments
 (0)