Skip to content

Commit 8a4aa9f

Browse files
authored
Merge branch 'main' into davidmotson.update_vertex_enums
2 parents fe48d78 + d9baf9e commit 8a4aa9f

File tree

12 files changed

+277
-38
lines changed

12 files changed

+277
-38
lines changed

.github/workflows/dataconnect.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,21 @@ jobs:
8484
- name: tool versions
8585
continue-on-error: true
8686
run: |
87-
set +e -v
88-
uname -a
89-
which java
90-
java -version
91-
which javac
92-
javac -version
93-
which node
94-
node --version
95-
${{ env.FDC_FIREBASE_COMMAND }} --version
96-
./gradlew --version
87+
function run_cmd {
88+
echo "==============================================================================="
89+
echo "Running Command: $*"
90+
("$@" 2>&1) || echo "WARNING: command failed with non-zero exit code $?: $*"
91+
}
92+
93+
run_cmd uname -a
94+
run_cmd which java
95+
run_cmd java -version
96+
run_cmd which javac
97+
run_cmd javac -version
98+
run_cmd which node
99+
run_cmd node --version
100+
run_cmd ${{ env.FDC_FIREBASE_COMMAND }} --version
101+
run_cmd ./gradlew --version
97102
98103
- name: Gradle assembleDebugAndroidTest
99104
run: |
@@ -116,7 +121,7 @@ jobs:
116121
path: |
117122
~/.gradle/caches
118123
~/.gradle/wrapper
119-
key: gradle-cache-jqnvfzw6w7
124+
key: gradle-cache-jqnvfzw6w7-${{ github.run_id }}
120125

