Skip to main content

Chat

Struct Chat 

Source
pub struct Chat {
    pub provider: OpenAIConfig,
    pub model: String,
    pub strict_tools: bool,
    pub tool_result_array_content: bool,
}
Expand description

The chat-completions wire: a provider configuration, a model, and the per-turn options the endpoint takes.

Fields§

§provider: OpenAIConfig

Which provider, and how to reach it.

§model: String

The model this wire addresses.

§strict_tools: bool

Whether tool schemas are sanitized for OpenAI’s strict mode: additionalProperties: false on every object, every property required, and strict: true on each function definition.

§tool_result_array_content: bool

Whether tool-result messages serialize their content as arrays.

Implementations§

Source§

impl Chat

Source

pub fn new(provider: OpenAIConfig, model: impl Into<String>) -> Self

The wire for model on provider, with every option off.

Source

pub fn with_strict_tools(self) -> Self

Sanitize tool schemas for OpenAI’s strict mode, so the provider can guarantee a tool call matches its schema exactly.

Source

pub fn with_tool_result_array_content(self) -> Self

Serialize tool-result content as arrays.

Trait Implementations§

Source§

impl Clone for Chat

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 Chat

Source§

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

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

impl<'de> Deserialize<'de> for Chat

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 From<Chat> for OpenAiWire

Source§

fn from(wire: Chat) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Chat

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 ReplayTarget for Chat

Source§

