Skip to content

Commit d4a3068

Browse files
davidmotsonDavid Motsonashvili
andauthored
Davidmotson.google count token modelname (#7011)
Co-authored-by: David Motsonashvili <[email protected]>
1 parent f03fe1c commit d4a3068

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

firebase-ai/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [changed] Introduced the `Voice` class, which accepts a voice name, and deprecated the `Voices` class.
66
* [changed] **Breaking Change**: Updated `SpeechConfig` to take in `Voice` class instead of `Voices` class.
77
* **Action Required:** Update all references of `SpeechConfig` initialization to use `Voice` class.
8+
* [fixed] Fix incorrect model name in count token requests to the developer API backend
89

910

1011
# 16.0.0

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/Request.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.google.firebase.ai.common
1919

2020
import com.google.firebase.ai.common.util.fullModelName
21+
import com.google.firebase.ai.common.util.trimmedModelName
2122
import com.google.firebase.ai.type.Content
2223
import com.google.firebase.ai.type.GenerationConfig
2324
import com.google.firebase.ai.type.ImagenImageFormat
@@ -57,7 +58,7 @@ internal data class CountTokensRequest(
5758
CountTokensRequest(
5859
generateContentRequest =
5960
generateContentRequest.model?.let {
60-
generateContentRequest.copy(model = fullModelName(it))
61+
generateContentRequest.copy(model = fullModelName(trimmedModelName(it)))
6162
}
6263
?: generateContentRequest
6364
)

firebase-ai/src/main/kotlin/com/google/firebase/ai/common/util/util.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ package com.google.firebase.ai.common.util
2323
*/
2424
internal fun fullModelName(name: String): String =
2525
name.takeIf { it.contains("/") } ?: "models/$name"
26+
27+
internal fun trimmedModelName(name: String): String = name.split("/").last()

0 commit comments

Comments
 (0)