121126
- name: Enable KVM group permissions for Android Emulator
122127
run: |
@@ -155,7 +160,7 @@ jobs:
155160
path: |
156161
~/.android/avd/*
157162
~/.android/adb*
158-
key: avd-cache-zhdsn586je-api${{ env.FDC_ANDROID_EMULATOR_API_LEVEL }}
163+
key: avd-cache-zhdsn586je-api${{ env.FDC_ANDROID_EMULATOR_API_LEVEL }}-${{ github.run_id }}
159164

160165
- name: Data Connect Emulator
161166
run: |

.github/workflows/dataconnect_demo_app.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,20 @@ jobs:
8989
- name: tool versions
9090
continue-on-error: true
9191
run: |
92-
set +e -v
93-
which java
94-
java -version
95-
which javac
96-
javac -version
97-
which node
98-
node --version
99-
${{ env.FDC_FIREBASE_COMMAND }} --version
100-
./gradlew --version
92+
function run_cmd {
93+
echo "==============================================================================="
94+
echo "Running Command: $*"
95+
("$@" 2>&1) || echo "WARNING: command failed with non-zero exit code $?: $*"
96+
}
97+
98+
run_cmd which java
99+
run_cmd java -version
100+
run_cmd which javac
101+
run_cmd javac -version
102+
run_cmd which node
103+
run_cmd node --version
104+
run_cmd ${{ env.FDC_FIREBASE_COMMAND }} --version
105+
run_cmd ./gradlew --version
101106
102107
- name: ./gradlew assemble test
103108
run: |

firebase-dataconnect/gradleplugin/plugin/src/main/resources/com/google/firebase/dataconnect/gradle/plugin/DataConnectExecutableVersions.json

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"defaultVersion": "1.7.5",
2+
"defaultVersion": "1.7.7",
33
"versions": [
44
{
55
"version": "1.3.4",
@@ -378,6 +378,42 @@
378378
"os": "linux",
379379
"size": 25190552,
380380
"sha512DigestHex": "14ec28595c1ebb2a7870e09c00c6401bebbe8b3ae56cdcc63e34cb86c1b0ec7ab359a16fb7d93f19b552343b0bd004f0990b847abee0b5feb19a720d48548432"
381+
},
382+
{
383+
"version": "1.7.6",
384+
"os": "windows",
385+
"size": 25752064,
386+
"sha512DigestHex": "c0541157251660c4fede1b021042f54ce15d885c4e2689316aaebf7903e6783e531b0c632f20dbe43b996e6a63dfa7d49c7b03d5c932248fcb95f3767a9ab4ac"
387+
},
388+
{
389+
"version": "1.7.6",
390+
"os": "macos",
391+
"size": 25322240,
392+
"sha512DigestHex": "5e9142bbcc4475a905c4b2e999998d7c450ec0852049012d8eefca7f264a1c880e9872d6fbb59fe770dd9388268b637a2011641173028bbbd4ddad71e8028d62"
393+
},
394+
{
395+
"version": "1.7.6",
396+
"os": "linux",
397+
"size": 25235608,
398+
"sha512DigestHex": "f55a259fdeaba503ff0f5202fbb2062619c14bc140c4c220d10c395bf8a587bc4352064d5f0800d52cb085d951460ebffdad26cfeb893894e655d0d74056e998"
399+
},
400+
{
401+
"version": "1.7.7",
402+
"os": "windows",
403+
"size": 25788416,
404+
"sha512DigestHex": "be114a86491cf0317e25437777febce6b2057ea4c1a4b1d26939d188091c3b1da19aeed7fcaa5085c687497842ee8330e1b623686899e0c7615340faa2b6eeff"
405+
},
406+
{
407+
"version": "1.7.7",
408+
"os": "macos",
409+
"size": 25359104,
410+
"sha512DigestHex": "009ade041a6c152b9657add2ad03f5e12058224679eef39cabeee0579c907a9be22e9ad212515e52491fbacd0aa477e6afd1684c0cddea037a76ba143ddc1b32"
411+
},
412+
{
413+
"version": "1.7.7",
414+
"os": "linux",
415+
"size": 25268376,
416+
"sha512DigestHex": "f55feb1ce670b4728bb30be138ab427545f77f63f9e11ee458096091c075699c647d5b768c642a1ef6b3569a2db87dbbed6f2fdaf64febd1154d1a730fda4a9c"
381417
}
382418
]
383419
}

firebase-vertexai/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unreleased
22
* [fixed] Added support for new values sent by the server for `FinishReason` and `BlockReason`
3-
3+
* [changed] Added support for modality-based token count. (#6658)
44

55
# 16.1.0
66
* [changed] Internal improvements to correctly handle empty model responses.
@@ -65,4 +65,3 @@
6565
* [feature] Added support for `responseMimeType` in `GenerationConfig`.
6666
* [changed] Renamed `GoogleGenerativeAIException` to `FirebaseVertexAIException`.
6767
* [changed] Updated the KDocs for various classes and functions.
68-

firebase-vertexai/api.txt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,30 @@ package com.google.firebase.vertexai.type {
167167
method public static com.google.firebase.vertexai.type.Content content(String? role = "user", kotlin.jvm.functions.Function1<? super com.google.firebase.vertexai.type.Content.Builder,kotlin.Unit> init);
168168
}
169169

170+
public final class ContentModality {
171+
method public int getOrdinal();
172+
property public final int ordinal;
173+
field public static final com.google.firebase.vertexai.type.ContentModality AUDIO;
174+
field public static final com.google.firebase.vertexai.type.ContentModality.Companion Companion;
175+
field public static final com.google.firebase.vertexai.type.ContentModality DOCUMENT;
176+
field public static final com.google.firebase.vertexai.type.ContentModality IMAGE;
177+
field public static final com.google.firebase.vertexai.type.ContentModality TEXT;
178+
field public static final com.google.firebase.vertexai.type.ContentModality UNSPECIFIED;
179+
field public static final com.google.firebase.vertexai.type.ContentModality VIDEO;
180+
}
181+
182+
public static final class ContentModality.Companion {
183+
}
184+
170185
public final class CountTokensResponse {
171-
ctor public CountTokensResponse(int totalTokens, Integer? totalBillableCharacters = null);
186+
ctor public CountTokensResponse(int totalTokens, Integer? totalBillableCharacters = null, java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? promptTokensDetails = null);
172187
method public operator int component1();
173188
method public operator Integer? component2();
189+
method public operator java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? component3();
190+
method public java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? getPromptTokensDetails();
174191
method public Integer? getTotalBillableCharacters();
175192
method public int getTotalTokens();
193+
property public final java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? promptTokensDetails;
176194
property public final Integer? totalBillableCharacters;
177195
property public final int totalTokens;
178196
}
@@ -375,6 +393,15 @@ package com.google.firebase.vertexai.type {
375393
public final class InvalidStateException extends com.google.firebase.vertexai.type.FirebaseVertexAIException {
376394
}
377395

396+
public final class ModalityTokenCount {
397+
method public operator com.google.firebase.vertexai.type.ContentModality component1();
398+
method public operator int component2();
399+
method public com.google.firebase.vertexai.type.ContentModality getModality();
400+
method public int getTokenCount();
401+
property public final com.google.firebase.vertexai.type.ContentModality modality;
402+
property public final int tokenCount;
403+
}
404+
378405
public interface Part {
379406
}
380407

@@ -555,12 +582,16 @@ package com.google.firebase.vertexai.type {
555582
}
556583

557584
public final class UsageMetadata {
558-
ctor public UsageMetadata(int promptTokenCount, Integer? candidatesTokenCount, int totalTokenCount);
585+
ctor public UsageMetadata(int promptTokenCount, Integer? candidatesTokenCount, int totalTokenCount, java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? promptTokensDetails, java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? candidatesTokensDetails);
559586
method public Integer? getCandidatesTokenCount();
587+
method public java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? getCandidatesTokensDetails();
560588
method public int getPromptTokenCount();
589+
method public java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? getPromptTokensDetails();
561590
method public int getTotalTokenCount();
562591
property public final Integer? candidatesTokenCount;
592+
property public final java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? candidatesTokensDetails;
563593
property public final int promptTokenCount;
594+
property public final java.util.List<com.google.firebase.vertexai.type.ModalityTokenCount>? promptTokensDetails;
564595
property public final int totalTokenCount;
565596
}
566597

firebase-vertexai/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
version=16.1.1
15+
version=16.2.0
1616
latestReleasedVersion=16.1.0
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.vertexai.type
18+
19+
import com.google.firebase.vertexai.common.util.FirstOrdinalSerializer
20+
import kotlinx.serialization.KSerializer
21+
import kotlinx.serialization.SerialName
22+
import kotlinx.serialization.Serializable
23+
24+
/** Content part modality. */
25+
public class ContentModality private constructor(public val ordinal: Int) {
26+
27+
@Serializable(Internal.Serializer::class)
28+
internal enum class Internal {
29+
@SerialName("MODALITY_UNSPECIFIED") UNSPECIFIED,
30+
TEXT,
31+
IMAGE,
32+
VIDEO,
33+
AUDIO,
34+
DOCUMENT;
35+
36+
internal object Serializer : KSerializer<Internal> by FirstOrdinalSerializer(Internal::class)
37+
38+
internal fun toPublic() =
39+
when (this) {
40+
TEXT -> ContentModality.TEXT
41+
IMAGE -> ContentModality.IMAGE
42+
VIDEO -> ContentModality.VIDEO
43+
AUDIO -> ContentModality.AUDIO
44+
DOCUMENT -> ContentModality.DOCUMENT
45+
else -> ContentModality.UNSPECIFIED
46+
}
47+
}
48+
49+
public companion object {
50+
/** Unspecified modality. */
51+
@JvmField public val UNSPECIFIED: ContentModality = ContentModality(0)
52+
53+
/** Plain text. */
54+
@JvmField public val TEXT: ContentModality = ContentModality(1)
55+
56+
/** Image. */
57+
@JvmField public val IMAGE: ContentModality = ContentModality(2)
58+
59+
/** Video. */
60+
@JvmField public val VIDEO: ContentModality = ContentModality(3)
61+
62+
/** Audio. */
63+
@JvmField public val AUDIO: ContentModality = ContentModality(4)
64+
65+
/** Document, e.g. PDF. */
66+
@JvmField public val DOCUMENT: ContentModality = ContentModality(5)
67+
}
68+
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,33 @@ import kotlinx.serialization.Serializable
3030
* to the model as a prompt. **Important:** this property does not include billable image, video or
3131
* other non-text input. See
3232
* [Vertex AI pricing](https://cloud.google.com/vertex-ai/generative-ai/pricing) for details.
33+
* @property promptTokensDetails The breakdown, by modality, of how many tokens are consumed by the
34+
* prompt.
3335
*/
3436
public class CountTokensResponse(
3537
public val totalTokens: Int,
36-
public val totalBillableCharacters: Int? = null
38+
public val totalBillableCharacters: Int? = null,
39+
public val promptTokensDetails: List<ModalityTokenCount>? = null,
3740
) {
3841
public operator fun component1(): Int = totalTokens
3942

4043
public operator fun component2(): Int? = totalBillableCharacters
4144

45+
public operator fun component3(): List<ModalityTokenCount>? = promptTokensDetails
46+
4247
@Serializable
43-
internal data class Internal(val totalTokens: Int, val totalBillableCharacters: Int? = null) :
44-
Response {
48+
internal data class Internal(
49+
val totalTokens: Int,
50+
val totalBillableCharacters: Int? = null,
51+
val promptTokensDetails: List<ModalityTokenCount.Internal>? = null
52+
) : Response {
4553

4654
internal fun toPublic(): CountTokensResponse {
47-
return CountTokensResponse(totalTokens, totalBillableCharacters ?: 0)
55+
return CountTokensResponse(
56+
totalTokens,
57+
totalBillableCharacters ?: 0,
58+
promptTokensDetails?.map { it.toPublic() }
59+
)
4860
}
4961
}
5062
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.vertexai.type
18+
19+
import kotlinx.serialization.Serializable
20+
21+
/**
22+
* Represents token counting info for a single modality.
23+
*
24+
* @property modality The modality associated with this token count.
25+
* @property tokenCount The number of tokens counted.
26+
*/
27+
public class ModalityTokenCount
28+
private constructor(public val modality: ContentModality, public val tokenCount: Int) {
29+
30+
public operator fun component1(): ContentModality = modality
31+
32+
public operator fun component2(): Int = tokenCount
33+
34+
@Serializable
35+
internal data class Internal(
36+
val modality: ContentModality.Internal,
37+
val tokenCount: Int? = null
38+
) {
39+
internal fun toPublic() = ModalityTokenCount(modality.toPublic(), tokenCount ?: 0)
40+
}
41+
}

0 commit comments

Comments
 (0)