struct Gemini::GenerationConfig

Overview

Configuration options for model generation and outputs. Not all parameters are configurable for every model.

API Reference

Included Modules

Defined in:

gemini/models.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(pull : JSON::PullParser) #

def self.new(candidate_count : Int32 | Nil = nil, stop_sequences : Nil | Array(String) = nil, temperature : Float64 | Nil = nil, max_output_tokens : Int32 | Nil = nil, top_k : Int32 | Nil = nil, top_p : Float64 | Nil = nil, response_mime_type : Nil | String = nil, response_schema : Nil | Gemini::Schema = nil, presence_penalty : Float64 | Nil = nil, frequency_penalty : Float64 | Nil = nil, response_logprobs : Bool | Nil = nil, logprobs : Int32 | Nil = nil) #

Instance Method Detail

def candidate_count : Int32 | Nil #

Number of generated responses to return.


def candidate_count=(candidate_count : Int32 | Nil) #

Number of generated responses to return.


def frequency_penalty : Float64 | Nil #

Frequency penalty applied to the next token's logprobs, multiplied by the number of times each token has been seen in the response so far. (Optional) A positive penalty will discourage the use of tokens that have already been used, proportional to the number of times the token has been used: The more a token is used, the more dificult it is for the model to use that token again increasing the vocabulary of responses.

Caution: A negative penalty will encourage the model to reuse tokens proportional to the number of times the token has been used. Small negative values will reduce the vocabulary of a response. Larger negative values will cause the model to start repeating a common token until it hits the maxOutputTokens limit: "...the the the the the...".


def frequency_penalty=(frequency_penalty : Float64 | Nil) #

Frequency penalty applied to the next token's logprobs, multiplied by the number of times each token has been seen in the response so far. (Optional) A positive penalty will discourage the use of tokens that have already been used, proportional to the number of times the token has been used: The more a token is used, the more dificult it is for the model to use that token again increasing the vocabulary of responses.

Caution: A negative penalty will encourage the model to reuse tokens proportional to the number of times the token has been used. Small negative values will reduce the vocabulary of a response. Larger negative values will cause the model to start repeating a common token until it hits the maxOutputTokens limit: "...the the the the the...".


def logprobs : Int32 | Nil #

Only valid if #responseLogprobs is true. This sets the number of top logprobs to return at each decoding step in the Candidate#logprobs_result. (Optional)


def logprobs=(logprobs : Int32 | Nil) #

Only valid if #responseLogprobs is true. This sets the number of top logprobs to return at each decoding step in the Candidate#logprobs_result. (Optional)


def max_output_tokens : Int32 | Nil #

The maximum number of tokens to include in a candidate. If unset, this will default to output_token_limit specified in the model's specification.


def max_output_tokens=(max_output_tokens : Int32 | Nil) #

The maximum number of tokens to include in a candidate. If unset, this will default to output_token_limit specified in the model's specification.


def presence_penalty : Float64 | Nil #

Presence penalty applied to the next token's logprobs if the token has already been seen in the response. (Optional) This penalty is binary on/off and not dependant on the number of times the token is used (after the first). Use frequencyPenalty for a penalty that increases with each use. A positive penalty will discourage the use of tokens that have already been used in the response, increasing the vocabulary. A negative penalty will encourage the use of tokens that have already been used in the response, decreasing the vocabulary.


def presence_penalty=(presence_penalty : Float64 | Nil) #

Presence penalty applied to the next token's logprobs if the token has already been seen in the response. (Optional) This penalty is binary on/off and not dependant on the number of times the token is used (after the first). Use frequencyPenalty for a penalty that increases with each use. A positive penalty will discourage the use of tokens that have already been used in the response, increasing the vocabulary. A negative penalty will encourage the use of tokens that have already been used in the response, decreasing the vocabulary.


def response_logprobs=(response_logprobs : Bool | Nil) #

If true, export the logprobs results in response. (Optional)


def response_logprobs? : Bool | Nil #

If true, export the logprobs results in response. (Optional)


def response_mime_type : String | Nil #

Output response mimetype of the generated candidate text. Supported mimetype:

  • text/plain: (default) Text output.
  • application/json: JSON response in the candidates.

def response_mime_type=(response_mime_type : String | Nil) #

Output response mimetype of the generated candidate text. Supported mimetype:

  • text/plain: (default) Text output.
  • application/json: JSON response in the candidates.

def response_schema : Schema | Nil #

Specifies the format of the JSON requested if response_mime_type is application/json.


def response_schema=(response_schema : Schema | Nil) #

Specifies the format of the JSON requested if response_mime_type is application/json.


def stop_sequences : Array(String) | Nil #

The set of character sequences (up to 5) that will stop output generation. If specified, the API will stop at the first appearance of a stop sequence. The stop sequence will not be included as part of the response.


def stop_sequences=(stop_sequences : Array(String) | Nil) #

The set of character sequences (up to 5) that will stop output generation. If specified, the API will stop at the first appearance of a stop sequence. The stop sequence will not be included as part of the response.


def temperature : Float64 | Nil #

Controls the randomness of the output. Values can range from [0.0,1.0], inclusive. A value closer to 1.0 will produce responses that are more varied and creative, while a value closer to 0.0 will typically result in more straightforward responses from the model.


def temperature=(temperature : Float64 | Nil) #

Controls the randomness of the output. Values can range from [0.0,1.0], inclusive. A value closer to 1.0 will produce responses that are more varied and creative, while a value closer to 0.0 will typically result in more straightforward responses from the model.


def top_k : Int32 | Nil #

The maximum number of tokens to consider when sampling. The model uses combined Top-k and nucleus sampling. Top-k sampling considers the set of top_k most probable tokens. Defaults to 40.


def top_k=(top_k : Int32 | Nil) #

The maximum number of tokens to consider when sampling. The model uses combined Top-k and nucleus sampling. Top-k sampling considers the set of top_k most probable tokens. Defaults to 40.


def top_p : Float64 | Nil #

The maximum cumulative probability of tokens to consider when sampling. The model uses combined Top-k and nucleus sampling. Tokens are sorted based on their assigned probabilities so that only the most likely tokens are considered. Top-k sampling directly limits the maximum number of tokens to consider, while Nucleus sampling limits number of tokens based on the cumulative probability.


def top_p=(top_p : Float64 | Nil) #

The maximum cumulative probability of tokens to consider when sampling. The model uses combined Top-k and nucleus sampling. Tokens are sorted based on their assigned probabilities so that only the most likely tokens are considered. Top-k sampling directly limits the maximum number of tokens to consider, while Nucleus sampling limits number of tokens based on the cumulative probability.