Skip to main content

StreamText

Struct StreamText 

Source
pub struct StreamText<O> { /* private fields */ }
Expand description

Builder and future of a stream_text call.

Implementations§

Source§

impl<O> StreamText<O>

Source

pub fn system(self, instructions: impl Into<Instructions>) -> Self

Sets system instructions.

Source

pub fn prompt(self, text: impl Into<String>) -> Self

Sets a single user prompt (mutually exclusive with messages).

Source

pub fn messages(self, messages: impl IntoIterator<Item = Message>) -> Self

Sets the conversation messages (mutually exclusive with prompt).

Source

pub fn allow_system_in_messages(self) -> Self

Allows system messages inside messages.

Source

pub fn settings(self, settings: CallSettings) -> Self

Replaces all sampling settings.

Source

pub fn max_output_tokens(self, n: u32) -> Self

Sets the maximum number of output tokens.

Source

pub fn temperature(self, t: f64) -> Self

Sets the sampling temperature.

Source

pub fn top_p(self, p: f64) -> Self

Sets nucleus sampling.

Source

pub fn top_k(self, k: u32) -> Self

Sets top-k sampling.

Source

pub fn presence_penalty(self, p: f64) -> Self

Sets the presence penalty.

Source

pub fn frequency_penalty(self, p: f64) -> Self

Sets the frequency penalty.

Source

