Skip to content

Commit ebc8488

Browse files
authored
Merge branch 'main' into daymon-fix-tests
2 parents 83a513a + cbd9636 commit ebc8488

File tree

7 files changed

+37
-6
lines changed

7 files changed

+37
-6
lines changed

firebase-ai/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +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)
17+
* [feature] Added a helper field for getting all the `InlineDataPart` from a `GenerateContentResponse`. (#6922)

firebase-ai/api.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,13 @@ package com.google.firebase.ai.type {
330330
ctor public GenerateContentResponse(java.util.List<com.google.firebase.ai.type.Candidate> candidates, com.google.firebase.ai.type.PromptFeedback? promptFeedback, com.google.firebase.ai.type.UsageMetadata? usageMetadata);
331331
method public java.util.List<com.google.firebase.ai.type.Candidate> getCandidates();
332332
method public java.util.List<com.google.firebase.ai.type.FunctionCallPart> getFunctionCalls();
333+
method public java.util.List<com.google.firebase.ai.type.InlineDataPart> getInlineDataParts();
333334
method public com.google.firebase.ai.type.PromptFeedback? getPromptFeedback();
334335
method public String? getText();
335336
method public com.google.firebase.ai.type.UsageMetadata? getUsageMetadata();
336337
property public final java.util.List<com.google.firebase.ai.type.Candidate> candidates;
337338
property public final java.util.List<com.google.firebase.ai.type.FunctionCallPart> functionCalls;
339+
property public final java.util.List<com.google.firebase.ai.type.InlineDataPart> inlineDataParts;
338340
property public final com.google.firebase.ai.type.PromptFeedback? promptFeedback;
339341
property public final String? text;
340342
property public final com.google.firebase.ai.type.UsageMetadata? usageMetadata;
@@ -352,6 +354,7 @@ package com.google.firebase.ai.type {
352354
field public Integer? maxOutputTokens;
353355
field public Float? presencePenalty;
354356
field public String? responseMimeType;
357+
field public java.util.List<com.google.firebase.ai.type.ResponseModality>? responseModalities;
355358
field public com.google.firebase.ai.type.Schema? responseSchema;
356359
field public java.util.List<java.lang.String>? stopSequences;
357360
field public Float? temperature;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ public class GenerateContentResponse(
4444
candidates.first().content.parts.filterIsInstance<FunctionCallPart>()
4545
}
4646

47+
/**
48+
* Convenience field representing all the [InlineDataPart]s in the first candidate, if they exist.
49+
*
50+
* This also includes any [ImagePart], but they will be represented as [InlineDataPart] instead.
51+
*/
52+
public val inlineDataParts: List<InlineDataPart> by lazy {
53+
candidates.first().content.parts.let { parts ->
54+
parts.filterIsInstance<ImagePart>().map { it.toInlineDataPart() } +
55+
parts.filterIsInstance<InlineDataPart>()
56+
}
57+
}
58+
4759
@Serializable
4860
internal data class Internal(
4961
val candidates: List<Candidate.Internal>? = null,

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

Lines changed: 11 additions & 1 deletion
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 {

plugins/src/main/java/com/google/firebase/gradle/plugins/PostReleasePlugin.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class PostReleasePlugin : Plugin<Project> {
6565
fun registerVersionBumpTask(project: Project) =
6666
project.tasks.register<VersionBumpTask>("versionBump") {
6767
// TODO(b/285892320): Remove condition when bug fixed
68-
bumpVersion.set(project.firebaseLibrary.artifactId.map {
69-
it !== "protolite-well-known-types"
70-
})
68+
bumpVersion.set(
69+
project.firebaseLibrary.artifactId.map { it !== "protolite-well-known-types" }
70+
)
7171
}
7272

7373
/**

plugins/src/main/java/com/google/firebase/gradle/plugins/PublishingPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ abstract class PublishingPlugin : Plugin<Project> {
418418
"com.google.firebase:firebase-crashlytics",
419419
"com.google.firebase:firebase-perf",
420420
"com.google.firebase:firebase-vertexai",
421+
"com.google.firebase:firebase-ai",
421422
"com.google.firebase:firebase-messaging",
422423
"com.google.firebase:firebase-auth",
423424
"com.google.firebase:firebase-database",
@@ -816,6 +817,7 @@ abstract class PublishingPlugin : Plugin<Project> {
816817
"com.google.firebase:firebase-storage",
817818
"com.google.firebase:firebase-storage-ktx",
818819
"com.google.firebase:firebase-vertexai",
820+
"com.google.firebase:firebase-ai",
819821
)
820822

821823
/** Artifacts that we use in the tutorial bundle, but _not_ in the bom. */

plugins/src/main/java/com/google/firebase/gradle/plugins/VersionBumpTask.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import org.gradle.kotlin.dsl.provideDelegate
4040
* version.
4141
* @property newVersion A [ModuleVersion] of what to set the version to. Defaults to one patch
4242
* higher than [releasedVersion].
43-
* @property bumpVersion If set, then the default provided by [newVersion] will be bumped by one patch. Defaults to `true`.
43+
* @property bumpVersion If set, then the default provided by [newVersion] will be bumped by one
44+
* patch. Defaults to `true`.
4445
* @see PostReleasePlugin
4546
*/
4647
abstract class VersionBumpTask : DefaultTask() {
@@ -63,7 +64,8 @@ abstract class VersionBumpTask : DefaultTask() {
6364
@TaskAction
6465
fun build() {
6566
val latestVersion = releasedVersion.get()
66-
val version = newVersion.orNull ?: if(bumpVersion.get()) latestVersion.bump() else latestVersion
67+
val version =
68+
newVersion.orNull ?: if (bumpVersion.get()) latestVersion.bump() else latestVersion
6769

6870
versionFile.get().asFile.rewriteLines {
6971
when {

0 commit comments

Comments
 (0)