Skip to content

Commit cbd9636

Browse files
authored
Add ResponseModality support to GenerationConfig (#6921)
Per [b/414638874](https://b.corp.google.com/issues/414638874), This adds support for `ResponseModality` in `GenerationConfig`. #6901 added this, but it seems it was missed during the migration to `firebase-ai`.
1 parent a879354 commit cbd9636

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

firebase-ai/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
* [fixed] Fixed an issue with `LiveContentResponse` audio data not being present when the model was
1414
interrupted or the turn completed. (#6870)
1515
* [fixed] Fixed an issue with `LiveSession` not converting exceptions to `FirebaseVertexAIException`. (#6870)
16+
* [feature] Add support for specifying response modalities in `GenerationConfig`. (#6921)
1617
* [feature] Added a helper field for getting all the `InlineDataPart` from a `GenerateContentResponse`. (#6922)

firebase-ai/api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ package com.google.firebase.ai.type {
354354
field public Integer? maxOutputTokens;
355355
field public Float? presencePenalty;
356356
field public String? responseMimeType;
357+
field public java.util.List<com.google.firebase.ai.type.ResponseModality>? responseModalities;
357358
field public com.google.firebase.ai.type.Schema? responseSchema;
358359
field public java.util.List<java.lang.String>? stopSequences;
359360
field public Float? temperature;

firebase-ai/src/main/kotlin/com/google/firebase/ai/type/GenerationConfig.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ import kotlinx.serialization.Serializable
7575
* Refer to the
7676
* [Control generated output](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/control-generated-output)
7777
* guide for more details.
78+
*
79+
* @property responseModalities The format of data in which the model should respond with.
7880
*/
7981
public class GenerationConfig
8082
private constructor(
@@ -88,6 +90,7 @@ private constructor(
8890
internal val stopSequences: List<String>?,
8991
internal val responseMimeType: String?,
9092
internal val responseSchema: Schema?,
93+
internal val responseModalities: List<ResponseModality>?,
9194
) {
9295

9396
/**
@@ -115,6 +118,9 @@ private constructor(
115118
* @property responseMimeType See [GenerationConfig.responseMimeType].
116119
*
117120
* @property responseSchema See [GenerationConfig.responseSchema].
121+
*
122+
* @property responseModalities See [GenerationConfig.responseModalities].
123+
*
118124
* @see [generationConfig]
119125
*/
120126
public class Builder {
@@ -128,6 +134,7 @@ private constructor(
128134
@JvmField public var stopSequences: List<String>? = null
129135
@JvmField public var responseMimeType: String? = null
130136
@JvmField public var responseSchema: Schema? = null
137+
@JvmField public var responseModalities: List<ResponseModality>? = null
131138

132139
/** Create a new [GenerationConfig] with the attached arguments. */
133140
public fun build(): GenerationConfig =
@@ -142,6 +149,7 @@ private constructor(
142149
frequencyPenalty = frequencyPenalty,
143150
responseMimeType = responseMimeType,
144151
responseSchema = responseSchema,
152+
responseModalities = responseModalities
145153
)
146154
}
147155

@@ -156,7 +164,8 @@ private constructor(
156164
frequencyPenalty = frequencyPenalty,
157165
presencePenalty = presencePenalty,
158166
responseMimeType = responseMimeType,
159-
responseSchema = responseSchema?.toInternal()
167+
responseSchema = responseSchema?.toInternal(),
168+
responseModalities = responseModalities?.map { it.toInternal() }
160169
)
161170

162171
@Serializable
@@ -171,6 +180,7 @@ private constructor(
171180
@SerialName("presence_penalty") val presencePenalty: Float? = null,
172181
@SerialName("frequency_penalty") val frequencyPenalty: Float? = null,
173182
@SerialName("response_schema") val responseSchema: Schema.Internal? = null,
183+
@SerialName("response_modalities") val responseModalities: List<String>? = null
174184
)
175185

176186
public companion object {

0 commit comments

Comments
 (0)