Skip to main content

ModelRequest

Struct ModelRequest 

Source
pub struct ModelRequest {
Show 15 fields pub request_id: RequestId, pub purpose: ModelPurpose, pub messages: Vec<Message>, pub system: Option<String>, pub output: OutputSpec, pub tools: Vec<ToolSpec>, pub tool_choice: ToolChoice, pub max_output_tokens: Option<u32>, pub temperature: Option<f32>, pub reasoning_effort: Option<ReasoningEffort>, pub seed: Option<u64>, pub stop: Vec<String>, pub metadata: RequestMetadata, pub timeout: Duration, pub cache_hint: CacheHint,
}
Expand description

One model call (spec §20.1).

Build it with ModelRequest::new and the with_* methods; every field is public so an adapter can read it without ceremony.

Fields§

§request_id: RequestId

Stable id of the logical call, unchanged across retries and fallbacks (spec §20.7).

§purpose: ModelPurpose

Why the call is being made. Decides capability requirements and logging policy; adapters do not branch on it.

§messages: Vec<Message>

The conversation, oldest first.

§system: Option<String>

Framing instructions, hoisted out of messages because most providers carry them in a dedicated field.

§output: OutputSpec

The shape of the answer.

§tools: Vec<ToolSpec>

Read-only tools the model may call.

§tool_choice: ToolChoice

How free the model is to call them.

§max_output_tokens: Option<u32>

Cap on generated tokens.

§temperature: Option<f32>

Sampling temperature. None leaves the provider’s default in place.

§reasoning_effort: Option<ReasoningEffort>

How much a reasoning model may think. None leaves the provider’s default.

§seed: Option<u64>

Sampling seed, for providers that honour one.

§stop: Vec<String>

Stop sequences.

§metadata: RequestMetadata

Non-personal labels.

§timeout: Duration

Deadline for the whole call, including reading a streamed body.

§cache_hint: CacheHint

Prompt-caching hint.

Implementations§

Source§

impl ModelRequest

Source

pub fn new(purpose: ModelPurpose) -> Self

A free-text request for purpose with a fresh RequestId and the DEFAULT_TIMEOUT.

Source

pub fn with_request_id(self, request_id: RequestId) -> Self

Pins the request id, so a retry or a fallback reuses it.

Source

pub fn with_system(self, system: impl Into<String>) -> Self

Sets the system prompt.

Source

pub fn with_message(self, message: Message) -> Self

Appends one message.

Source

pub fn with_messages(self, messages: Vec<Message>) -> Self

Replaces the conversation.

Source

pub fn with_output(self, output: OutputSpec) -> Self

Sets the expected output shape.

Source

pub fn with_tools(self, tools: Vec<ToolSpec>) -> Self

Declares the read-only tools.

Source

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

Sets the tool-choice mode.

Source

pub fn with_max_output_tokens(self, tokens: u32) -> Self

Caps generated tokens.

Source

pub fn with_temperature(self, temperature: f32) -> Self

Sets the sampling temperature.

Source

pub fn sampling_for(&self, capabilities: &ProviderCapabilities) -> Sampling

The sampling parameters capabilities accepts, with the rest named as dropped.

Source

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

Sets how much a reasoning model may think.

Source

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

Sets the sampling seed.

Source

pub fn with_stop(self, stop: Vec<String>) -> Self

Sets the stop sequences.

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Sets the deadline.

Source

pub fn with_cache_hint(self, cache_hint: CacheHint) -> Self

Sets the caching hint.

Source

pub fn with_metadata( self, key: impl Into<String>, value: impl Into<String>, ) -> Result<Self, MetadataError>

Adds a metadata label.

§Errors

Returns MetadataError when the value is not label-shaped.

Source

pub fn requirements(&self) -> CapabilityRequirements

The capability requirements this request implies on its own, before the purpose’s own requirements are folded in.

It asks for tools when tools are declared, vision when any message carries an image, document input when any message carries a document, and the structured-output transports the purpose accepts when OutputSpec::Json is requested.

Trait Implementations§

Source§

impl Clone for ModelRequest

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelRequest

Source§

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

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

impl<'de> Deserialize<'de> for ModelRequest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ModelRequest

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ModelRequest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ModelRequest

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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