Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion firebase-vertexai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

* [changed] **Breaking Change**: `LiveModelFutures.connect` now returns `ListenableFuture<LiveSessionFutures>` instead of `ListenableFuture<LiveSession>`.
* **Action Required:** Remove any transformations from LiveSession object to LiveSessionFutures.
* **Action Required:** Change type of variable handling `LiveModelFutures.connect` to `ListenableFuture<LiveSessionsFutures>`
* [changed] **Breaking Change**: Removed `UNSPECIFIED` value for enum class `ResponseModality`
* **Action Required:** Remove all references to `ResponseModality.UNSPECIFIED`
* [changed] **Breaking Change**: Renamed `LiveGenerationConfig.setResponseModalities` to `LiveGenerationConfig.setResponseModality`
* **Action Required:** Replace all references of `LiveGenerationConfig.setResponseModalities` with `LiveGenerationConfig.setResponseModality`

# 16.3.0
* [feature] Emits a warning when attempting to use an incompatible model with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.google.firebase.vertexai.java
import androidx.concurrent.futures.SuspendToFutureAdapter
import com.google.common.util.concurrent.ListenableFuture
import com.google.firebase.vertexai.LiveGenerativeModel
import com.google.firebase.vertexai.type.LiveSession
import com.google.firebase.vertexai.type.PublicPreviewAPI
import com.google.firebase.vertexai.type.ServiceConnectionHandshakeFailedException

Expand All @@ -32,16 +31,16 @@ import com.google.firebase.vertexai.type.ServiceConnectionHandshakeFailedExcepti
public abstract class LiveModelFutures internal constructor() {

/**
* Start a [LiveSession] with the server for bidirectional streaming.
* @return A [LiveSession] that you can use to stream messages to and from the server.
* Start a [LiveSessionFutures] with the server for bidirectional streaming.
* @return A [LiveSessionFutures] that you can use to stream messages to and from the server.
* @throws [ServiceConnectionHandshakeFailedException] If the client was not able to establish a
* connection with the server.
*/
public abstract fun connect(): ListenableFuture<LiveSession>
public abstract fun connect(): ListenableFuture<LiveSessionFutures>

private class FuturesImpl(private val model: LiveGenerativeModel) : LiveModelFutures() {
override fun connect(): ListenableFuture<LiveSession> {
return SuspendToFutureAdapter.launchFuture { model.connect() }
override fun connect(): ListenableFuture<LiveSessionFutures> {
return SuspendToFutureAdapter.launchFuture { LiveSessionFutures.from(model.connect()) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public abstract class LiveSessionFutures internal constructor() {
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)?
): ListenableFuture<Unit>

/**
* Starts an audio conversation with the Gemini server, which can only be stopped using
* [stopAudioConversation].
*/
public abstract fun startAudioConversation(): ListenableFuture<Unit>

/**
* Stops the audio conversation with the Gemini Server.
*
Expand Down Expand Up @@ -124,6 +130,9 @@ public abstract class LiveSessionFutures internal constructor() {
functionCallHandler: ((FunctionCallPart) -> FunctionResponsePart)?
) = SuspendToFutureAdapter.launchFuture { session.startAudioConversation(functionCallHandler) }

override fun startAudioConversation() =
SuspendToFutureAdapter.launchFuture { session.startAudioConversation() }

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ private constructor(
public fun setFrequencyPenalty(frequencyPenalty: Float?): Builder = apply {
this.frequencyPenalty = frequencyPenalty
}
public fun setResponseModalities(responseModalities: ResponseModality?): Builder = apply {
this.responseModality = responseModalities
public fun setResponseModality(responseModality: ResponseModality?): Builder = apply {
this.responseModality = responseModality
}
public fun setSpeechConfig(speechConfig: SpeechConfig?): Builder = apply {
this.speechConfig = speechConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package com.google.firebase.vertexai.type

import com.google.firebase.vertexai.common.util.FirstOrdinalSerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/** Modality for bidirectional streaming. */
Expand All @@ -27,7 +26,6 @@ public class ResponseModality private constructor(public val ordinal: Int) {

@Serializable(Internal.Serializer::class)
internal enum class Internal {
@SerialName("MODALITY_UNSPECIFIED") UNSPECIFIED,
TEXT,
IMAGE,
AUDIO;
Expand All @@ -38,29 +36,24 @@ public class ResponseModality private constructor(public val ordinal: Int) {
when (this) {
TEXT -> ResponseModality.TEXT
IMAGE -> ResponseModality.IMAGE
AUDIO -> ResponseModality.AUDIO
else -> ResponseModality.UNSPECIFIED
else -> ResponseModality.AUDIO
}
}

internal fun toInternal() =
when (this) {
TEXT -> "TEXT"
IMAGE -> "IMAGE"
AUDIO -> "AUDIO"
else -> "UNSPECIFIED"
else -> "AUDIO"
}
public companion object {
/** Unspecified modality. */
@JvmField public val UNSPECIFIED: ResponseModality = ResponseModality(0)

/** Plain text. */
@JvmField public val TEXT: ResponseModality = ResponseModality(1)
@JvmField public val TEXT: ResponseModality = ResponseModality(0)

/** Image. */
@JvmField public val IMAGE: ResponseModality = ResponseModality(2)
@JvmField public val IMAGE: ResponseModality = ResponseModality(1)

/** Audio. */
@JvmField public val AUDIO: ResponseModality = ResponseModality(4)
@JvmField public val AUDIO: ResponseModality = ResponseModality(2)
}
}