pub struct StructuredOutputProcessor { /* private fields */ }Expand description
Per-request structured-output parser state.
Implementations§
Source§impl StructuredOutputProcessor
impl StructuredOutputProcessor
Sourcepub fn mask_logits(
&self,
logits: &mut [f32],
generated: &[TokenId],
) -> Result<()>
pub fn mask_logits( &self, logits: &mut [f32], generated: &[TokenId], ) -> Result<()>
Consume newly generated tokens and hard-mask every illegal next token. Waiting-for-reasoning mode leaves normal logits untouched until the typed delimiter has been observed.
Sourcepub fn mask_logits_with_terminals(
&self,
logits: &mut [f32],
generated: &[TokenId],
terminal_token_ids: &HashSet<u32>,
hidden_control_token_ids: &HashSet<u32>,
) -> Result<StructuredOutputMaskOutcome>
pub fn mask_logits_with_terminals( &self, logits: &mut [f32], generated: &[TokenId], terminal_token_ids: &HashSet<u32>, hidden_control_token_ids: &HashSet<u32>, ) -> Result<StructuredOutputMaskOutcome>
Apply the grammar mask while allowing engine-resolved stop tokens once the grammar accepts. Some model templates use an end-of-turn token that is not the tokenizer’s primary EOS, so it cannot be represented by the grammar parser’s EOS set alone.
Sourcepub fn is_accepting(&self, generated: &[TokenId]) -> Result<bool>
pub fn is_accepting(&self, generated: &[TokenId]) -> Result<bool>
True only when reasoning has closed and the grammar accepts the full generated structured value.
Sourcepub fn is_accepting_with_terminals(
&self,
generated: &[TokenId],
terminal_token_ids: &HashSet<u32>,
) -> Result<bool>
pub fn is_accepting_with_terminals( &self, generated: &[TokenId], terminal_token_ids: &HashSet<u32>, ) -> Result<bool>
Completion check that treats an engine-resolved terminal sampled after grammar acceptance as framing rather than part of the JSON value.
Sourcepub fn progress_with_terminals(
&self,
generated: &[TokenId],
terminal_token_ids: &HashSet<u32>,
) -> Result<StructuredOutputProgress>
pub fn progress_with_terminals( &self, generated: &[TokenId], terminal_token_ids: &HashSet<u32>, ) -> Result<StructuredOutputProgress>
Inspect the typed activation/grammar state after consuming generated.