pub struct RegexGuidedProcessor { /* private fields */ }Expand description
Hard-mask regex constraint processor.
Build with RegexGuidedProcessor::new(pattern, tokenizer, eos_token);
use by adding as a high-priority logits processor before temperature /
top-k / top-p.
Implementations§
Source§impl RegexGuidedProcessor
impl RegexGuidedProcessor
Sourcepub fn new(
pattern: &str,
tokenizer: Arc<dyn Tokenizer + Send + Sync>,
eos_token: Option<TokenId>,
) -> Result<Self>
pub fn new( pattern: &str, tokenizer: Arc<dyn Tokenizer + Send + Sync>, eos_token: Option<TokenId>, ) -> Result<Self>
Build a guided-decoding processor for pattern. tokenizer is used
to map each vocab entry to its byte representation.
Sourcepub fn can_accept(&self) -> bool
pub fn can_accept(&self) -> bool
Check if the pattern can currently accept (i.e. EOS is valid here).
Sourcepub fn mask_logits(&self, logits: &mut [f32])
pub fn mask_logits(&self, logits: &mut [f32])
Apply the hard mask to logits given the current DFA state.
Sourcepub fn advance_with_tokens_public(&self, tokens: &[TokenId])
pub fn advance_with_tokens_public(&self, tokens: &[TokenId])
Public wrapper around advance_with_tokens for direct callers
(the engine applies the mask inline rather than via
LogitsProcessor::process).
Trait Implementations§
Source§impl Debug for RegexGuidedProcessor
impl Debug for RegexGuidedProcessor
Auto Trait Implementations§
impl !Freeze for RegexGuidedProcessor
impl !RefUnwindSafe for RegexGuidedProcessor
impl Send for RegexGuidedProcessor
impl Sync for RegexGuidedProcessor
impl Unpin for RegexGuidedProcessor
impl UnsafeUnpin for RegexGuidedProcessor
impl UnwindSafe for RegexGuidedProcessor
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