pub struct SamplingParams {
pub temperature: Option<f32>,
pub max_tokens: Option<u32>,
pub stop: Vec<String>,
}Expand description
Sampling knobs forwarded to an OpenAI-compatible provider.
Why (issue #3758): the streaming request wire previously sent only
model/messages/tools, so a streamed reply’s style, verbosity, and
stopping behaviour were NOT equivalent to the blocking path’s for the same
turn — the caller silently got provider defaults instead of its configured
temperature, token ceiling, and stop sequences. Carrying them in one struct
(rather than three provider constructor arguments) keeps new() stable for
existing callers and lets the set grow without churning call sites.
What: every field is optional — None/empty means “omit from the request
body and let the provider default apply”, which is exactly the pre-#3758
behaviour, so a caller that does not opt in is unaffected. stop maps to
the OpenAI stop array (the direct-Anthropic dialect calls the same thing
stop_sequences).
Test: sampling_params_serialize_into_request_body,
default_sampling_omits_fields.
Fields§
§temperature: Option<f32>Sampling temperature; None omits the field.
max_tokens: Option<u32>Maximum tokens to generate; None omits the field.
stop: Vec<String>Stop sequences; empty omits the field.
Implementations§
Source§impl SamplingParams
impl SamplingParams
Sourcepub fn stop_slice(&self) -> Option<&[String]>
pub fn stop_slice(&self) -> Option<&[String]>
The stop sequences as a request-body-ready Option<&[String]>.
Why: an EMPTY stop array is not the same as an absent one — some
OpenAI-compatible servers reject "stop": [] outright, which is the
same trap ChatProvider already documents for an empty tools
array. Collapsing empty to None at the boundary keeps that decision
in one place instead of at each provider.
What: None when empty, Some(slice) otherwise.
Test: default_sampling_omits_fields.
Trait Implementations§
Source§impl Clone for SamplingParams
impl Clone for SamplingParams
Source§fn clone(&self) -> SamplingParams
fn clone(&self) -> SamplingParams
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more