pub struct StreamAccumulator { /* private fields */ }Expand description
Rebuilds a ModelResponse from StreamEvents.
Seed it with the identity of the call, feed it every event with
push, then call finish. reconstruct
does exactly that over a whole ModelStream.
Implementations§
Source§impl StreamAccumulator
impl StreamAccumulator
Sourcepub fn new(
request_id: RequestId,
provider: impl Into<ProviderKey>,
model: impl Into<ModelKey>,
) -> Self
pub fn new( request_id: RequestId, provider: impl Into<ProviderKey>, model: impl Into<ModelKey>, ) -> Self
A fresh accumulator for one call.
Sourcepub fn with_raw_id(self, raw_id: impl Into<String>) -> Self
pub fn with_raw_id(self, raw_id: impl Into<String>) -> Self
Records the provider’s response identifier.
Only needed when the identifier is known before the stream opens — from
a response header, say. An adapter that reads it off the wire emits a
StreamEvent::ResponseId instead, and the last one wins.
Sourcepub const fn with_latency(self, latency: Duration) -> Self
pub const fn with_latency(self, latency: Duration) -> Self
Records the measured latency of the whole stream.
Sourcepub fn with_warning(self, warning: ResponseWarning) -> Self
pub fn with_warning(self, warning: ResponseWarning) -> Self
Adds a warning the adapter already knows about.
For what the request conversion gave up before the call. A warning the
stream itself reveals travels as a StreamEvent::Warning, and a
warning that arrives both ways is recorded once.
Sourcepub fn push(&mut self, event: StreamEvent) -> Result<(), ProviderError>
pub fn push(&mut self, event: StreamEvent) -> Result<(), ProviderError>
Absorbs one event.
§Errors
Returns ProviderErrorKind::Malformed
for a fragment or terminator that names a call which was never started,
a call started twice, a fragment after the call ended, or a second
finish event.
Sourcepub fn finish(self) -> Result<ModelResponse, ProviderError>
pub fn finish(self) -> Result<ModelResponse, ProviderError>
Builds the response.
§Errors
Returns ProviderErrorKind::Malformed
when no finish event arrived — a truncated stream is not a short answer
— or when a call’s concatenated fragments are not valid JSON.