pub struct GenerationConfig { /* private fields */ }Expand description
Optional sampling and tool-choice overrides.
These are portable requested controls. Local validation does not establish support for every selected model; unsupported combinations fail at the model operation.
§Examples
use providers_kit::generation::GenerationConfig;
let config = GenerationConfig::default().with_temperature(0.5)?.with_seed(42);
assert_eq!(config.temperature(), Some(0.5));
assert_eq!(config.seed(), Some(42));
Implementations§
Source§impl GenerationConfig
impl GenerationConfig
Sourcepub fn with_temperature(self, value: f32) -> Result<Self, KitError>
pub fn with_temperature(self, value: f32) -> Result<Self, KitError>
Sets a finite non-negative sampling temperature.
§Errors
Returns an input error unless temperature is finite and between 0 and 2 inclusive.
§Examples
use providers_kit::generation::GenerationConfig;
let config = GenerationConfig::default().with_temperature(0.5)?;
assert_eq!(config.temperature(), Some(0.5));
Sourcepub fn with_top_p(self, value: f32) -> Result<Self, KitError>
pub fn with_top_p(self, value: f32) -> Result<Self, KitError>
Sourcepub fn with_top_k(self, value: NonZeroU32) -> Self
pub fn with_top_k(self, value: NonZeroU32) -> Self
Sets a non-zero top-k cutoff.
§Examples
use providers_kit::generation::GenerationConfig;
let config = GenerationConfig::default().with_top_k(std::num::NonZeroU32::new(20).unwrap());
assert_eq!(config.top_k(), std::num::NonZeroU32::new(20));
Sourcepub fn with_max_output_tokens(self, value: NonZeroU32) -> Self
pub fn with_max_output_tokens(self, value: NonZeroU32) -> Self
Sets a non-zero maximum output-token count.
§Examples
use providers_kit::generation::GenerationConfig;
let config =
GenerationConfig::default().with_max_output_tokens(std::num::NonZeroU32::new(256).unwrap());
assert_eq!(config.max_output_tokens(), std::num::NonZeroU32::new(256));
Sourcepub fn with_stop_sequences(self, values: Vec<String>) -> Result<Self, KitError>
pub fn with_stop_sequences(self, values: Vec<String>) -> Result<Self, KitError>
Replaces validated unique stop sequences.
§Errors
Returns an input error for a blank or repeated sequence. An empty list clears existing stop sequences.
§Examples
use providers_kit::generation::GenerationConfig;
let config = GenerationConfig::default().with_stop_sequences(vec!["END".into()])?;
assert_eq!(config.stop_sequences(), &["END"]);
Sourcepub fn with_presence_penalty(self, value: f32) -> Result<Self, KitError>
pub fn with_presence_penalty(self, value: f32) -> Result<Self, KitError>
Sets a finite presence penalty in [-2, 2].
§Errors
Returns an input error unless the penalty is finite and between -2 and 2 inclusive.
§Examples
use providers_kit::generation::GenerationConfig;
let config = GenerationConfig::default().with_presence_penalty(0.25)?;
assert_eq!(config.presence_penalty(), Some(0.25));
Sourcepub fn with_frequency_penalty(self, value: f32) -> Result<Self, KitError>
pub fn with_frequency_penalty(self, value: f32) -> Result<Self, KitError>
Sets a finite frequency penalty in [-2, 2].
§Errors
Returns an input error unless the penalty is finite and between -2 and 2 inclusive.
§Examples
use providers_kit::generation::GenerationConfig;
let config = GenerationConfig::default().with_frequency_penalty(0.25)?;
assert_eq!(config.frequency_penalty(), Some(0.25));
Sourcepub fn with_seed(self, value: u64) -> Self
pub fn with_seed(self, value: u64) -> Self
Sets a deterministic sampling seed.
§Examples
use providers_kit::generation::GenerationConfig;
let config = GenerationConfig::default().with_seed(42);
assert_eq!(config.seed(), Some(42));
Sourcepub fn with_tool_choice(self, value: ToolChoice) -> Self
pub fn with_tool_choice(self, value: ToolChoice) -> Self
Sets a validated tool-selection policy.
§Examples
use providers_kit::generation::GenerationConfig;
let config =
GenerationConfig::default().with_tool_choice(providers_kit::generation::ToolChoice::Auto);
assert_eq!(config.tool_choice(), Some(&providers_kit::generation::ToolChoice::Auto));
Sourcepub const fn temperature(&self) -> Option<f32>
pub const fn temperature(&self) -> Option<f32>
Returns the requested sampling temperature.
See crate::generation::GenerationConfig::with_temperature for a complete example.
Sourcepub const fn top_p(&self) -> Option<f32>
pub const fn top_p(&self) -> Option<f32>
Returns the requested nucleus-sampling probability.
See crate::generation::GenerationConfig::with_top_p for a complete example.
Sourcepub const fn top_k(&self) -> Option<NonZeroU32>
pub const fn top_k(&self) -> Option<NonZeroU32>
Returns the requested top-k cutoff.
See crate::generation::GenerationConfig::with_top_k for a complete example.
Sourcepub const fn max_output_tokens(&self) -> Option<NonZeroU32>
pub const fn max_output_tokens(&self) -> Option<NonZeroU32>
Returns the requested maximum output-token count.
See crate::generation::GenerationConfig::with_max_output_tokens for a complete example.
Sourcepub fn stop_sequences(&self) -> &[String]
pub fn stop_sequences(&self) -> &[String]
Returns validated stop sequences in caller order.
See crate::generation::GenerationConfig::with_stop_sequences for a complete example.
Sourcepub const fn presence_penalty(&self) -> Option<f32>
pub const fn presence_penalty(&self) -> Option<f32>
Returns the requested presence penalty.
See crate::generation::GenerationConfig::with_presence_penalty for a complete example.
Sourcepub const fn frequency_penalty(&self) -> Option<f32>
pub const fn frequency_penalty(&self) -> Option<f32>
Returns the requested frequency penalty.
See crate::generation::GenerationConfig::with_frequency_penalty for a complete example.
Sourcepub const fn seed(&self) -> Option<u64>
pub const fn seed(&self) -> Option<u64>
Returns the requested sampling seed.
See crate::generation::GenerationConfig::with_seed for a complete example.
Sourcepub const fn tool_choice(&self) -> Option<&ToolChoice>
pub const fn tool_choice(&self) -> Option<&ToolChoice>
Returns the requested tool-selection policy.
See crate::generation::GenerationConfig::with_tool_choice for a complete example.