pub struct ResponseAccumulator { /* private fields */ }Expand description
Accumulates LLM response chunks from streaming or non-streaming sources.
Implementations§
Source§impl ResponseAccumulator
impl ResponseAccumulator
Sourcepub fn new(response_id: String, conversation_id: Option<String>) -> Self
pub fn new(response_id: String, conversation_id: Option<String>) -> Self
Creates a new response accumulator.
Sourcepub fn from_json(
body: &str,
conversation_id: Option<&str>,
) -> ExecutorResult<Self>
pub fn from_json( body: &str, conversation_id: Option<&str>, ) -> ExecutorResult<Self>
Parses a non-streaming JSON response body.
§Errors
Returns ExecutorError::ParseError if JSON parsing fails or required fields are missing.
Sourcepub async fn from_stream(
stream: Pin<Box<dyn Stream<Item = Result<String, ExecutorError>> + Send>>,
conversation_id: Option<&str>,
) -> ExecutorResult<Self>
pub async fn from_stream( stream: Pin<Box<dyn Stream<Item = Result<String, ExecutorError>> + Send>>, conversation_id: Option<&str>, ) -> ExecutorResult<Self>
Accumulates an async stream of raw SSE lines with parallel processing.
The async task feeds raw SSE lines through a channel while a spawn_blocking
worker handles JSON parsing on a blocking thread — keeping the tokio executor
free between chunk arrivals.
§Errors
Returns ExecutorError::ParseError if chunk parsing fails, or
ExecutorError::StreamError if the stream or worker encounters an error.
Sourcepub fn from_sse_lines(
lines: impl IntoIterator<Item = String>,
conversation_id: Option<&str>,
) -> Self
pub fn from_sse_lines( lines: impl IntoIterator<Item = String>, conversation_id: Option<&str>, ) -> Self
Processes pre-collected raw SSE lines synchronously.
Useful when lines have already been buffered (e.g. replaying a recorded stream).
Prefer from_stream for live async streams.
Line parse errors are silently skipped — this function is infallible.
Sourcepub fn mark_incomplete(&mut self, reason: impl Into<String>)
pub fn mark_incomplete(&mut self, reason: impl Into<String>)
Marks the response as incomplete due to an error or interruption.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ResponseAccumulator
impl RefUnwindSafe for ResponseAccumulator
impl Send for ResponseAccumulator
impl Sync for ResponseAccumulator
impl Unpin for ResponseAccumulator
impl UnsafeUnpin for ResponseAccumulator
impl UnwindSafe for ResponseAccumulator
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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