fn map_options( &self, request: &CompletionRequest, fields: OptionFields<'_>, ) -> OptionMap

Section 6.2 of the typed-options design, by dialect.

Source§

fn accepts(&self, model: &str) -> Accepts

Chat reads no images in assistant messages, images in tool results only on a dialect that says so, and tools where the dialect takes them. Which models read user images follows each provider’s documented model rules (reads_images).

Source§

fn encodes(&self, _model: &str, media: Media<'_>) -> bool

What the Chat encoder carries, by dialect: an image as a URL or typed data; audio as data; video as a URL or typed data, except to OpenAI, Azure and Mistral; a PDF as data, or as a URL OpenRouter or Mistral fetches; a file id where the dialect takes one; and a string document as text. DeepSeek and Mira take text only; Perplexity and Cohere take no media but images, and Ollama only images as data.

Source§

fn normalize_tool_call_id( &self, id: &str, _model: &str, _: Option<&Origin>, ) -> String

pi’s rule for this wire. A call|item id joins its sanitized halves with _, ending a result over 40 characters in a hash of the whole id; OpenAI’s own ids are cut to 40; any other id is kept. Mistral takes any such id (checked live on eight models), where pi derives nine alphanumerics.

Source§

fn identity(&self, item: &Value) -> Map<String, Value>

What an edited block keeps of its item: a custom call’s kind and Mistral’s thinking part (type), or the field reasoning arrived in, as pi keeps thinkingSignature. Signed data such as reasoning_details never survives an edit.

Source§

fn result_parts(&self, _model: &str) -> bool

In array mode a result’s parts go as an array.

Source§

fn sends_alone(&self, block: &AssistantContent) -> bool

A Chat message needs content or calls, as pi’s rebuild does: text only when it is not empty or its item carries audio, reasoning only as a content part (Mistral’s thinking), an opaque item only as a typed part, and never an image.

Source§

fn api(&self) -> Api

The wire format.
Source§

fn provider(&self) -> &str

The provider descriptor name.
Source§

fn model(&self) -> &str

The model id the wire addresses.
Source§

fn call_id_slot(&self) -> Option<&'static str>

Where a tool call’s id sits in this wire’s call item, as a JSON pointer, when it has one. Replay writes the call’s wire id there, so a replayed item and its result always agree, and a call the provider sent without an id keeps its item only on a wire with a slot.
Source§

fn later_system(&self, _model: &str) -> LaterSystem

Where model takes system messages that come after the conversation begins (LaterSystem). By default where the history has them.
Source§

fn continues_stored(&self, request: &CompletionRequest) -> bool

Whether request continues a conversation the provider stores, such as one naming a previous interaction. Results before the history’s first turn then answer calls the provider holds, so adapt keeps them.
Source§

fn declares_tools(&self, request: &CompletionRequest) -> bool

Whether request declares tools to the provider, in tools, in the tools of its additional_params, or through tools the wire adds. A request that declares none gets its history’s calls and results as text. ToolChoice::None still declares them: the wire sends its own none choice beside the tool history.
Source§

fn states_finish_reason(&self) -> bool

Whether every reply on this wire states why it stopped. A reply that then names no reason failed (pi’s supportsFinishReason); a wire with no finish vocabulary, such as a local runtime, says false.
Source§

fn binds_context(&self, model: &str) -> bool

Whether model binds its provider items to the request’s tools and system prompt, so a turn made under another context replays as if from another model.
Source§

fn drops_unbound_items(&self, request: &CompletionRequest) -> bool

Whether request asks the provider to drop an item bound to another context itself (Anthropic’s drop_block), so a turn made under another context replays verbatim rather than as another model’s.
Source§

fn route(&self, request: &CompletionRequest) -> Option<&dyn ReplayTarget>

The target request is sent to, for a wire that picks its API per request. Preparing the request and folding its reply both read the target this names, so a turn records the API it was made on. None, the default, is this target.
Source§

fn takes_documents(&self) -> bool

Whether the encoder sends a request’s documents itself. Otherwise they join the history as text before it is adapted.
Source§

fn needs_next(&self, item: &Value) -> bool

Whether this provider item requires the item after it in its turn (Responses reasoning): when that one is not replayed, neither is this.
Source§

fn hosted_pair(&self, item: &Value) -> Option<(Pairing, String)>

The hosted-tool pair this opaque item belongs to: whether it is the use or the result, and the id they share. A use and its result replay only together, in one turn or across the model’s turns. A use still running when the last turn ended (a paused turn, or one whose client call the hosted tool made) replays alone.
Source§

fn starts_with_user(&self) -> bool

Whether the wire rejects a conversation whose first message after the system prompt is not a user message. adapt then drops the assistant turns before the first user message, with their results.
Source§

fn alternates_roles(&self) -> bool

Whether the wire requires user and assistant messages to alternate. adapt then joins two messages of one role that only system messages separate, which move after them.
Source§

fn hosted_needs_tools(&self) -> bool

Whether a hosted tool’s use and result need the request to declare tools. A request that declares none then sends neither.
Source§

impl Serialize for Chat

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 Chat

Source§

impl Wire for Chat

Source§

fn describe(&self) -> Descriptor<'_>

Format deferral permits tool composition; dialects without schema support require the agent’s tool-mode enforcement instead.

Source§

type Op = Completion

The operation this wire performs.
Source§

type Payload = Encoded

What Self::encode produces for the transport to send.
Source§

type Frame = WireFrame

One unit of a reply, as the transport delivers it.
Source§

type Decoder<'id> = ChatDecoder

The decoder for one of its replies, branded with that reply.
Source§

type Reassembler = ChatCompletion

What rebuilds a reply’s provider document from its frames when the transport reports no whole document, as for a stream. The driver feeds it every frame and records what it finishes with as raw. A wire whose operation’s decoders record raw themselves names document::Unreassembled; a completion wire cannot, because it does not Serve completions.
Source§

fn encode( &self, request: CompletionRequest, mode: Mode, ) -> Result<Encoded, EncodeError>

The request to send. Pure: it may read self, request and mode, and nothing else. A request that cannot be built is an EncodeError, which always reports as a request failure.
Source§

fn decoder<'id>(&self) -> Self::Decoder<'id>

A fresh decoder for one reply.
Source§

fn reassembler(&self) -> Self::Reassembler

A fresh reassembler for one reply. A wire that picks its API per reply builds the matching one.

Auto Trait Implementations§

§

impl Freeze for Chat

§

impl RefUnwindSafe for Chat

§

impl Send for Chat

§

impl Sync for Chat

§

impl Unpin for Chat

§

impl UnsafeUnpin for Chat

§

impl UnwindSafe for Chat

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> IntoToolOutput for T
where T: Serialize + 'static,

Source§

fn into_tool_output(self) -> Result<ToolOutput, ToolExecutionError>

Convert this value without routing structured data through a string.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmCompatSend for T
where T: Send,

Source§

impl<T> WasmCompatSync for T
where T: Sync,

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