diff --git a/src/main/java/com/google/genai/Models.java b/src/main/java/com/google/genai/Models.java index 4c3dacd5db4..c276aeba505 100644 --- a/src/main/java/com/google/genai/Models.java +++ b/src/main/java/com/google/genai/Models.java @@ -469,6 +469,13 @@ ObjectNode contentEmbeddingStatisticsFromVertex( Common.getValueByPath(fromObject, new String[] {"token_count"})); } + if (Common.getValueByPath(fromObject, new String[] {"tokensDetails"}) != null) { + Common.setValueByPath( + toObject, + new String[] {"tokensDetails"}, + Common.getValueByPath(fromObject, new String[] {"tokensDetails"})); + } + return toObject; } @@ -1349,6 +1356,9 @@ ObjectNode embedContentResponseFromVertex( if (usageMetadata != null && usageMetadata.get("promptTokenCount") != null) { stats.set("token_count", usageMetadata.get("promptTokenCount")); } + if (usageMetadata != null && usageMetadata.get("promptTokensDetails") != null) { + stats.set("tokensDetails", usageMetadata.get("promptTokensDetails")); + } if (truncated != null) { stats.set("truncated", truncated); } diff --git a/src/main/java/com/google/genai/types/ContentEmbeddingStatistics.java b/src/main/java/com/google/genai/types/ContentEmbeddingStatistics.java index 1aabea9b772..f5715912ab6 100644 --- a/src/main/java/com/google/genai/types/ContentEmbeddingStatistics.java +++ b/src/main/java/com/google/genai/types/ContentEmbeddingStatistics.java @@ -18,12 +18,16 @@ package com.google.genai.types; +import static com.google.common.collect.ImmutableList.toImmutableList; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.google.auto.value.AutoValue; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.genai.JsonSerializable; +import java.util.Arrays; +import java.util.List; import java.util.Optional; /** Statistics of the input text associated with the result of content embedding. */ @@ -41,6 +45,13 @@ public abstract class ContentEmbeddingStatistics extends JsonSerializable { @JsonProperty("tokenCount") public abstract Optional tokenCount(); + /** + * Gemini Enterprise Agent Platform only. List of modalities and their token count for the input + * content. + */ + @JsonProperty("tokensDetails") + public abstract Optional> tokensDetails(); + /** Instantiates a builder for ContentEmbeddingStatistics. */ @ExcludeFromGeneratedCoverageReport public static Builder builder() { @@ -96,6 +107,50 @@ public Builder clearTokenCount() { return tokenCount(Optional.empty()); } + /** + * Setter for tokensDetails. + * + *

tokensDetails: Gemini Enterprise Agent Platform only. List of modalities and their token + * count for the input content. + */ + @JsonProperty("tokensDetails") + public abstract Builder tokensDetails(List tokensDetails); + + /** + * Setter for tokensDetails. + * + *

tokensDetails: Gemini Enterprise Agent Platform only. List of modalities and their token + * count for the input content. + */ + @CanIgnoreReturnValue + public Builder tokensDetails(ModalityTokenCount... tokensDetails) { + return tokensDetails(Arrays.asList(tokensDetails)); + } + + /** + * Setter for tokensDetails builder. + * + *

tokensDetails: Gemini Enterprise Agent Platform only. List of modalities and their token + * count for the input content. + */ + @CanIgnoreReturnValue + public Builder tokensDetails(ModalityTokenCount.Builder... tokensDetailsBuilders) { + return tokensDetails( + Arrays.asList(tokensDetailsBuilders).stream() + .map(ModalityTokenCount.Builder::build) + .collect(toImmutableList())); + } + + @ExcludeFromGeneratedCoverageReport + abstract Builder tokensDetails(Optional> tokensDetails); + + /** Clears the value of tokensDetails field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearTokensDetails() { + return tokensDetails(Optional.empty()); + } + public abstract ContentEmbeddingStatistics build(); }