Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/com/google/genai/Models.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -41,6 +45,13 @@ public abstract class ContentEmbeddingStatistics extends JsonSerializable {
@JsonProperty("tokenCount")
public abstract Optional<Float> tokenCount();

/**
* Gemini Enterprise Agent Platform only. List of modalities and their token count for the input
* content.
*/
@JsonProperty("tokensDetails")
public abstract Optional<List<ModalityTokenCount>> tokensDetails();

/** Instantiates a builder for ContentEmbeddingStatistics. */
@ExcludeFromGeneratedCoverageReport
public static Builder builder() {
Expand Down Expand Up @@ -96,6 +107,50 @@ public Builder clearTokenCount() {
return tokenCount(Optional.empty());
}

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

/**
* Setter for tokensDetails.
*
* <p>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.
*
* <p>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<List<ModalityTokenCount>> tokensDetails);

/** Clears the value of tokensDetails field. */
@ExcludeFromGeneratedCoverageReport
@CanIgnoreReturnValue
public Builder clearTokensDetails() {
return tokensDetails(Optional.empty());
}

public abstract ContentEmbeddingStatistics build();
}

Expand Down
Loading