pub struct StreamedTurnAssembler { /* private fields */ }Expand description
Sans-IO accumulator that assembles one streamed model turn. See the module docs for the driving protocol.
Implementations§
Source§impl StreamedTurnAssembler
impl StreamedTurnAssembler
Sourcepub fn new(
executable_tool_names: BTreeSet<String>,
allowed_tool_names: BTreeSet<String>,
) -> Self
pub fn new( executable_tool_names: BTreeSet<String>, allowed_tool_names: BTreeSet<String>, ) -> Self
Create an assembler for one streamed turn with the tool names advertised to the provider for that turn.
Sourcepub fn aggregated_text(&self) -> &str
pub fn aggregated_text(&self) -> &str
Aggregated assistant text streamed so far this turn (empty until the first text delta).
Sourcepub fn ingest<R>(
&mut self,
item: &StreamedAssistantContent<R>,
) -> Result<Vec<StreamedTurnEvent>, CompletionError>
pub fn ingest<R>( &mut self, item: &StreamedAssistantContent<R>, ) -> Result<Vec<StreamedTurnEvent>, CompletionError>
Ingest one provider stream item and return what the driver must do.
§Errors
Returns an error when the provider stream is inconsistent (argument deltas finishing without a validated tool name) or when an invalid tool call is still awaiting resolution.
Sourcepub fn resolve_pending_invalid(
&mut self,
resolution: &StreamedResolution,
) -> Vec<StreamedTurnEvent>
pub fn resolve_pending_invalid( &mut self, resolution: &StreamedResolution, ) -> Vec<StreamedTurnEvent>
Apply the machine’s resolution for the invalid tool call surfaced by
the last StreamedTurnEvent::InvalidToolCall. For a repaired name
this returns the deltas to forward (the repaired name plus any
buffered argument deltas).
Sourcepub fn pending_delta_error(&self) -> Option<CompletionError>
pub fn pending_delta_error(&self) -> Option<CompletionError>
Error when argument deltas were buffered for a tool call whose name never validated — a provider-stream consistency violation.
Sourcepub fn partial_turn(&self, message_id: Option<String>) -> PartialStreamedTurn
pub fn partial_turn(&self, message_id: Option<String>) -> PartialStreamedTurn
Snapshot of the turn so far, for diagnostics and rollback messages.
Sourcepub fn finish(
self,
message_id: Option<String>,
final_choice: &OneOrMany<AssistantContent>,
) -> StreamedTurn
pub fn finish( self, message_id: Option<String>, final_choice: &OneOrMany<AssistantContent>, ) -> StreamedTurn
Assemble the completed turn. final_choice is the provider’s
aggregated choice for the turn
(crate::streaming::StreamingCompletionResponse::choice).
Auto Trait Implementations§
impl Freeze for StreamedTurnAssembler
impl RefUnwindSafe for StreamedTurnAssembler
impl Send for StreamedTurnAssembler
impl Sync for StreamedTurnAssembler
impl Unpin for StreamedTurnAssembler
impl UnsafeUnpin for StreamedTurnAssembler
impl UnwindSafe for StreamedTurnAssembler
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> 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