pub struct LlamaSampler {
pub sampler: *mut llama_sampler,
}Fields§
§sampler: *mut llama_samplerImplementations§
Source§impl LlamaSampler
impl LlamaSampler
Sourcepub fn sample(
&mut self,
ctx: &LlamaContext<'_>,
idx: i32,
) -> Result<LlamaToken, SampleError>
pub fn sample( &mut self, ctx: &LlamaContext<'_>, idx: i32, ) -> Result<LlamaToken, SampleError>
§Errors
Returns SampleError if the C++ sampler throws an exception or if the index is invalid.
pub fn apply(&self, data_array: &mut LlamaTokenDataArray)
Sourcepub fn accept(&mut self, token: LlamaToken) -> Result<(), SamplerAcceptError>
pub fn accept(&mut self, token: LlamaToken) -> Result<(), SamplerAcceptError>
§Errors
Returns SamplerAcceptError if the underlying sampler rejects the token.
Sourcepub fn accept_many(
&mut self,
tokens: impl IntoIterator<Item = impl Borrow<LlamaToken>>,
) -> Result<(), SamplerAcceptError>
pub fn accept_many( &mut self, tokens: impl IntoIterator<Item = impl Borrow<LlamaToken>>, ) -> Result<(), SamplerAcceptError>
§Errors
Returns SamplerAcceptError if the underlying sampler rejects any token.
Sourcepub fn with_tokens(
self,
tokens: impl IntoIterator<Item = impl Borrow<LlamaToken>>,
) -> Result<Self, SamplerAcceptError>
pub fn with_tokens( self, tokens: impl IntoIterator<Item = impl Borrow<LlamaToken>>, ) -> Result<Self, SamplerAcceptError>
§Errors
Returns SamplerAcceptError if the underlying sampler rejects any token.
Sourcepub fn try_accept(
&mut self,
token: LlamaToken,
) -> Result<(), SamplerAcceptError>
pub fn try_accept( &mut self, token: LlamaToken, ) -> Result<(), SamplerAcceptError>
§Errors
Returns an error if the underlying sampler rejects the token.
pub fn reset(&mut self)
pub fn get_seed(&self) -> u32
pub fn chain(samplers: impl IntoIterator<Item = Self>, no_perf: bool) -> Self
pub fn chain_simple(samplers: impl IntoIterator<Item = Self>) -> Self
pub fn temp(t: f32) -> Self
pub fn temp_ext(t: f32, delta: f32, exponent: f32) -> Self
pub fn top_k(k: i32) -> Self
pub fn top_n_sigma(n: f32) -> Self
pub fn typical(p: f32, min_keep: usize) -> Self
pub fn top_p(p: f32, min_keep: usize) -> Self
pub fn min_p(p: f32, min_keep: usize) -> Self
pub fn xtc(p: f32, t: f32, min_keep: usize, seed: u32) -> Self
Sourcepub fn grammar(
model: &LlamaModel,
grammar_str: &str,
grammar_root: &str,
) -> Result<Self, GrammarError>
pub fn grammar( model: &LlamaModel, grammar_str: &str, grammar_root: &str, ) -> Result<Self, GrammarError>
§Errors
Returns an error if the grammar is invalid or the sampler cannot be initialized.
Sourcepub fn grammar_lazy(
model: &LlamaModel,
grammar_str: &str,
grammar_root: &str,
trigger_words: impl IntoIterator<Item = impl AsRef<[u8]>>,
trigger_tokens: &[LlamaToken],
) -> Result<Self, GrammarError>
pub fn grammar_lazy( model: &LlamaModel, grammar_str: &str, grammar_root: &str, trigger_words: impl IntoIterator<Item = impl AsRef<[u8]>>, trigger_tokens: &[LlamaToken], ) -> Result<Self, GrammarError>
§Errors
Returns an error if the grammar or trigger words are invalid.
Sourcepub fn grammar_lazy_patterns(
model: &LlamaModel,
grammar_str: &str,
grammar_root: &str,
trigger_patterns: &[String],
trigger_tokens: &[LlamaToken],
) -> Result<Self, GrammarError>
pub fn grammar_lazy_patterns( model: &LlamaModel, grammar_str: &str, grammar_root: &str, trigger_patterns: &[String], trigger_tokens: &[LlamaToken], ) -> Result<Self, GrammarError>
§Errors
Returns an error if the grammar or trigger patterns are invalid.
Sourcepub fn llguidance(
model: &LlamaModel,
grammar_kind: &str,
grammar_data: &str,
) -> Result<Self, GrammarError>
pub fn llguidance( model: &LlamaModel, grammar_kind: &str, grammar_data: &str, ) -> Result<Self, GrammarError>
§Errors
Returns GrammarError if the grammar is invalid or the sampler cannot be initialized.
Sourcepub fn dry(
model: &LlamaModel,
multiplier: f32,
base: f32,
allowed_length: i32,
penalty_last_n: i32,
seq_breakers: impl IntoIterator<Item = impl AsRef<[u8]>>,
) -> Result<Self, GrammarError>
pub fn dry( model: &LlamaModel, multiplier: f32, base: f32, allowed_length: i32, penalty_last_n: i32, seq_breakers: impl IntoIterator<Item = impl AsRef<[u8]>>, ) -> Result<Self, GrammarError>
§Errors
Returns an error if any string in seq_breakers contains null bytes.
pub fn penalties( penalty_last_n: i32, penalty_repeat: f32, penalty_freq: f32, penalty_present: f32, ) -> Self
pub fn mirostat(n_vocab: i32, seed: u32, tau: f32, eta: f32, m: i32) -> Self
pub fn mirostat_v2(seed: u32, tau: f32, eta: f32) -> Self
pub fn dist(seed: u32) -> Self
pub fn greedy() -> Self
Sourcepub fn logit_bias(
n_vocab: i32,
biases: &[LlamaLogitBias],
) -> Result<Self, SamplingError>
pub fn logit_bias( n_vocab: i32, biases: &[LlamaLogitBias], ) -> Result<Self, SamplingError>
§Errors
Returns SamplingError::IntegerOverflow if biases.len() exceeds i32::MAX.
Trait Implementations§
Source§impl Debug for LlamaSampler
impl Debug for LlamaSampler
Source§impl Drop for LlamaSampler
impl Drop for LlamaSampler
Auto Trait Implementations§
impl Freeze for LlamaSampler
impl RefUnwindSafe for LlamaSampler
impl !Send for LlamaSampler
impl !Sync for LlamaSampler
impl Unpin for LlamaSampler
impl UnsafeUnpin for LlamaSampler
impl UnwindSafe for LlamaSampler
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
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 more