Skip to main content

GenerationConfig

Struct GenerationConfig 

Source
pub struct GenerationConfig {
Show 15 fields pub temperature: Option<f32>, pub top_p: Option<f32>, pub top_k: Option<i32>, pub seed: Option<i32>, pub max_output_tokens: Option<i32>, pub candidate_count: Option<i32>, pub stop_sequences: Option<Vec<String>>, pub response_mime_type: Option<String>, pub response_schema: Option<Value>, pub response_json_schema: Option<Value>, pub response_modalities: Option<Vec<String>>, pub image_config: Option<ImageConfig>, pub speech_config: Option<SpeechConfig>, pub thinking_config: Option<ThinkingConfig>, pub media_resolution: Option<MediaResolutionLevel>,
}
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

Expand description

Configuration for generation

Fieldsยง

ยงtemperature: Option<f32>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The temperature for the model (0.0 to 1.0)

Controls the randomness of the output. Higher values (e.g., 0.9) make output more random, lower values (e.g., 0.1) make output more deterministic.

ยงtop_p: Option<f32>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The top-p value for the model (0.0 to 1.0)

For each token generation step, the model considers the top_p percentage of probability mass for potential token choices. Lower values are more selective, higher values allow more variety.

ยงtop_k: Option<i32>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The top-k value for the model

For each token generation step, the model considers the top_k most likely tokens. Lower values are more selective, higher values allow more variety.

ยงseed: Option<i32>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

Seed used in decoding.

By default, the model uses a random value for each request if a seed is not provided. Setting a specific seed, along with consistent values for other parameters like temperature, can make the model return the same response for repeated requests with the same input. Identical outputs are not guaranteed across all runs, due to backend infrastructure variations, but it provides a โ€œbest effortโ€ for reproducibility.

ยงmax_output_tokens: Option<i32>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The maximum number of tokens to generate

Limits the length of the generated content. One token is roughly 4 characters.

ยงcandidate_count: Option<i32>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The candidate count

Number of alternative responses to generate.

ยงstop_sequences: Option<Vec<String>>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

Whether to stop on specific sequences

The model will stop generating content when it encounters any of these sequences.

ยงresponse_mime_type: Option<String>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The response mime type

Specifies the format of the modelโ€™s response.

ยงresponse_schema: Option<Value>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The response schema

Specifies the JSON schema for structured responses.

ยงresponse_json_schema: Option<Value>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The response JSON schema (strict mode).

Prefer this field for modern Gemini models that support JSON Schema natively.

ยงresponse_modalities: Option<Vec<String>>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

Response modalities (for TTS and other multimodal outputs)

ยงimage_config: Option<ImageConfig>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

Optional. Config for image generation. An error will be returned if this field is set for models that donโ€™t support these config options.

ยงspeech_config: Option<SpeechConfig>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

Speech configuration for text-to-speech generation

ยงthinking_config: Option<ThinkingConfig>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

The thinking configuration

Configuration for the modelโ€™s thinking process (Gemini 2.5 and Gemini 3 series).

ยงmedia_resolution: Option<MediaResolutionLevel>
๐Ÿ‘ŽDeprecated since 1.8.0:

Use crate::interactions::InteractionGenerationConfig instead

Global media resolution for all images and PDFs. Controls the resolution used for inline image and PDF data, affecting token usage. Can be overridden per-part using the Part::InlineData media_resolution field.

Trait Implementationsยง

Sourceยง

impl Clone for GenerationConfig

Sourceยง

fn clone(&self) -> GenerationConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) ยท Sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for GenerationConfig

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Default for GenerationConfig

Sourceยง

fn default() -> GenerationConfig

Returns the โ€œdefault valueโ€ for a type. Read more
Sourceยง

impl<'de> Deserialize<'de> for GenerationConfig

Sourceยง

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Sourceยง

impl Serialize for GenerationConfig

Sourceยง

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> CloneToUninit for T
where T: Clone,

Sourceยง

unsafe fn clone_to_uninit(&self, dest: *mut u8)

๐Ÿ”ฌThis is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Sourceยง

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Sourceยง

impl<T> DynClone for T
where T: Clone,

Sourceยง

fn __clone_box(&self, _: Private) -> *mut ()

Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T> PolicyExt for T
where T: ?Sized,

Sourceยง

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Sourceยง

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Sourceยง

impl<T> ToOwned for T
where T: Clone,

Sourceยง

type Owned = T

The resulting type after obtaining ownership.
Sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more