Class GenerationConfig.Builder
-
- All Implemented Interfaces:
public abstract class GenerationConfig.BuilderBuilder for GenerationConfig.
-
-
Constructor Summary
Constructors Constructor Description GenerationConfig.Builder()
-
Method Summary
Modifier and Type Method Description abstract GenerationConfig.BuildermodelSelectionConfig(ModelSelectionConfig modelSelectionConfig)Setter for modelSelectionConfig. GenerationConfig.BuildermodelSelectionConfig(ModelSelectionConfig.Builder modelSelectionConfigBuilder)Setter for modelSelectionConfig builder. GenerationConfig.BuilderclearModelSelectionConfig()Clears the value of modelSelectionConfig field. abstract GenerationConfig.BuilderresponseJsonSchema(Object responseJsonSchema)Setter for responseJsonSchema. GenerationConfig.BuilderclearResponseJsonSchema()Clears the value of responseJsonSchema field. abstract GenerationConfig.BuilderaudioTimestamp(boolean audioTimestamp)Setter for audioTimestamp. GenerationConfig.BuilderclearAudioTimestamp()Clears the value of audioTimestamp field. abstract GenerationConfig.BuildercandidateCount(Integer candidateCount)Setter for candidateCount. GenerationConfig.BuilderclearCandidateCount()Clears the value of candidateCount field. abstract GenerationConfig.BuilderenableAffectiveDialog(boolean enableAffectiveDialog)Setter for enableAffectiveDialog. GenerationConfig.BuilderclearEnableAffectiveDialog()Clears the value of enableAffectiveDialog field. abstract GenerationConfig.BuilderfrequencyPenalty(Float frequencyPenalty)Setter for frequencyPenalty. GenerationConfig.BuilderclearFrequencyPenalty()Clears the value of frequencyPenalty field. abstract GenerationConfig.Builderlogprobs(Integer logprobs)Setter for logprobs. GenerationConfig.BuilderclearLogprobs()Clears the value of logprobs field. abstract GenerationConfig.BuildermaxOutputTokens(Integer maxOutputTokens)Setter for maxOutputTokens. GenerationConfig.BuilderclearMaxOutputTokens()Clears the value of maxOutputTokens field. abstract GenerationConfig.BuildermediaResolution(MediaResolution mediaResolution)Setter for mediaResolution. GenerationConfig.BuilderclearMediaResolution()Clears the value of mediaResolution field. GenerationConfig.BuildermediaResolution(MediaResolution.Known knownType)Setter for mediaResolution given a known enum. GenerationConfig.BuildermediaResolution(String mediaResolution)Setter for mediaResolution given a string. abstract GenerationConfig.BuilderpresencePenalty(Float presencePenalty)Setter for presencePenalty. GenerationConfig.BuilderclearPresencePenalty()Clears the value of presencePenalty field. abstract GenerationConfig.BuilderresponseLogprobs(boolean responseLogprobs)Setter for responseLogprobs. GenerationConfig.BuilderclearResponseLogprobs()Clears the value of responseLogprobs field. abstract GenerationConfig.BuilderresponseMimeType(String responseMimeType)Setter for responseMimeType. GenerationConfig.BuilderclearResponseMimeType()Clears the value of responseMimeType field. abstract GenerationConfig.BuilderresponseModalities(List<Modality> responseModalities)Setter for responseModalities. GenerationConfig.BuilderresponseModalities(Array<Modality> responseModalities)Setter for responseModalities. GenerationConfig.BuilderclearResponseModalities()Clears the value of responseModalities field. GenerationConfig.BuilderresponseModalities(Array<String> responseModalities)Setter for responseModalities given a varargs of strings. GenerationConfig.BuilderresponseModalities(Array<Modality.Known> knownTypes)Setter for responseModalities given a varargs of known enums. GenerationConfig.BuilderresponseModalitiesFromKnown(List<Modality.Known> knownTypes)Setter for responseModalities given a list of known enums. GenerationConfig.BuilderresponseModalitiesFromString(List<String> responseModalities)Setter for responseModalities given a list of strings. abstract GenerationConfig.BuilderresponseSchema(Schema responseSchema)Setter for responseSchema. GenerationConfig.BuilderresponseSchema(Schema.Builder responseSchemaBuilder)Setter for responseSchema builder. GenerationConfig.BuilderclearResponseSchema()Clears the value of responseSchema field. abstract GenerationConfig.BuilderroutingConfig(GenerationConfigRoutingConfig routingConfig)Setter for routingConfig. GenerationConfig.BuilderroutingConfig(GenerationConfigRoutingConfig.Builder routingConfigBuilder)Setter for routingConfig builder. GenerationConfig.BuilderclearRoutingConfig()Clears the value of routingConfig field. abstract GenerationConfig.Builderseed(Integer seed)Setter for seed. GenerationConfig.BuilderclearSeed()Clears the value of seed field. abstract GenerationConfig.BuilderspeechConfig(SpeechConfig speechConfig)Setter for speechConfig. GenerationConfig.BuilderspeechConfig(SpeechConfig.Builder speechConfigBuilder)Setter for speechConfig builder. GenerationConfig.BuilderclearSpeechConfig()Clears the value of speechConfig field. abstract GenerationConfig.BuilderstopSequences(List<String> stopSequences)Setter for stopSequences. GenerationConfig.BuilderstopSequences(Array<String> stopSequences)Setter for stopSequences. GenerationConfig.BuilderclearStopSequences()Clears the value of stopSequences field. abstract GenerationConfig.Buildertemperature(Float temperature)Setter for temperature. GenerationConfig.BuilderclearTemperature()Clears the value of temperature field. abstract GenerationConfig.BuilderthinkingConfig(ThinkingConfig thinkingConfig)Setter for thinkingConfig. GenerationConfig.BuilderthinkingConfig(ThinkingConfig.Builder thinkingConfigBuilder)Setter for thinkingConfig builder. GenerationConfig.BuilderclearThinkingConfig()Clears the value of thinkingConfig field. abstract GenerationConfig.BuildertopK(Float topK)Setter for topK. GenerationConfig.BuilderclearTopK()Clears the value of topK field. abstract GenerationConfig.BuildertopP(Float topP)Setter for topP. GenerationConfig.BuilderclearTopP()Clears the value of topP field. abstract GenerationConfig.BuilderenableEnhancedCivicAnswers(boolean enableEnhancedCivicAnswers)Setter for enableEnhancedCivicAnswers. GenerationConfig.BuilderclearEnableEnhancedCivicAnswers()Clears the value of enableEnhancedCivicAnswers field. abstract GenerationConfigbuild()-
-
Method Detail
-
modelSelectionConfig
abstract GenerationConfig.Builder modelSelectionConfig(ModelSelectionConfig modelSelectionConfig)
Setter for modelSelectionConfig.
modelSelectionConfig: Optional. Config for model selection.
-
modelSelectionConfig
@CanIgnoreReturnValue() GenerationConfig.Builder modelSelectionConfig(ModelSelectionConfig.Builder modelSelectionConfigBuilder)
Setter for modelSelectionConfig builder.
modelSelectionConfig: Optional. Config for model selection.
-
clearModelSelectionConfig
@CanIgnoreReturnValue() GenerationConfig.Builder clearModelSelectionConfig()
Clears the value of modelSelectionConfig field.
-
responseJsonSchema
abstract GenerationConfig.Builder responseJsonSchema(Object responseJsonSchema)
Setter for responseJsonSchema.
responseJsonSchema: Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/).
-
clearResponseJsonSchema
@CanIgnoreReturnValue() GenerationConfig.Builder clearResponseJsonSchema()
Clears the value of responseJsonSchema field.
-
audioTimestamp
abstract GenerationConfig.Builder audioTimestamp(boolean audioTimestamp)
Setter for audioTimestamp.
audioTimestamp: Optional. If enabled, audio timestamps will be included in the request to the model. This can be useful for synchronizing audio with other modalities in the response. This field is not supported in Gemini API.
-
clearAudioTimestamp
@CanIgnoreReturnValue() GenerationConfig.Builder clearAudioTimestamp()
Clears the value of audioTimestamp field.
-
candidateCount
abstract GenerationConfig.Builder candidateCount(Integer candidateCount)
Setter for candidateCount.
candidateCount: Optional. The number of candidate responses to generate. A higher `candidate_count` can provide more options to choose from, but it also consumes more resources. This can be useful for generating a variety of responses and selecting the best one.
-
clearCandidateCount
@CanIgnoreReturnValue() GenerationConfig.Builder clearCandidateCount()
Clears the value of candidateCount field.
-
enableAffectiveDialog
abstract GenerationConfig.Builder enableAffectiveDialog(boolean enableAffectiveDialog)
Setter for enableAffectiveDialog.
enableAffectiveDialog: Optional. If enabled, the model will detect emotions and adapt its responses accordingly. For example, if the model detects that the user is frustrated, it may provide a more empathetic response. This field is not supported in Gemini API.
-
clearEnableAffectiveDialog
@CanIgnoreReturnValue() GenerationConfig.Builder clearEnableAffectiveDialog()
Clears the value of enableAffectiveDialog field.
-
frequencyPenalty
abstract GenerationConfig.Builder frequencyPenalty(Float frequencyPenalty)
Setter for frequencyPenalty.
frequencyPenalty: Optional. Penalizes tokens based on their frequency in the generated text. A positive value helps to reduce the repetition of words and phrases. Valid values can range from [-2.0, 2.0].
-
clearFrequencyPenalty
@CanIgnoreReturnValue() GenerationConfig.Builder clearFrequencyPenalty()
Clears the value of frequencyPenalty field.
-
logprobs
abstract GenerationConfig.Builder logprobs(Integer logprobs)
Setter for logprobs.
logprobs: Optional. The number of top log probabilities to return for each token. This can be used to see which other tokens were considered likely candidates for a given position. A higher value will return more options, but it will also increase the size of the response.
-
clearLogprobs
@CanIgnoreReturnValue() GenerationConfig.Builder clearLogprobs()
Clears the value of logprobs field.
-
maxOutputTokens
abstract GenerationConfig.Builder maxOutputTokens(Integer maxOutputTokens)
Setter for maxOutputTokens.
maxOutputTokens: Optional. The maximum number of tokens to generate in the response. A token is approximately four characters. The default value varies by model. This parameter can be used to control the length of the generated text and prevent overly long responses.
-
clearMaxOutputTokens
@CanIgnoreReturnValue() GenerationConfig.Builder clearMaxOutputTokens()
Clears the value of maxOutputTokens field.
-
mediaResolution
abstract GenerationConfig.Builder mediaResolution(MediaResolution mediaResolution)
Setter for mediaResolution.
mediaResolution: Optional. The token resolution at which input media content is sampled. This is used to control the trade-off between the quality of the response and the number of tokens used to represent the media. A higher resolution allows the model to perceive more detail, which can lead to a more nuanced response, but it will also use more tokens. This does not affect the image dimensions sent to the model.
-
clearMediaResolution
@CanIgnoreReturnValue() GenerationConfig.Builder clearMediaResolution()
Clears the value of mediaResolution field.
-
mediaResolution
@CanIgnoreReturnValue() GenerationConfig.Builder mediaResolution(MediaResolution.Known knownType)
Setter for mediaResolution given a known enum.
mediaResolution: Optional. The token resolution at which input media content is sampled. This is used to control the trade-off between the quality of the response and the number of tokens used to represent the media. A higher resolution allows the model to perceive more detail, which can lead to a more nuanced response, but it will also use more tokens. This does not affect the image dimensions sent to the model.
-
mediaResolution
@CanIgnoreReturnValue() GenerationConfig.Builder mediaResolution(String mediaResolution)
Setter for mediaResolution given a string.
mediaResolution: Optional. The token resolution at which input media content is sampled. This is used to control the trade-off between the quality of the response and the number of tokens used to represent the media. A higher resolution allows the model to perceive more detail, which can lead to a more nuanced response, but it will also use more tokens. This does not affect the image dimensions sent to the model.
-
presencePenalty
abstract GenerationConfig.Builder presencePenalty(Float presencePenalty)
Setter for presencePenalty.
presencePenalty: Optional. Penalizes tokens that have already appeared in the generated text. A positive value encourages the model to generate more diverse and less repetitive text. Valid values can range from [-2.0, 2.0].
-
clearPresencePenalty
@CanIgnoreReturnValue() GenerationConfig.Builder clearPresencePenalty()
Clears the value of presencePenalty field.
-
responseLogprobs
abstract GenerationConfig.Builder responseLogprobs(boolean responseLogprobs)
Setter for responseLogprobs.
responseLogprobs: Optional. If set to true, the log probabilities of the output tokens are returned. Log probabilities are the logarithm of the probability of a token appearing in the output. A higher log probability means the token is more likely to be generated. This can be useful for analyzing the model's confidence in its own output and for debugging.
-
clearResponseLogprobs
@CanIgnoreReturnValue() GenerationConfig.Builder clearResponseLogprobs()
Clears the value of responseLogprobs field.
-
responseMimeType
abstract GenerationConfig.Builder responseMimeType(String responseMimeType)
Setter for responseMimeType.
responseMimeType: Optional. The IANA standard MIME type of the response. The model will generate output that conforms to this MIME type. Supported values include 'text/plain' (default) and 'application/json'. The model needs to be prompted to output the appropriate response type, otherwise the behavior is undefined. This is a preview feature.
-
clearResponseMimeType
@CanIgnoreReturnValue() GenerationConfig.Builder clearResponseMimeType()
Clears the value of responseMimeType field.
-
responseModalities
abstract GenerationConfig.Builder responseModalities(List<Modality> responseModalities)
Setter for responseModalities.
responseModalities: Optional. The modalities of the response. The model will generate a response that includes all the specified modalities. For example, if this is set to `[TEXT, IMAGE]`, the response will include both text and an image.
-
responseModalities
@CanIgnoreReturnValue() GenerationConfig.Builder responseModalities(Array<Modality> responseModalities)
Setter for responseModalities.
responseModalities: Optional. The modalities of the response. The model will generate a response that includes all the specified modalities. For example, if this is set to `[TEXT, IMAGE]`, the response will include both text and an image.
-
clearResponseModalities
@CanIgnoreReturnValue() GenerationConfig.Builder clearResponseModalities()
Clears the value of responseModalities field.
-
responseModalities
@CanIgnoreReturnValue() GenerationConfig.Builder responseModalities(Array<String> responseModalities)
Setter for responseModalities given a varargs of strings.
responseModalities: Optional. The modalities of the response. The model will generate a response that includes all the specified modalities. For example, if this is set to `[TEXT, IMAGE]`, the response will include both text and an image.
-
responseModalities
@CanIgnoreReturnValue() GenerationConfig.Builder responseModalities(Array<Modality.Known> knownTypes)
Setter for responseModalities given a varargs of known enums.
responseModalities: Optional. The modalities of the response. The model will generate a response that includes all the specified modalities. For example, if this is set to `[TEXT, IMAGE]`, the response will include both text and an image.
-
responseModalitiesFromKnown
@CanIgnoreReturnValue() GenerationConfig.Builder responseModalitiesFromKnown(List<Modality.Known> knownTypes)
Setter for responseModalities given a list of known enums.
responseModalities: Optional. The modalities of the response. The model will generate a response that includes all the specified modalities. For example, if this is set to `[TEXT, IMAGE]`, the response will include both text and an image.
-
responseModalitiesFromString
@CanIgnoreReturnValue() GenerationConfig.Builder responseModalitiesFromString(List<String> responseModalities)
Setter for responseModalities given a list of strings.
responseModalities: Optional. The modalities of the response. The model will generate a response that includes all the specified modalities. For example, if this is set to `[TEXT, IMAGE]`, the response will include both text and an image.
-
responseSchema
abstract GenerationConfig.Builder responseSchema(Schema responseSchema)
Setter for responseSchema.
responseSchema: Optional. Lets you to specify a schema for the model's response, ensuring that the output conforms to a particular structure. This is useful for generating structured data such as JSON. The schema is a subset of the [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema) object. When this field is set, you must also set the `response_mime_type` to `application/json`.
-
responseSchema
@CanIgnoreReturnValue() GenerationConfig.Builder responseSchema(Schema.Builder responseSchemaBuilder)
Setter for responseSchema builder.
responseSchema: Optional. Lets you to specify a schema for the model's response, ensuring that the output conforms to a particular structure. This is useful for generating structured data such as JSON. The schema is a subset of the [OpenAPI 3.0 schema object](https://spec.openapis.org/oas/v3.0.3#schema) object. When this field is set, you must also set the `response_mime_type` to `application/json`.
-
clearResponseSchema
@CanIgnoreReturnValue() GenerationConfig.Builder clearResponseSchema()
Clears the value of responseSchema field.
-
routingConfig
abstract GenerationConfig.Builder routingConfig(GenerationConfigRoutingConfig routingConfig)
Setter for routingConfig.
routingConfig: Optional. Routing configuration. This field is not supported in Gemini API.
-
routingConfig
@CanIgnoreReturnValue() GenerationConfig.Builder routingConfig(GenerationConfigRoutingConfig.Builder routingConfigBuilder)
Setter for routingConfig builder.
routingConfig: Optional. Routing configuration. This field is not supported in Gemini API.
-
clearRoutingConfig
@CanIgnoreReturnValue() GenerationConfig.Builder clearRoutingConfig()
Clears the value of routingConfig field.
-
seed
abstract GenerationConfig.Builder seed(Integer seed)
Setter for seed.
seed: Optional. A seed for the random number generator. By setting a seed, you can make the model's output mostly deterministic. For a given prompt and parameters (like temperature, top_p, etc.), the model will produce the same response every time. However, it's not a guaranteed absolute deterministic behavior. This is different from parameters like `temperature`, which control the *level* of randomness. `seed` ensures that the "random" choices the model makes are the same on every run, making it essential for testing and ensuring reproducible results.
-
clearSeed
@CanIgnoreReturnValue() GenerationConfig.Builder clearSeed()
Clears the value of seed field.
-
speechConfig
abstract GenerationConfig.Builder speechConfig(SpeechConfig speechConfig)
Setter for speechConfig.
speechConfig: Optional. The speech generation config.
-
speechConfig
@CanIgnoreReturnValue() GenerationConfig.Builder speechConfig(SpeechConfig.Builder speechConfigBuilder)
Setter for speechConfig builder.
speechConfig: Optional. The speech generation config.
-
clearSpeechConfig
@CanIgnoreReturnValue() GenerationConfig.Builder clearSpeechConfig()
Clears the value of speechConfig field.
-
stopSequences
abstract GenerationConfig.Builder stopSequences(List<String> stopSequences)
Setter for stopSequences.
stopSequences: Optional. A list of character sequences that will stop the model from generating further tokens. If a stop sequence is generated, the output will end at that point. This is useful for controlling the length and structure of the output. For example, you can use ["\n", "###"] to stop generation at a new line or a specific marker.
-
stopSequences
@CanIgnoreReturnValue() GenerationConfig.Builder stopSequences(Array<String> stopSequences)
Setter for stopSequences.
stopSequences: Optional. A list of character sequences that will stop the model from generating further tokens. If a stop sequence is generated, the output will end at that point. This is useful for controlling the length and structure of the output. For example, you can use ["\n", "###"] to stop generation at a new line or a specific marker.
-
clearStopSequences
@CanIgnoreReturnValue() GenerationConfig.Builder clearStopSequences()
Clears the value of stopSequences field.
-
temperature
abstract GenerationConfig.Builder temperature(Float temperature)
Setter for temperature.
temperature: Optional. Controls the randomness of the output. A higher temperature results in more creative and diverse responses, while a lower temperature makes the output more predictable and focused. The valid range is (0.0, 2.0].
-
clearTemperature
@CanIgnoreReturnValue() GenerationConfig.Builder clearTemperature()
Clears the value of temperature field.
-
thinkingConfig
abstract GenerationConfig.Builder thinkingConfig(ThinkingConfig thinkingConfig)
Setter for thinkingConfig.
thinkingConfig: Optional. Configuration for thinking features. An error will be returned if this field is set for models that don't support thinking.
-
thinkingConfig
@CanIgnoreReturnValue() GenerationConfig.Builder thinkingConfig(ThinkingConfig.Builder thinkingConfigBuilder)
Setter for thinkingConfig builder.
thinkingConfig: Optional. Configuration for thinking features. An error will be returned if this field is set for models that don't support thinking.
-
clearThinkingConfig
@CanIgnoreReturnValue() GenerationConfig.Builder clearThinkingConfig()
Clears the value of thinkingConfig field.
-
topK
abstract GenerationConfig.Builder topK(Float topK)
Setter for topK.
topK: Optional. Specifies the top-k sampling threshold. The model considers only the top k most probable tokens for the next token. This can be useful for generating more coherent and less random text. For example, a `top_k` of 40 means the model will choose the next word from the 40 most likely words.
-
clearTopK
@CanIgnoreReturnValue() GenerationConfig.Builder clearTopK()
Clears the value of topK field.
-
topP
abstract GenerationConfig.Builder topP(Float topP)
Setter for topP.
topP: Optional. Specifies the nucleus sampling threshold. The model considers only the smallest set of tokens whose cumulative probability is at least `top_p`. This helps generate more diverse and less repetitive responses. For example, a `top_p` of 0.9 means the model considers tokens until the cumulative probability of the tokens to select from reaches 0.9. It's recommended to adjust either temperature or `top_p`, but not both.
-
clearTopP
@CanIgnoreReturnValue() GenerationConfig.Builder clearTopP()
Clears the value of topP field.
-
enableEnhancedCivicAnswers
abstract GenerationConfig.Builder enableEnhancedCivicAnswers(boolean enableEnhancedCivicAnswers)
Setter for enableEnhancedCivicAnswers.
enableEnhancedCivicAnswers: Optional. Enables enhanced civic answers. It may not be available for all models. This field is not supported in Vertex AI.
-
clearEnableEnhancedCivicAnswers
@CanIgnoreReturnValue() GenerationConfig.Builder clearEnableEnhancedCivicAnswers()
Clears the value of enableEnhancedCivicAnswers field.
-
build
abstract GenerationConfig build()
-
-
-
-