pub struct CompletionBuilder { /* private fields */ }Expand description
Reassembles a stream of TextDeltas back into a Completion —
the inverse of completion_deltas, for a caller that consumed a
stream incrementally (relaying it to a client, say) and still wants
the whole answer at the end: to log, to persist, to hand to the tool
loop.
§Semantics
TextDelta::Textpieces concatenate in order.TextDelta::Reasoningis dropped: reasoning is not part of a completion.TextDelta::ToolCallFinishedfillstool_callsinindexorder; argument chunks and starts are informational here, since the finished call carries the reassembled form. A call whose finish never arrived (the stream died mid-call) leaves no trace — a half-finished call is not a call the tool loop may run.TextDelta::Usageis last-wins, whole replacement.TextDelta::Finishsuppliesmodel(empty when the stream ended without one).jsonis alwaysNone: structured output is acompletefeature — the parsed value comes from validating the whole answer against the prompt’s schema, which a stream that relayed itself away never promised. A streaming caller wanting a value parses and validates the reassembled text itself.
Implementations§
Source§impl CompletionBuilder
impl CompletionBuilder
Sourcepub fn push(&mut self, delta: &TextDelta)
pub fn push(&mut self, delta: &TextDelta)
Folds one delta in. Cheap; call it for every item the stream yields.
Sourcepub fn finish_reason(&self) -> Option<&FinishReason>
pub fn finish_reason(&self) -> Option<&FinishReason>
Why the stream ended, where it sent a Finish — None for a
stream that is still open or died without one.
Sourcepub fn finish(self) -> Completion
pub fn finish(self) -> Completion
The completion the deltas add up to: text concatenated, tool calls
from their finishes in index order, usage last-wins, model from
the Finish, json None (see the type’s docs).
Trait Implementations§
Source§impl Debug for CompletionBuilder
impl Debug for CompletionBuilder
Auto Trait Implementations§
impl Freeze for CompletionBuilder
impl RefUnwindSafe for CompletionBuilder
impl Send for CompletionBuilder
impl Sync for CompletionBuilder
impl Unpin for CompletionBuilder
impl UnsafeUnpin for CompletionBuilder
impl UnwindSafe for CompletionBuilder
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