Gemini.Types.GenerationConfig (GeminiEx v0.3.0)

View Source

Configuration for content generation parameters.

Summary

Functions

Create a balanced generation config.

Create a creative generation config (higher temperature).

Create a deterministic generation config.

Enable thought summaries in model response.

Set JSON response format.

Set maximum output tokens.

Create a new generation config with default values.

Create a precise generation config (lower temperature).

Set plain text response format.

Set thinking budget for Gemini 2.5 series models.

Set complete thinking configuration (budget + thoughts).

Types

t()

@type t() :: %Gemini.Types.GenerationConfig{
  candidate_count: integer() | nil,
  frequency_penalty: float() | nil,
  logprobs: integer() | nil,
  max_output_tokens: integer() | nil,
  presence_penalty: float() | nil,
  response_logprobs: boolean() | nil,
  response_mime_type: String.t() | nil,
  response_schema: map() | nil,
  stop_sequences: [String.t()],
  temperature: float() | nil,
  thinking_config: Gemini.Types.GenerationConfig.ThinkingConfig.t() | nil,
  top_k: integer() | nil,
  top_p: float() | nil
}

Functions

balanced(opts \\ [])

Create a balanced generation config.

creative(opts \\ [])

Create a creative generation config (higher temperature).

deterministic(opts \\ [])

Create a deterministic generation config.

include_thoughts(config \\ %__MODULE__{}, include)

@spec include_thoughts(t(), boolean()) :: t()

Enable thought summaries in model response.

When enabled, the model includes a summary of its reasoning process.

Parameters

  • config: GenerationConfig struct (defaults to new config)
  • include: Boolean to enable/disable thought summaries

Examples

# Enable thought summaries
config = GenerationConfig.include_thoughts(true)

# Combine with thinking budget
config =
  GenerationConfig.new()
  |> GenerationConfig.thinking_budget(2048)
  |> GenerationConfig.include_thoughts(true)

json_response(config \\ %__MODULE__{})

Set JSON response format.

max_tokens(config \\ %__MODULE__{}, tokens)

Set maximum output tokens.

new(opts \\ [])

Create a new generation config with default values.

precise(opts \\ [])

Create a precise generation config (lower temperature).

stop_sequences(config \\ %__MODULE__{}, sequences)

Add stop sequences.

text_response(config \\ %__MODULE__{})

Set plain text response format.

thinking_budget(config \\ %__MODULE__{}, budget)

@spec thinking_budget(t(), integer()) :: t()

Set thinking budget for Gemini 2.5 series models.

Controls how many thinking tokens the model can use for internal reasoning.

Parameters

  • config: GenerationConfig struct (defaults to new config)
  • budget: Integer controlling thinking tokens
    • 0: Disable thinking (Flash/Lite only, NOT Pro)
    • -1: Dynamic thinking (model decides budget)
    • Positive integer: Fixed budget
      • Flash: 0-24,576
      • Pro: 128-32,768
      • Lite: 512-24,576

Examples

# Disable thinking (save costs)
config = GenerationConfig.thinking_budget(0)

# Dynamic thinking (model decides)
config = GenerationConfig.thinking_budget(-1)

# Fixed budget (balance cost/quality)
config = GenerationConfig.thinking_budget(1024)

# Chain with other options
config =
  GenerationConfig.new()
  |> GenerationConfig.temperature(0.7)
  |> GenerationConfig.thinking_budget(2048)

thinking_config(config \\ %__MODULE__{}, budget, opts \\ [])

@spec thinking_config(t(), integer(), keyword()) :: t()

Set complete thinking configuration (budget + thoughts).

Convenience function to set both thinking budget and thought inclusion.

Parameters

  • config: GenerationConfig struct (defaults to new config)
  • budget: Thinking budget integer
  • opts: Keyword list with optional :include_thoughts boolean

Examples

# Set budget and enable thoughts
config = GenerationConfig.thinking_config(1024, include_thoughts: true)

# Just budget (thoughts disabled)
config = GenerationConfig.thinking_config(512)