pub struct SamplingConfig {
pub temperature: Option<f64>,
pub top_p: Option<f64>,
pub top_k: Option<u64>,
pub min_p: Option<f64>,
pub max_tokens: Option<u64>,
pub frequency_penalty: Option<f32>,
pub presence_penalty: Option<f32>,
}Expand description
Sampling parameters for text generation.
All fields are optional — None means “use the engine default”.
Note: usize is replaced with u64 for UniFFI compatibility.
Fields§
§temperature: Option<f64>Sampling temperature (higher = more random). Typical range: 0.0–2.0.
top_p: Option<f64>Nucleus (top-p) sampling threshold. Typical value: 0.9–0.95.
top_k: Option<u64>Top-k sampling limit.
min_p: Option<f64>Min-p sampling threshold.
max_tokens: Option<u64>Maximum number of tokens to generate.
frequency_penalty: Option<f32>Frequency penalty (penalise tokens proportional to occurrence count).
presence_penalty: Option<f32>Presence penalty (penalise tokens that appeared at all).
Implementations§
Source§impl SamplingConfig
impl SamplingConfig
Sourcepub fn reasoning() -> SamplingConfig
pub fn reasoning() -> SamplingConfig
Defaults for models that emit an extended reasoning block before the user-visible answer.
Sourcepub fn deterministic() -> SamplingConfig
pub fn deterministic() -> SamplingConfig
Deterministic sampling (temperature = 0, greedy decoding).
Sourcepub fn mobile() -> SamplingConfig
pub fn mobile() -> SamplingConfig
Conservative mobile defaults — lower max_tokens for faster response on constrained devices (CPU-only ARM SoCs doing ~1-3 tok/sec).
Sourcepub fn coding() -> SamplingConfig
pub fn coding() -> SamplingConfig
Sampling config tuned for coding assistants.
Key differences from the general-purpose default:
-
frequency_penalty = 1.15— the primary fix for the repeated-token loop you saw with small GGUF models. Penalises each token proportional to how many times it has already appeared in the output, making it progressively harder to emit the same word again. 1.15 is aggressive enough to kill echo loops without hurting code token repetition (identifiers, keywords) at typical response lengths. -
presence_penalty = 0.1— a light nudge away from any token that has appeared at all, encouraging lexical variety across the response. -
temperature = 0.2— low randomness keeps generated code deterministic and syntactically correct. High temperature causes hallucinated variable names and broken syntax in code blocks. -
top_p = 0.95— nucleus sampling retained to avoid degenerate greedy outputs while still keeping the distribution tight. -
max_tokens = 1024— doubled vs. the chat default to allow complete function / class explanations without truncation.
Sourcepub fn coding_mobile() -> SamplingConfig
pub fn coding_mobile() -> SamplingConfig
Like coding but capped at 256 tokens for mobile
devices where latency matters more than completeness.
Trait Implementations§
Source§impl Clone for SamplingConfig
impl Clone for SamplingConfig
Source§fn clone(&self) -> SamplingConfig
fn clone(&self) -> SamplingConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<UT> ConvertError<UT> for SamplingConfig
impl<UT> ConvertError<UT> for SamplingConfig
Source§impl Debug for SamplingConfig
impl Debug for SamplingConfig
Source§impl Default for SamplingConfig
impl Default for SamplingConfig
Source§fn default() -> SamplingConfig
fn default() -> SamplingConfig
Sensible creative-chat defaults.
Source§impl<'de> Deserialize<'de> for SamplingConfig
impl<'de> Deserialize<'de> for SamplingConfig
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SamplingConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<SamplingConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<UT> FfiConverter<UT> for SamplingConfig
impl<UT> FfiConverter<UT> for SamplingConfig
Source§const TYPE_ID_META: MetadataBuffer
const TYPE_ID_META: MetadataBuffer
Source§type FfiType = RustBuffer
type FfiType = RustBuffer
Source§fn lower(v: SamplingConfig) -> RustBuffer
fn lower(v: SamplingConfig) -> RustBuffer
Source§fn try_lift(buf: RustBuffer) -> Result<SamplingConfig, Error>
fn try_lift(buf: RustBuffer) -> Result<SamplingConfig, Error>
Source§impl<UT> Lift<UT> for SamplingConfig
impl<UT> Lift<UT> for SamplingConfig
type FfiType = <SamplingConfig as FfiConverter<UT>>::FfiType
fn try_lift( v: <SamplingConfig as Lift<UT>>::FfiType, ) -> Result<SamplingConfig, Error>
fn try_read(buf: &mut &[u8]) -> Result<SamplingConfig, Error>
Source§fn try_lift_from_rust_buffer(v: RustBuffer) -> Result<Self, Error>
fn try_lift_from_rust_buffer(v: RustBuffer) -> Result<Self, Error>
Source§impl<UT> LiftRef<UT> for SamplingConfig
impl<UT> LiftRef<UT> for SamplingConfig
type LiftType = SamplingConfig
Source§impl<UT> LiftReturn<UT> for SamplingConfig
impl<UT> LiftReturn<UT> for SamplingConfig
Source§type ReturnType = <SamplingConfig as Lift<UT>>::FfiType
type ReturnType = <SamplingConfig as Lift<UT>>::FfiType
Source§fn try_lift_successful_return(
v: <SamplingConfig as LiftReturn<UT>>::ReturnType,
) -> Result<SamplingConfig, Error>
fn try_lift_successful_return( v: <SamplingConfig as LiftReturn<UT>>::ReturnType, ) -> Result<SamplingConfig, Error>
Source§fn lift_foreign_return(
ffi_return: Self::ReturnType,
call_status: RustCallStatus,
) -> Self
fn lift_foreign_return( ffi_return: Self::ReturnType, call_status: RustCallStatus, ) -> Self
Source§fn lift_error(_buf: RustBuffer) -> Self
fn lift_error(_buf: RustBuffer) -> Self
Source§fn handle_callback_unexpected_error(e: UnexpectedUniFFICallbackError) -> Self
fn handle_callback_unexpected_error(e: UnexpectedUniFFICallbackError) -> Self
Source§impl<UT> Lower<UT> for SamplingConfig
impl<UT> Lower<UT> for SamplingConfig
type FfiType = <SamplingConfig as FfiConverter<UT>>::FfiType
fn lower(obj: SamplingConfig) -> <SamplingConfig as Lower<UT>>::FfiType
fn write(obj: SamplingConfig, buf: &mut Vec<u8>)
Source§fn lower_into_rust_buffer(obj: Self) -> RustBuffer
fn lower_into_rust_buffer(obj: Self) -> RustBuffer
Source§impl<UT> LowerError<UT> for SamplingConfig
impl<UT> LowerError<UT> for SamplingConfig
Source§fn lower_error(obj: SamplingConfig) -> RustBuffer
fn lower_error(obj: SamplingConfig) -> RustBuffer
Source§impl<UT> LowerReturn<UT> for SamplingConfig
impl<UT> LowerReturn<UT> for SamplingConfig
Source§type ReturnType = <SamplingConfig as Lower<UT>>::FfiType
type ReturnType = <SamplingConfig as Lower<UT>>::FfiType
Source§fn lower_return(
v: SamplingConfig,
) -> Result<<SamplingConfig as LowerReturn<UT>>::ReturnType, RustCallError>
fn lower_return( v: SamplingConfig, ) -> Result<<SamplingConfig as LowerReturn<UT>>::ReturnType, RustCallError>
Source§fn handle_failed_lift(
error: LiftArgsError,
) -> Result<Self::ReturnType, RustCallError>
fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>
Source§impl Serialize for SamplingConfig
impl Serialize for SamplingConfig
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl<UT> TypeId<UT> for SamplingConfig
impl<UT> TypeId<UT> for SamplingConfig
Auto Trait Implementations§
impl Freeze for SamplingConfig
impl RefUnwindSafe for SamplingConfig
impl Send for SamplingConfig
impl Sync for SamplingConfig
impl Unpin for SamplingConfig
impl UnsafeUnpin for SamplingConfig
impl UnwindSafe for SamplingConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for T
impl<T> Downcast for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.