pub struct SequenceConstraint { /* private fields */ }Expand description
A constraint that forces the generated output to reproduce a specific, pre-determined token sequence.
While position < target.len(), only target[position] is allowed.
Once the target has been fully reproduced (position >= target.len()) the
constraint is satisfied and all tokens become allowed again (returns None).
§Example
use oxibonsai_runtime::constrained_decoding::{SequenceConstraint, TokenConstraint};
let mut c = SequenceConstraint::new(vec![5, 6, 7]);
let mask = c.allowed_tokens(&[], 10).unwrap();
assert!(mask[5]);
assert!(!mask[6]);
assert_eq!(c.advance(5), true);Implementations§
Trait Implementations§
Source§impl TokenConstraint for SequenceConstraint
impl TokenConstraint for SequenceConstraint
Source§fn allowed_tokens(
&self,
_generated: &[u32],
vocab_size: usize,
) -> Option<Vec<bool>>
fn allowed_tokens( &self, _generated: &[u32], vocab_size: usize, ) -> Option<Vec<bool>>
Returns a bitmask allowing only the next expected token, or None once the
full sequence has been reproduced.
Source§fn advance(&mut self, token: u32) -> bool
fn advance(&mut self, token: u32) -> bool
Commits token. Returns false (and sets the failed flag) if token
does not match the expected token at the current position.
Source§fn is_complete(&self) -> bool
fn is_complete(&self) -> bool
Returns true once all tokens in the target sequence have been consumed.
Auto Trait Implementations§
impl Freeze for SequenceConstraint
impl RefUnwindSafe for SequenceConstraint
impl Send for SequenceConstraint
impl Sync for SequenceConstraint
impl Unpin for SequenceConstraint
impl UnsafeUnpin for SequenceConstraint
impl UnwindSafe for SequenceConstraint
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
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>
Converts
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>
Converts
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