pub struct LlamaTokenDataArray {
pub data: Vec<LlamaTokenData>,
pub selected: Option<usize>,
pub sorted: bool,
}
Expand description
a safe wrapper around llama_token_data_array
.
Fields§
§data: Vec<LlamaTokenData>
the underlying data
selected: Option<usize>
the index of the selected token in data
sorted: bool
is the data sorted?
Implementations§
Source§impl LlamaTokenDataArray
impl LlamaTokenDataArray
Sourcepub fn new(data: Vec<LlamaTokenData>, sorted: bool) -> Self
pub fn new(data: Vec<LlamaTokenData>, sorted: bool) -> Self
Create a new LlamaTokenDataArray
from a vector and whether or not the data is sorted.
let array = LlamaTokenDataArray::new(vec![
LlamaTokenData::new(LlamaToken(0), 0.0, 0.0),
LlamaTokenData::new(LlamaToken(1), 0.1, 0.1)
], false);
assert_eq!(array.data.len(), 2);
assert_eq!(array.sorted, false);
Sourcepub fn from_iter<T>(data: T, sorted: bool) -> LlamaTokenDataArraywhere
T: IntoIterator<Item = LlamaTokenData>,
pub fn from_iter<T>(data: T, sorted: bool) -> LlamaTokenDataArraywhere
T: IntoIterator<Item = LlamaTokenData>,
Create a new LlamaTokenDataArray
from an iterator and whether or not the data is sorted.
let array = LlamaTokenDataArray::from_iter([
LlamaTokenData::new(LlamaToken(0), 0.0, 0.0),
LlamaTokenData::new(LlamaToken(1), 0.1, 0.1)
], false);
assert_eq!(array.data.len(), 2);
assert_eq!(array.sorted, false);
Sourcepub fn selected_token(&self) -> Option<LlamaToken>
pub fn selected_token(&self) -> Option<LlamaToken>
Returns the current selected token, if one exists.
Source§impl LlamaTokenDataArray
impl LlamaTokenDataArray
Sourcepub fn apply_sampler(&mut self, sampler: &LlamaSampler)
pub fn apply_sampler(&mut self, sampler: &LlamaSampler)
Modifies the data array by applying a sampler to it
Sourcepub fn with_sampler(self, sampler: &mut LlamaSampler) -> Self
pub fn with_sampler(self, sampler: &mut LlamaSampler) -> Self
Modifies the data array by applying a sampler to it
Sourcepub fn sample_token(&mut self, seed: u32) -> LlamaToken
pub fn sample_token(&mut self, seed: u32) -> LlamaToken
Randomly selects a token from the candidates based on their probabilities.
§Panics
If the internal llama.cpp sampler fails to select a token.
Sourcepub fn sample_token_greedy(&mut self) -> LlamaToken
pub fn sample_token_greedy(&mut self) -> LlamaToken
Selects the token with the highest probability.
§Panics
If the internal llama.cpp sampler fails to select a token.
Trait Implementations§
Source§impl Clone for LlamaTokenDataArray
impl Clone for LlamaTokenDataArray
Source§fn clone(&self) -> LlamaTokenDataArray
fn clone(&self) -> LlamaTokenDataArray
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for LlamaTokenDataArray
impl Debug for LlamaTokenDataArray
Source§impl PartialEq for LlamaTokenDataArray
impl PartialEq for LlamaTokenDataArray
impl StructuralPartialEq for LlamaTokenDataArray
Auto Trait Implementations§
impl Freeze for LlamaTokenDataArray
impl RefUnwindSafe for LlamaTokenDataArray
impl Send for LlamaTokenDataArray
impl Sync for LlamaTokenDataArray
impl Unpin for LlamaTokenDataArray
impl UnwindSafe for LlamaTokenDataArray
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
Mutably borrows from an owned value. Read more