Class Candidate
-
- All Implemented Interfaces:
public abstract class Candidate extends JsonSerializable
A response candidate generated from the model.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public abstract classCandidate.BuilderBuilder for Candidate.
-
Field Summary
Fields Modifier and Type Field Description public final static StringMAX_READ_LENGTH_PROPERTY
-
Constructor Summary
Constructors Constructor Description Candidate()
-
Method Summary
Modifier and Type Method Description abstract Optional<Content>content()Contains the multi-part content of the response. abstract Optional<CitationMetadata>citationMetadata()Source attribution of the generated content. abstract Optional<String>finishMessage()Describes the reason the model stopped generating tokens. abstract Optional<Integer>tokenCount()Number of tokens for this candidate. abstract Optional<FinishReason>finishReason()The reason why the model stopped generating tokens. abstract Optional<GroundingMetadata>groundingMetadata()Output only. abstract Optional<Double>avgLogprobs()Output only. abstract Optional<Integer>index()Output only. abstract Optional<LogprobsResult>logprobsResult()Output only. abstract Optional<List<SafetyRating>>safetyRatings()Output only. abstract Optional<UrlContextMetadata>urlContextMetadata()Output only. static Candidate.Builderbuilder()Instantiates a builder for Candidate. abstract Candidate.BuildertoBuilder()Creates a builder with the same values as this instance. static CandidatefromJson(String jsonString)Deserializes a JSON string to a Candidate object. -
Methods inherited from class com.google.genai.JsonSerializable
fromJsonNode, fromJsonString, objectMapper, setMaxReadLength, stringToJsonNode, toJson, toJsonNode, toJsonString -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
citationMetadata
abstract Optional<CitationMetadata> citationMetadata()
Source attribution of the generated content.
-
finishMessage
abstract Optional<String> finishMessage()
Describes the reason the model stopped generating tokens.
-
tokenCount
abstract Optional<Integer> tokenCount()
Number of tokens for this candidate.
-
finishReason
abstract Optional<FinishReason> finishReason()
The reason why the model stopped generating tokens. If empty, the model has not stopped generating the tokens.
-
groundingMetadata
abstract Optional<GroundingMetadata> groundingMetadata()
Output only. Metadata returned when grounding is enabled. It contains the sources used to ground the generated content.
-
avgLogprobs
abstract Optional<Double> avgLogprobs()
Output only. The average log probability of the tokens in this candidate. This is a length-normalized score that can be used to compare the quality of candidates of different lengths. A higher average log probability suggests a more confident and coherent response.
-
index
abstract Optional<Integer> index()
Output only. The 0-based index of this candidate in the list of generated responses. This is useful for distinguishing between multiple candidates when `candidate_count` >1.
-
logprobsResult
abstract Optional<LogprobsResult> logprobsResult()
Output only. The detailed log probability information for the tokens in this candidate. This is useful for debugging, understanding model uncertainty, and identifying potential "hallucinations".
-
safetyRatings
abstract Optional<List<SafetyRating>> safetyRatings()
Output only. A list of ratings for the safety of a response candidate. There is at most one rating per category.
-
urlContextMetadata
abstract Optional<UrlContextMetadata> urlContextMetadata()
Output only. Metadata returned when the model uses the `url_context` tool to get information from a user-provided URL.
-
builder
static Candidate.Builder builder()
Instantiates a builder for Candidate.
-
toBuilder
abstract Candidate.Builder toBuilder()
Creates a builder with the same values as this instance.
-
-
-
-