pub struct Transcript { /* private fields */ }Expand description
A streamed reply, assembled.
Fold Events into this and it produces the same ChatResponse the non streamed call
would have returned. That equality is checked by the contract suite rather than hoped
for: two ways to ask the same question that disagree about the answer are worse than one.
It is deliberately usable after a failure. Everything that arrived before the stream
broke is still here, and finish will hand it to you marked
StopReason::Interrupted.
Implementations§
Source§impl Transcript
impl Transcript
Sourcepub fn new(asked_for: impl Into<ModelId>) -> Self
pub fn new(asked_for: impl Into<ModelId>) -> Self
An empty transcript for a request that named this model.
The model is needed because a stream that fails before its first frame never says which model served it, and a reply has to name one.
Sourcepub async fn drain(&mut self, stream: EventStream<'_>) -> Result<()>
pub async fn drain(&mut self, stream: EventStream<'_>) -> Result<()>
Reads a whole stream into this transcript.
§Errors
Whatever the stream failed with. The transcript is still valid: everything that
arrived before the failure is in it, and finish will hand it
back marked StopReason::Interrupted. That is the whole point of this returning
rather than consuming — a caller can tell what arrived, that the turn did not
finish, and why, without inferring any of the three from the others.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether a stop reason has arrived.
False while the turn is still being written, and false forever if the stream broke.
Sourcepub fn finish(self) -> ChatResponse
pub fn finish(self) -> ChatResponse
The assembled reply.
A transcript with no stop reason is one whose stream ended early, and it comes back
as StopReason::Interrupted rather than as something that looks finished. Usage
nobody reported is Usage::absent, never zero.
Trait Implementations§
Source§impl Clone for Transcript
impl Clone for Transcript
Source§fn clone(&self) -> Transcript
fn clone(&self) -> Transcript
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more