diff --git a/firebase-vertexai/CHANGELOG.md b/firebase-vertexai/CHANGELOG.md index b7db00bdde2..d4aab80d601 100644 --- a/firebase-vertexai/CHANGELOG.md +++ b/firebase-vertexai/CHANGELOG.md @@ -14,6 +14,8 @@ interrupted or the turn completed. (#6870) * [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870) * [feature] Enable response generation in multiple modalities. (#6901) +* [changed] Removed the `LiveContentResponse.Status` class, and instead have nested the status + fields as properties of `LiveContentResponse`. (#6906) # 16.3.0 diff --git a/firebase-vertexai/api.txt b/firebase-vertexai/api.txt index cb3d14904b3..dac472f2a0c 100644 --- a/firebase-vertexai/api.txt +++ b/firebase-vertexai/api.txt @@ -569,25 +569,14 @@ package com.google.firebase.vertexai.type { @com.google.firebase.vertexai.type.PublicPreviewAPI public final class LiveContentResponse { method public com.google.firebase.vertexai.type.Content? getData(); method public java.util.List? getFunctionCalls(); - method public int getStatus(); + method public Boolean? getInterrupted(); method public String? getText(); + method public Boolean? getTurnComplete(); property public final com.google.firebase.vertexai.type.Content? data; property public final java.util.List? functionCalls; - property public final int status; + property public final Boolean? interrupted; property public final String? text; - } - - @kotlin.jvm.JvmInline public static final value class LiveContentResponse.Status { - field public static final com.google.firebase.vertexai.type.LiveContentResponse.Status.Companion Companion; - } - - public static final class LiveContentResponse.Status.Companion { - method public int getINTERRUPTED(); - method public int getNORMAL(); - method public int getTURN_COMPLETE(); - property public final int INTERRUPTED; - property public final int NORMAL; - property public final int TURN_COMPLETE; + property public final Boolean? turnComplete; } @com.google.firebase.vertexai.type.PublicPreviewAPI public final class LiveGenerationConfig { diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveContentResponse.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveContentResponse.kt index b09beb0fe29..4ae1d5df255 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveContentResponse.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveContentResponse.kt @@ -30,10 +30,19 @@ internal constructor( public val data: Content?, /** - * The status of the live content response. Indicates whether the response is normal, was - * interrupted, or signifies the completion of a turn. + * The model was interrupted while generating data. + * + * An interruption occurs when the client sends a message while the model is actively sending + * data. + */ + public val interrupted: Boolean?, + + /** + * The model has finished sending data in the current interaction. + * + * Can be set alongside content, signifying that the content is the last in the turn. */ - public val status: Status, + public val turnComplete: Boolean?, /** * A list of [FunctionCallPart] included in the response, if any. @@ -49,26 +58,4 @@ internal constructor( */ public val text: String? = data?.parts?.filterIsInstance()?.joinToString(" ") { it.text } - - /** Represents the status of a [LiveContentResponse], within a single interaction. */ - @JvmInline - public value class Status private constructor(private val value: Int) { - public companion object { - /** The server is actively sending data for the current interaction. */ - public val NORMAL: Status = Status(0) - /** - * The server was interrupted while generating data. - * - * An interruption occurs when the client sends a message while the server is [actively] - * [NORMAL] sending data. - */ - public val INTERRUPTED: Status = Status(1) - /** - * The model has finished sending data in the current interaction. - * - * Can be set alongside content, signifying that the content is the last in the turn. - */ - public val TURN_COMPLETE: Status = Status(2) - } - } } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt index 30bd92c6043..e7d00714548 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/LiveSession.kt @@ -310,7 +310,7 @@ internal constructor( ) { receive() .transform { - if (it.status == LiveContentResponse.Status.INTERRUPTED) { + if (it.interrupted == true) { playBackQueue.clear() } else { emit(it) @@ -387,7 +387,8 @@ internal constructor( JSON.decodeFromJsonElement(jsonMessage) LiveContentResponse( null, - LiveContentResponse.Status.NORMAL, + null, + null, functionContent.toolCall.functionCalls.map { FunctionCallPart(it.name, it.args.orEmpty().mapValues { x -> x.value ?: JsonNull }) } @@ -397,13 +398,12 @@ internal constructor( val serverContent = JSON.decodeFromJsonElement(jsonMessage) .serverContent - val status = - when { - serverContent.turnComplete == true -> LiveContentResponse.Status.TURN_COMPLETE - serverContent.interrupted == true -> LiveContentResponse.Status.INTERRUPTED - else -> LiveContentResponse.Status.NORMAL - } - LiveContentResponse(serverContent.modelTurn?.toPublic(), status, null) + LiveContentResponse( + serverContent.modelTurn?.toPublic(), + serverContent.interrupted, + serverContent.turnComplete, + null + ) } else -> { Log.w(TAG, "Failed to decode the server response: $jsonMessage")