pub fn stop_sequences( self, sequences: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Sets stop sequences.

Source

pub fn seed(self, seed: u64) -> Self

Sets the random seed.

Source

pub fn reasoning(self, effort: ReasoningEffort) -> Self

Sets the reasoning effort.

Source

pub fn tools(self, tools: ToolSet) -> Self

Sets the tool set.

Source

pub fn tool_choice(self, choice: ToolChoice) -> Self

Sets the tool choice.

Source

pub fn active_tools( self, names: impl IntoIterator<Item = impl Into<ToolName>>, ) -> Self

Restricts the tools sent to the model.

Source

pub fn tool_order( self, names: impl IntoIterator<Item = impl Into<ToolName>>, ) -> Self

Sets the order in which tools are sent (listed first, rest alphabetical).

Source

pub fn tools_context(self, context: JsonValue) -> Self

Sets the shared tools context (validated against each tool’s context schema).

Source

pub fn runtime_context(self, context: JsonValue) -> Self

Sets application state for step preparation, approval and lifecycle hooks. This value is separate from tool execution context and is never sent to models.

Source

pub fn tool_approval(self, policy: impl ApprovalPolicy + 'static) -> Self

Sets the call-level approval policy.

Source

pub fn tool_approval_secret(self, secret: SecretBox<[u8]>) -> Self

Sets the secret used to sign approval requests.

Source

pub fn tool_callers(self, callers: ToolCallers) -> Self

Restricts which callers may trigger each tool.

Source

pub fn repair_tool_call(self, repair: impl ToolCallRepair + 'static) -> Self

Sets the tool call repair function.

Source

pub fn refine_tool_input( self, name: impl Into<ToolName>, refine: impl Fn(JsonValue) -> BoxFuture<'static, Result<JsonValue, Error>> + Send + Sync + 'static, ) -> Self

Rewrites the validated input of name before execution.

Source

pub fn sandbox(self, sandbox: Arc<dyn Sandbox>) -> Self

Sets the sandbox handed to tools.

Source

pub fn max_tool_concurrency(self, n: usize) -> Self

Limits how many tools execute concurrently within a step.

Source

pub fn stop_when(self, condition: impl StopCondition + 'static) -> Self

Adds a stop condition (any-of). Without conditions the loop stops after one step.

Source

pub fn prepare_step(self, prepare: impl PrepareStep + 'static) -> Self

Sets the per-step preparation callback.

Source

pub fn max_retries(self, n: u32) -> Self

Sets the maximum number of retries (exponential backoff).

Source

pub fn retry_policy(self, policy: RetryPolicy) -> Self

Replaces the retry policy.

Source

pub fn timeout(self, timeout: impl Into<Timeout>) -> Self

Sets timeouts.

Source

pub fn cancellation(self, token: CancellationToken) -> Self

Sets the cancellation token.

Source

pub fn headers(self, headers: Headers) -> Self

Adds request headers.

Source

pub fn provider_options(self, options: ProviderOptions) -> Self

Adds provider options.

Source

pub fn download(self, download: Arc<dyn DownloadFn>) -> Self

Sets the download function for file URLs.

Source

pub fn include(self, include: Include) -> Self

Controls which payloads are kept in step results.

Source

pub fn clock(self, clock: Arc<dyn Clock>) -> Self

Sets the clock used for response.timestamp when the provider sends none.

Source

pub fn id_generator(self, generator: Arc<dyn IdGenerator>) -> Self

Sets the id generator.

Source

pub fn telemetry(self, options: TelemetryOptions) -> Self

Sets telemetry options.

Source

pub fn hooks(self, hooks: Hooks) -> Self

Adds all hooks of hooks.

Source

pub fn on_start(self, f: impl HookFn<StartEvent>) -> Self

Runs when the call starts.

Source

pub fn on_step_start(self, f: impl HookFn<StepStartEvent>) -> Self

Runs when a step starts.

Source

pub fn on_language_model_call_start( self, f: impl HookFn<ModelCallStartEvent>, ) -> Self

Runs before each model call.

Source

pub fn on_language_model_call_end( self, f: impl HookFn<ModelCallEndEvent>, ) -> Self

Runs after each model call.

Source

pub fn on_tool_execution_start( self, f: impl HookFn<ToolExecutionStartEvent>, ) -> Self

Runs before each tool execution.

Source

pub fn on_tool_execution_end( self, f: impl HookFn<ToolExecutionEndEvent>, ) -> Self

Runs after each tool execution.

Source

pub fn on_step_end(self, f: impl HookFn<StepResult>) -> Self

Runs when a step finishes.

Source

pub fn on_end(self, f: impl HookFn<EndEvent>) -> Self

Runs when the call finishes.

Source§

impl<O> StreamText<O>

Source

pub fn output<T>(self, output: Output<T>) -> StreamText<T>

Requests structured output parsed by output.

Source

pub fn transform(self, transform: impl StreamTransform + 'static) -> Self

Appends a transform applied to the event stream before the step results are accumulated. Transforms run in order.

Source

pub fn include_raw_chunks(self) -> Self

Forwards raw provider chunks as StreamEvent::Raw.

Source

pub fn stream_retries(self, retries: u32) -> Self

Enables stream-level retries: after an error reported by the model stream the current step is retried up to retries times. 0 allows only retries requested by the on_error callback. Retries are disabled when this is not called.

Source

pub fn on_chunk(self, f: impl HookFn<StreamEvent>) -> Self

Observes transformed events and provider errors considered for retry.

A provider error is observed before on_error, including errors swallowed by a successful retry. Retry boundaries bypass this hook; a terminal provider error is not reported twice after transforms.

Source

pub fn on_abort(self, f: impl HookFn<AbortEvent>) -> Self

Runs when the call is aborted by cancellation.

Source

pub fn on_error(self, f: impl OnErrorFn) -> Self

Runs for every error that occurs while streaming; the returned decision may request a retry (see stream_retries). Synchronous and asynchronous callback panics are ignored, preserving the original provider failure and configured automatic retry budget.

Trait Implementations§

Source§

impl<O> Debug for StreamText<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<O: Send + 'static> IntoFuture for StreamText<O>

Source§

type Output = Result<StreamTextResult<O>, Error>

The output that the future will produce on completion.
Source§

type IntoFuture = Pin<Box<dyn Future<Output = <StreamText<O> as IntoFuture>::Output> + Send>>

Which kind of future are we turning this into?
Source§

fn into_future(self) -> Self::IntoFuture

Creates a future from a value. Read more

Auto Trait Implementations§

§

impl<O> !Freeze for StreamText<O>

§

impl<O> !RefUnwindSafe for StreamText<O>

§

impl<O> !UnwindSafe for StreamText<O>

§

impl<O> Send for StreamText<O>
where Arc<dyn OutputHandler<O>>: Send,

§

impl<O> Sync for StreamText<O>
where Arc<dyn OutputHandler<O>>: Sync,

§

impl<O> Unpin for StreamText<O>
where Arc<dyn OutputHandler<O>>: Unpin,

§

impl<O> UnsafeUnpin for StreamText<O>
where Arc<dyn OutputHandler<O>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more