pub struct ThinkTagContext { /* private fields */ }Expand description
Context for tracking <think>...</think> tag parsing state within a sequence.
This provides incremental parsing of token streams containing think tags, with delta extraction for streaming responses.
Implementations§
Source§impl ThinkTagContext
impl ThinkTagContext
Sourcepub fn new() -> ThinkTagContext
pub fn new() -> ThinkTagContext
Create a new ThinkTagContext
Sourcepub fn new_in_think_block() -> ThinkTagContext
pub fn new_in_think_block() -> ThinkTagContext
Create a new ThinkTagContext that starts inside a think block.
Use this when the chat template hardcodes <think> in the generation prompt,
so the model’s output starts inside the think block without an opening tag.
Sourcepub fn process_bytes(&mut self, bytes: &[u8])
pub fn process_bytes(&mut self, bytes: &[u8])
Process incremental bytes from the model output.
This method handles bytes that may contain incomplete UTF-8 sequences (e.g., multi-byte characters like emojis split across token boundaries).
Sourcepub fn process_text(&mut self, text: &str)
pub fn process_text(&mut self, text: &str)
Process incremental text from the model output.
This method handles text that may contain partial tags split across token boundaries by buffering potentially incomplete tags.
Sourcepub fn get_content_delta(&mut self) -> Option<String>
pub fn get_content_delta(&mut self) -> Option<String>
Get the content delta since the last call.
Returns new content that hasn’t been sent yet, or None if no new content.
Sourcepub fn get_reasoning_delta(&mut self) -> Option<String>
pub fn get_reasoning_delta(&mut self) -> Option<String>
Get the reasoning delta since the last call.
Returns new reasoning content that hasn’t been sent yet, or None if no new content.
Sourcepub fn content(&self) -> Option<String>
pub fn content(&self) -> Option<String>
Get the accumulated content (outside think blocks).
Returns None if no content has been accumulated.
Sourcepub fn reasoning_content(&self) -> Option<String>
pub fn reasoning_content(&self) -> Option<String>
Get the accumulated reasoning content (inside think blocks).
Returns None if no reasoning content has been accumulated.
Sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Finalize parsing at end of stream.
If there’s an unclosed <think> block, treat any remaining buffer
content as reasoning. Otherwise, treat it as content.
Sourcepub fn is_in_think_block(&self) -> bool
pub fn is_in_think_block(&self) -> bool
Check if currently inside a think block
Trait Implementations§
Source§impl Default for ThinkTagContext
impl Default for ThinkTagContext
Source§fn default() -> ThinkTagContext
fn default() -> ThinkTagContext
Auto Trait Implementations§
impl Freeze for ThinkTagContext
impl RefUnwindSafe for ThinkTagContext
impl Send for ThinkTagContext
impl Sync for ThinkTagContext
impl Unpin for ThinkTagContext
impl UnwindSafe for ThinkTagContext
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
§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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> ⓘ
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> ⓘ
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§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.