pub struct StreamText<O> { /* private fields */ }Expand description
Builder and future of a stream_text call.
Implementations§
Source§impl<O> StreamText<O>
impl<O> StreamText<O>
Sourcepub fn system(self, instructions: impl Into<Instructions>) -> Self
pub fn system(self, instructions: impl Into<Instructions>) -> Self
Sets system instructions.
Sourcepub fn prompt(self, text: impl Into<String>) -> Self
pub fn prompt(self, text: impl Into<String>) -> Self
Sets a single user prompt (mutually exclusive with messages).
Sourcepub fn messages(self, messages: impl IntoIterator<Item = Message>) -> Self
pub fn messages(self, messages: impl IntoIterator<Item = Message>) -> Self
Sets the conversation messages (mutually exclusive with prompt).
Sourcepub fn allow_system_in_messages(self) -> Self
pub fn allow_system_in_messages(self) -> Self
Allows system messages inside messages.
Sourcepub fn settings(self, settings: CallSettings) -> Self
pub fn settings(self, settings: CallSettings) -> Self
Replaces all sampling settings.
Sourcepub fn max_output_tokens(self, n: u32) -> Self
pub fn max_output_tokens(self, n: u32) -> Self
Sets the maximum number of output tokens.
Sourcepub fn temperature(self, t: f64) -> Self
pub fn temperature(self, t: f64) -> Self
Sets the sampling temperature.
Sourcepub fn presence_penalty(self, p: f64) -> Self
pub fn presence_penalty(self, p: f64) -> Self
Sets the presence penalty.
Sourcepub fn frequency_penalty(self, p: f64) -> Self
pub fn frequency_penalty(self, p: f64) -> Self
Sets the frequency penalty.
Sourcepub fn stop_sequences(
self,
sequences: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn stop_sequences( self, sequences: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Sets stop sequences.
Sourcepub fn reasoning(self, effort: ReasoningEffort) -> Self
pub fn reasoning(self, effort: ReasoningEffort) -> Self
Sets the reasoning effort.
Sourcepub fn tool_choice(self, choice: ToolChoice) -> Self
pub fn tool_choice(self, choice: ToolChoice) -> Self
Sets the tool choice.
Sourcepub fn active_tools(
self,
names: impl IntoIterator<Item = impl Into<ToolName>>,
) -> Self
pub fn active_tools( self, names: impl IntoIterator<Item = impl Into<ToolName>>, ) -> Self
Restricts the tools sent to the model.
Sourcepub fn tool_order(
self,
names: impl IntoIterator<Item = impl Into<ToolName>>,
) -> Self
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).
Sourcepub fn tools_context(self, context: JsonValue) -> Self
pub fn tools_context(self, context: JsonValue) -> Self
Sets the shared tools context (validated against each tool’s context schema).
Sourcepub fn runtime_context(self, context: JsonValue) -> Self
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.
Sourcepub fn tool_approval(self, policy: impl ApprovalPolicy + 'static) -> Self
pub fn tool_approval(self, policy: impl ApprovalPolicy + 'static) -> Self
Sets the call-level approval policy.
Sourcepub fn tool_approval_secret(self, secret: SecretBox<[u8]>) -> Self
pub fn tool_approval_secret(self, secret: SecretBox<[u8]>) -> Self
Sets the secret used to sign approval requests.
Sourcepub fn tool_callers(self, callers: ToolCallers) -> Self
pub fn tool_callers(self, callers: ToolCallers) -> Self
Restricts which callers may trigger each tool.
Sourcepub fn repair_tool_call(self, repair: impl ToolCallRepair + 'static) -> Self
pub fn repair_tool_call(self, repair: impl ToolCallRepair + 'static) -> Self
Sets the tool call repair function.
Sourcepub fn refine_tool_input(
self,
name: impl Into<ToolName>,
refine: impl Fn(JsonValue) -> BoxFuture<'static, Result<JsonValue, Error>> + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn max_tool_concurrency(self, n: usize) -> Self
pub fn max_tool_concurrency(self, n: usize) -> Self
Limits how many tools execute concurrently within a step.
Sourcepub fn stop_when(self, condition: impl StopCondition + 'static) -> Self
pub fn stop_when(self, condition: impl StopCondition + 'static) -> Self
Adds a stop condition (any-of). Without conditions the loop stops after one step.
Sourcepub fn prepare_step(self, prepare: impl PrepareStep + 'static) -> Self
pub fn prepare_step(self, prepare: impl PrepareStep + 'static) -> Self
Sets the per-step preparation callback.
Sourcepub fn max_retries(self, n: u32) -> Self
pub fn max_retries(self, n: u32) -> Self
Sets the maximum number of retries (exponential backoff).
Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Replaces the retry policy.
Sourcepub fn cancellation(self, token: CancellationToken) -> Self
pub fn cancellation(self, token: CancellationToken) -> Self
Sets the cancellation token.
Sourcepub fn provider_options(self, options: ProviderOptions) -> Self
pub fn provider_options(self, options: ProviderOptions) -> Self
Adds provider options.
Sourcepub fn download(self, download: Arc<dyn DownloadFn>) -> Self
pub fn download(self, download: Arc<dyn DownloadFn>) -> Self
Sets the download function for file URLs.
Sourcepub fn include(self, include: Include) -> Self
pub fn include(self, include: Include) -> Self
Controls which payloads are kept in step results.
Sourcepub fn clock(self, clock: Arc<dyn Clock>) -> Self
pub fn clock(self, clock: Arc<dyn Clock>) -> Self
Sets the clock used for response.timestamp when the provider sends none.
Sourcepub fn id_generator(self, generator: Arc<dyn IdGenerator>) -> Self
pub fn id_generator(self, generator: Arc<dyn IdGenerator>) -> Self
Sets the id generator.
Sourcepub fn telemetry(self, options: TelemetryOptions) -> Self
pub fn telemetry(self, options: TelemetryOptions) -> Self
Sets telemetry options.
Sourcepub fn on_start(self, f: impl HookFn<StartEvent>) -> Self
pub fn on_start(self, f: impl HookFn<StartEvent>) -> Self
Runs when the call starts.
Sourcepub fn on_step_start(self, f: impl HookFn<StepStartEvent>) -> Self
pub fn on_step_start(self, f: impl HookFn<StepStartEvent>) -> Self
Runs when a step starts.
Sourcepub fn on_language_model_call_start(
self,
f: impl HookFn<ModelCallStartEvent>,
) -> Self
pub fn on_language_model_call_start( self, f: impl HookFn<ModelCallStartEvent>, ) -> Self
Runs before each model call.
Sourcepub fn on_language_model_call_end(
self,
f: impl HookFn<ModelCallEndEvent>,
) -> Self
pub fn on_language_model_call_end( self, f: impl HookFn<ModelCallEndEvent>, ) -> Self
Runs after each model call.
Sourcepub fn on_tool_execution_start(
self,
f: impl HookFn<ToolExecutionStartEvent>,
) -> Self
pub fn on_tool_execution_start( self, f: impl HookFn<ToolExecutionStartEvent>, ) -> Self
Runs before each tool execution.
Sourcepub fn on_tool_execution_end(
self,
f: impl HookFn<ToolExecutionEndEvent>,
) -> Self
pub fn on_tool_execution_end( self, f: impl HookFn<ToolExecutionEndEvent>, ) -> Self
Runs after each tool execution.
Sourcepub fn on_step_end(self, f: impl HookFn<StepResult>) -> Self
pub fn on_step_end(self, f: impl HookFn<StepResult>) -> Self
Runs when a step finishes.
Source§impl<O> StreamText<O>
impl<O> StreamText<O>
Sourcepub fn output<T>(self, output: Output<T>) -> StreamText<T>
pub fn output<T>(self, output: Output<T>) -> StreamText<T>
Requests structured output parsed by output.
Sourcepub fn transform(self, transform: impl StreamTransform + 'static) -> Self
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.
Sourcepub fn include_raw_chunks(self) -> Self
pub fn include_raw_chunks(self) -> Self
Forwards raw provider chunks as StreamEvent::Raw.
Sourcepub fn stream_retries(self, retries: u32) -> Self
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.
Sourcepub fn on_chunk(self, f: impl HookFn<StreamEvent>) -> Self
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.
Sourcepub fn on_abort(self, f: impl HookFn<AbortEvent>) -> Self
pub fn on_abort(self, f: impl HookFn<AbortEvent>) -> Self
Runs when the call is aborted by cancellation.
Sourcepub fn on_error(self, f: impl OnErrorFn) -> Self
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.