Skip to main content

ChatRequest

Struct ChatRequest 

Source
#[non_exhaustive]
pub struct ChatRequest { pub messages: Vec<Message>, pub system_prompt: Option<SystemPrompt>, pub tools: Option<Vec<ToolDefinition>>, pub temperature: Option<f32>, pub top_p: Option<f32>, pub top_k: Option<u32>, pub stop_sequences: Vec<String>, pub max_tokens: u32, pub tool_choice: Option<ToolChoice>, pub disable_parallel_tool_use: Option<bool>, pub additional_params: Option<Value>, }
Expand description

Per-turn request the engine assembles and the adapter lowers to the provider’s wire format.

The struct is #[non_exhaustive], so external construction goes through Default / ChatRequest::new rather than struct literals. Adapters that don’t natively support a control (e.g. top_k on Chat Completions) ignore it; provider-specific knobs outside the typed surface ride Self::additional_params.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§messages: Vec<Message>

Conversation history sent to the provider, in order. Adapters translate each Message block to the provider’s content shape.

§system_prompt: Option<SystemPrompt>

System instructions sent out-of-band from messages. None lets the provider use its default behaviour.

§tools: Option<Vec<ToolDefinition>>

Tools the model may call this turn. None disables tool use entirely and lets adapters omit the tools field on the wire, which some providers require when no tools are configured.

§temperature: Option<f32>

Sampling temperature in the provider’s native range (typically [0.0, 1.0] or [0.0, 2.0]). None keeps the provider default.

§top_p: Option<f32>

Nucleus sampling cutoff. None keeps the provider default.

§top_k: Option<u32>

Top-k sampling cutoff. Only honoured by providers that expose the parameter (Anthropic). None keeps the provider default; adapters without top_k ignore the field.

§stop_sequences: Vec<String>

Strings that, if produced, terminate the response with crate::FinishReason::StopSequence.

§max_tokens: u32

Maximum output tokens the provider should generate this turn.

§tool_choice: Option<ToolChoice>

How the model should pick among the available tools. None leaves the provider default (typically Auto). Mapped to each provider’s wire format by the adapter.

§disable_parallel_tool_use: Option<bool>

Forbid the model from emitting more than one tool_use block per turn. None leaves the provider default (parallel allowed). Adapters lower this to the field their API expects: tool_choice.disable_parallel_tool_use for Anthropic, parallel_tool_calls (negated) for Chat Completions.

§additional_params: Option<Value>

Free-form JSON merged into the provider’s request body. Escape hatch for provider-specific knobs not yet typed in the shared shape (Anthropic thinking, OpenAI reasoning_effort, future betas). Adapters merge this last so it can override any field the typed surface set.

Implementations§

Source§

impl ChatRequest

Source

pub fn new(messages: Vec<Message>, max_tokens: u32) -> Self

Build a request with the given history and token cap; every other field takes its Default value. Use ..Default::default() in struct-update form when more than these two fields are set.

Trait Implementations§

Source§

impl Clone for ChatRequest

Source§

fn clone(&self) -> ChatRequest

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 Default for ChatRequest

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.