Skip to content

Commit c607b04

Browse files
speedstorm1copybara-github
authored andcommitted
feat: Populate per-modality prompt token count in embedding responses for gemini-embedding-2
PiperOrigin-RevId: 940552765
1 parent d244d90 commit c607b04

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Google.GenAI/Models.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ internal JsonNode ContentEmbeddingStatisticsFromVertex(JsonNode fromObject,
308308
Common.GetValueByPath(fromObject, new string[] { "token_count" }));
309309
}
310310

311+
if (Common.GetValueByPath(fromObject, new string[] { "tokensDetails" }) != null) {
312+
Common.SetValueByPath(toObject, new string[] { "tokensDetails" },
313+
Common.GetValueByPath(fromObject, new string[] { "tokensDetails" }));
314+
}
315+
311316
return toObject;
312317
}
313318

@@ -1059,6 +1064,10 @@ internal JsonNode EmbedContentResponseFromVertex(JsonNode fromObject, JsonObject
10591064
stats.Add("token_count",
10601065
JsonNode.Parse(usageMetadata["promptTokenCount"].ToJsonString()));
10611066
}
1067+
if (usageMetadata != null && usageMetadata["promptTokensDetails"] != null) {
1068+
stats.Add("tokensDetails",
1069+
JsonNode.Parse(usageMetadata["promptTokensDetails"].ToJsonString()));
1070+
}
10621071
if (truncated != null) {
10631072
stats.Add("truncated", JsonNode.Parse(truncated.ToJsonString()));
10641073
}

Google.GenAI/types/ContentEmbeddingStatistics.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ public double
4545
get; set;
4646
}
4747

48+
/// <summary>
49+
/// Gemini Enterprise Agent Platform only. List of modalities and their token count for the
50+
/// input content.
51+
/// </summary>
52+
[JsonPropertyName("tokensDetails")]
53+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
54+
public List<ModalityTokenCount>
55+
? TokensDetails {
56+
get; set;
57+
}
58+
4859
/// <summary>
4960
/// Deserializes a JSON string to a ContentEmbeddingStatistics object.
5061
/// </summary>

0 commit comments

Comments
 (0)