Skip to content

Commit 5b468a5

Browse files
committed
update
1 parent 50b919b commit 5b468a5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.google.firebase.auth.internal.InternalAuthProvider
2222
import com.google.firebase.vertexai.common.APIController
2323
import com.google.firebase.vertexai.common.AppCheckHeaderProvider
2424
import com.google.firebase.vertexai.type.BidiGenerateContentClientMessage
25+
import com.google.firebase.vertexai.type.BidiServerHandshakeFailed
2526
import com.google.firebase.vertexai.type.Content
2627
import com.google.firebase.vertexai.type.LiveGenerationConfig
2728
import com.google.firebase.vertexai.type.LiveSession
@@ -33,8 +34,8 @@ import io.ktor.client.engine.okhttp.OkHttp
3334
import io.ktor.client.plugins.websocket.WebSockets
3435
import io.ktor.client.plugins.websocket.webSocketSession
3536
import io.ktor.websocket.Frame
37+
import io.ktor.websocket.close
3638
import io.ktor.websocket.readBytes
37-
import java.nio.channels.ClosedChannelException
3839
import kotlinx.serialization.encodeToString
3940
import kotlinx.serialization.json.Json
4041

@@ -84,9 +85,9 @@ internal constructor(
8485
/**
8586
* Returns a LiveSession object using which you could send/receive messages from the server
8687
* @return LiveSession object created. Returns null if the object cannot be created.
87-
* @throws [ClosedChannelException] if channel was closed before creating a websocket connection.
88+
* @throws [BidiServerHandshakeFailed] if the handshake with the server failed.
8889
*/
89-
public suspend fun connect(): LiveSession? {
90+
public suspend fun connect(): LiveSession {
9091
val client = HttpClient(OkHttp) { install(WebSockets) }
9192

9293
val bidiEndPoint = this.controller.getBidiEndpoint(location)
@@ -115,7 +116,8 @@ internal constructor(
115116
return if (shouldReturn) {
116117
LiveSession(session = webSession, isRecording = false)
117118
} else {
118-
null
119+
webSession.close()
120+
throw BidiServerHandshakeFailed()
119121
}
120122
}
121123

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/BidiGenerateContentSetup.kt renamed to firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/BidiGenerateContentClientMessage.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.google.firebase.vertexai.type
22

3+
import kotlinx.serialization.ExperimentalSerializationApi
34
import kotlinx.serialization.Serializable
45

6+
@OptIn(ExperimentalSerializationApi::class)
57
internal class BidiGenerateContentClientMessage(
68
val model: String,
79
val generationConfig: LiveGenerationConfig.Internal?,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ public class AudioRecordInitializationFailedException :
189189
public class AudioRecordInvalidBufferSizeException :
190190
FirebaseVertexAIException("Audio Record buffer size is invalid")
191191

192+
/** Handshake failed with the server */
193+
public class BidiServerHandshakeFailed :
194+
FirebaseVertexAIException("Handshake failed with the server.")
195+
192196
/** Catch all case for exceptions not explicitly expected. */
193197
public class UnknownException internal constructor(message: String, cause: Throwable? = null) :
194198
FirebaseVertexAIException(message, cause)

0 commit comments

Comments
 (0)