Struct kalosm_sample::StructuredSampler
source · pub struct StructuredSampler<V: Parser<Error = E, Output = O, PartialState = PA>, E, O, PA> { /* private fields */ }Expand description
A sampler that enforces the given validator. Any tokens that form an invalid sequence will have a probability of 0
Implementations§
source§impl<V: Parser<Error = E, Output = O, PartialState = PA>, E, O, PA> StructuredSampler<V, E, O, PA>
impl<V: Parser<Error = E, Output = O, PartialState = PA>, E, O, PA> StructuredSampler<V, E, O, PA>
sourcepub fn new(
structure: V,
current_token_count: usize,
tokenizer: impl Into<DynTokenizer>
) -> Self
pub fn new( structure: V, current_token_count: usize, tokenizer: impl Into<DynTokenizer> ) -> Self
Create a new structured sampler that starts validating tokens at the given token count.
Trait Implementations§
source§impl<V: Parser<Error = E, Output = O, PartialState = PA>, E, O, PA> Debug for StructuredSampler<V, E, O, PA>
impl<V: Parser<Error = E, Output = O, PartialState = PA>, E, O, PA> Debug for StructuredSampler<V, E, O, PA>
source§impl<V: Parser<Error = E, Output = O, PartialState = PA> + CreateParserState + Send + Sync, E, O, PA> Sampler for StructuredSampler<V, E, O, PA>
impl<V: Parser<Error = E, Output = O, PartialState = PA> + CreateParserState + Send + Sync, E, O, PA> Sampler for StructuredSampler<V, E, O, PA>
source§fn sample<'a>(
&mut self,
res: &mut dyn HasSamplerResources,
logits: &'a mut Logits
) -> Result<&'a mut Logits>
fn sample<'a>( &mut self, res: &mut dyn HasSamplerResources, logits: &'a mut Logits ) -> Result<&'a mut Logits>
source§fn sampled_token_id(&self) -> Option<u32>
fn sampled_token_id(&self) -> Option<u32>
Returns the last sampled token id if available. Read more
source§fn sample_token(
&mut self,
res: &mut dyn HasSamplerResources,
logits: &mut Logits
) -> Result<Option<u32>, Error>
fn sample_token( &mut self, res: &mut dyn HasSamplerResources, logits: &mut Logits ) -> Result<Option<u32>, Error>
Run the sampler and return the last sampled token id if available. Read more
Auto Trait Implementations§
impl<V, E, O, PA> !RefUnwindSafe for StructuredSampler<V, E, O, PA>
impl<V, E, O, PA> Send for StructuredSampler<V, E, O, PA>where
V: Send,
impl<V, E, O, PA> Sync for StructuredSampler<V, E, O, PA>where
V: Sync,
impl<V, E, O, PA> Unpin for StructuredSampler<V, E, O, PA>where
V: Unpin,
impl<V, E, O, PA> !UnwindSafe for StructuredSampler<V, E, O, PA>
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