pub struct StopMatcher { /* private fields */ }Expand description
Incremental stop-sequence matcher over the DECODED text stream.
The hard part is that a stop string need not align with token boundaries: "\n\n" may arrive as
"\n" + "\n", and "END" as "E" + "ND". Two rules make that work:
- Match on the accumulated tail, not on the individual piece — so a split stop still fires.
- Hold back the longest suffix of the emitted text that is a PREFIX of some stop string.
Streaming clients must never see
"E"from a token that turns out to begin"END"; if the next piece completes the stop, that"E"was never ours to send. The hold-back is bounded bylongest_stop - 1bytes, so at most 3-4 bytes of latency in practice.
On a hit, the text BEFORE the stop string is emitted and the stop string itself is discarded (OpenAI does not include it in the completion).
Implementations§
Source§impl StopMatcher
impl StopMatcher
pub fn new(stops: Vec<String>) -> Self
pub fn is_active(&self) -> bool
Sourcepub fn hit(&self) -> bool
pub fn hit(&self) -> bool
A stop sequence has fired: generation must halt and no further text may be emitted.
Trait Implementations§
Source§impl Debug for StopMatcher
impl Debug for StopMatcher
Auto Trait Implementations§
impl Freeze for StopMatcher
impl RefUnwindSafe for StopMatcher
impl Send for StopMatcher
impl Sync for StopMatcher
impl Unpin for StopMatcher
impl UnsafeUnpin for StopMatcher
impl UnwindSafe for StopMatcher
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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