pub struct SseFormatter {
pub include_usage: bool,
/* private fields */
}Expand description
Stateless SSE event formatter.
Produces correctly framed data: …\n\n strings for each stage of a
streaming generation response.
Fields§
§include_usage: boolWhether to append a usage chunk after the final delta.
Implementations§
Source§impl SseFormatter
impl SseFormatter
Sourcepub fn with_usage(self) -> Self
pub fn with_usage(self) -> Self
Enable a trailing usage chunk.
Sourcepub fn first_chunk(&self, request_id: &str) -> String
pub fn first_chunk(&self, request_id: &str) -> String
Format the first chunk of a streaming response.
The first chunk carries role: "assistant" and an empty content string
so that clients can render the role indicator immediately.
Sourcepub fn token_chunk(&self, request_id: &str, token_text: &str) -> String
pub fn token_chunk(&self, request_id: &str, token_text: &str) -> String
Format a token delta chunk carrying token_text as the content.
Sourcepub fn final_chunk(&self, request_id: &str, finish_reason: &str) -> String
pub fn final_chunk(&self, request_id: &str, finish_reason: &str) -> String
Format the final chunk carrying the finish_reason and no content.
Sourcepub fn done_sentinel() -> &'static str
pub fn done_sentinel() -> &'static str
The SSE [DONE] sentinel that signals stream completion.
Sourcepub fn format_event(data: &str) -> String
pub fn format_event(data: &str) -> String
Wrap arbitrary JSON data in a data: …\n\n SSE frame.
Sourcepub fn error_event(message: &str) -> String
pub fn error_event(message: &str) -> String
Format a JSON error payload as an SSE event.
Auto Trait Implementations§
impl Freeze for SseFormatter
impl RefUnwindSafe for SseFormatter
impl Send for SseFormatter
impl Sync for SseFormatter
impl Unpin for SseFormatter
impl UnsafeUnpin for SseFormatter
impl UnwindSafe for SseFormatter
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