Skip to content

Commit 3263623

Browse files
authored
[Firebase AI] Deprecate TotalBillableCharacters (#1283)
* [Firebase AI] Deprecate TotalBillableCharacters * Update CountTokensResponse.cs
1 parent 75ebdd4 commit 3263623

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

docs/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ Release Notes
115115
- Analytics: Removed deprecated `FirebaseAnalytics.ParameterGroupId`
116116
and `Parameter.Dispose` methods.
117117
- Auth: Removed deprecated `FirebaseUser.UpdateEmailAsync`.
118+
- Firebase AI: Deprecated `CountTokensResponse.TotalBillableCharacters`, use
119+
`CountTokensResponse.TotalTokens` instead.
118120
- Messaging: Removed deprecated `FirebaseMessage.Dispose`,
119121
`FirebaseNotification.Dispose`, and `MessagingOptions.Dispose` methods.
120122

firebaseai/src/CountTokensResponse.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
using System;
1718
using System.Collections.Generic;
1819
using System.Collections.ObjectModel;
1920
using Google.MiniJSON;
@@ -35,6 +36,12 @@ public readonly struct CountTokensResponse {
3536
/// > Important: This does not include billable image, video or other non-text input. See
3637
/// [Firebase AI pricing](https://firebase.google.com/docs/vertex-ai/pricing) for details.
3738
/// </summary>
39+
/// <remarks>
40+
/// Use TotalTokens instead; Gemini 2.0 series models and newer are always billed by token count.
41+
/// </remarks>
42+
/// @deprecated Use TotalTokens instead; Gemini 2.0 series models and newer are always
43+
/// billed by token count.
44+
[Obsolete("Use TotalTokens instead; Gemini 2.0 series models and newer are always billed by token count.")]
3845
public int? TotalBillableCharacters { get; }
3946

4047
private readonly ReadOnlyCollection<ModalityTokenCount> _promptTokensDetails;
@@ -52,7 +59,9 @@ private CountTokensResponse(int totalTokens,
5259
int? totalBillableCharacters = null,
5360
List<ModalityTokenCount> promptTokensDetails = null) {
5461
TotalTokens = totalTokens;
62+
#pragma warning disable CS0618
5563
TotalBillableCharacters = totalBillableCharacters;
64+
#pragma warning restore CS0618
5665
_promptTokensDetails =
5766
new ReadOnlyCollection<ModalityTokenCount>(promptTokensDetails ?? new List<ModalityTokenCount>());
5867
}

firebaseai/testapp/Assets/Firebase/Sample/FirebaseAI/UIHandlerAutomated.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,6 @@ async Task TestCountTokens(Backend backend) {
627627
CountTokensResponse response = await model.CountTokensAsync("Hello, I am testing CountTokens!");
628628

629629
Assert($"CountTokens TotalTokens {response.TotalTokens}", response.TotalTokens > 0);
630-
// TotalBillableCharacters is only expected to be set with VertexAI.
631-
if (backend == Backend.VertexAI) {
632-
Assert($"CountTokens TotalBillableCharacters {response.TotalBillableCharacters}",
633-
response.TotalBillableCharacters > 0);
634-
}
635630

636631
AssertEq("CountTokens PromptTokenDetails", response.PromptTokensDetails.Count(), 1);
637632
var details = response.PromptTokensDetails.First();
@@ -1014,7 +1009,9 @@ async Task InternalTestCountTokenResponse() {
10141009
CountTokensResponse response = CountTokensResponse.FromJson(json);
10151010

10161011
AssertEq("TotalTokens", response.TotalTokens, 1837);
1012+
#pragma warning disable CS0618
10171013
AssertEq("TotalBillableCharacters", response.TotalBillableCharacters, 117);
1014+
#pragma warning restore CS0618
10181015
List<ModalityTokenCount> details = response.PromptTokensDetails.ToList();
10191016
AssertEq("PromptTokensDetails.Count", details.Count, 2);
10201017
AssertEq("PromptTokensDetails[0].Modality", details[0].Modality, ContentModality.Image);

0 commit comments

Comments
 (0)