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: OpenAIConfigWhich provider, and how to reach it.
model: StringThe model this wire addresses.
strict_tools: boolWhether 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: boolWhether tool-result messages serialize their content as arrays.
Implementations§
Source§impl Chat
impl Chat
Sourcepub fn new(provider: OpenAIConfig, model: impl Into<String>) -> Self
pub fn new(provider: OpenAIConfig, model: impl Into<String>) -> Self
The wire for model on provider, with every option off.
Sourcepub fn with_strict_tools(self) -> Self
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.
Sourcepub fn with_tool_result_array_content(self) -> Self
pub fn with_tool_result_array_content(self) -> Self
Serialize tool-result content as arrays.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Chat
impl<'de> Deserialize<'de> for Chat
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<Chat> for OpenAiWire
impl From<Chat> for OpenAiWire
Source§impl ReplayTarget for Chat
impl ReplayTarget for Chat
Source§fn map_options(
&self,
request: &CompletionRequest,
fields: OptionFields<'_>,
) -> OptionMap
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
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
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
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>
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
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
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 call_id_slot(&self) -> Option<&'static str>
fn call_id_slot(&self) -> Option<&'static str>
Source§fn later_system(&self, _model: &str) -> LaterSystem
fn later_system(&self, _model: &str) -> LaterSystem
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
fn continues_stored(&self, request: &CompletionRequest) -> bool
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
fn declares_tools(&self, request: &CompletionRequest) -> bool
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
fn states_finish_reason(&self) -> bool
supportsFinishReason); a wire
with no finish vocabulary, such as a local runtime, says false.Source§fn binds_context(&self, model: &str) -> bool
fn binds_context(&self, model: &str) -> bool
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
fn drops_unbound_items(&self, request: &CompletionRequest) -> bool
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>
fn route(&self, request: &CompletionRequest) -> Option<&dyn ReplayTarget>
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
fn takes_documents(&self) -> bool
Source§fn needs_next(&self, item: &Value) -> bool
fn needs_next(&self, item: &Value) -> bool
Source§fn hosted_pair(&self, item: &Value) -> Option<(Pairing, String)>
fn hosted_pair(&self, item: &Value) -> Option<(Pairing, String)>
Source§fn starts_with_user(&self) -> bool
fn starts_with_user(&self) -> bool
adapt then drops the
assistant turns before the first user message, with their results.Source§fn alternates_roles(&self) -> bool
fn alternates_roles(&self) -> bool
adapt then joins two messages of one role that only system
messages separate, which move after them.Source§fn hosted_needs_tools(&self) -> bool
fn hosted_needs_tools(&self) -> bool
impl StructuralPartialEq for Chat
Source§impl Wire for Chat
impl Wire for Chat
Source§fn describe(&self) -> Descriptor<'_>
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
type Op = Completion
Source§type Payload = Encoded
type Payload = Encoded
Self::encode produces for the transport to send.Source§type Reassembler = ChatCompletion
type Reassembler = ChatCompletion
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>
fn encode( &self, request: CompletionRequest, mode: Mode, ) -> Result<Encoded, EncodeError>
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 reassembler(&self) -> Self::Reassembler
fn reassembler(&self) -> Self::Reassembler
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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