Skip to main content

ChatBody

Struct ChatBody 

Source
pub struct ChatBody<N, M>{ /* private fields */ }
Expand description

Validated request body for a chat-completion operation.

This type stores the union of frozen chat request fields. Its fields are private, and capability-gated builders expose only the subset accepted by the selected text, vision, or audio model family.

§Examples

use zai_rs::model::{
    chat_base_request::ChatBody,
    chat_message_types::TextMessage,
    chat_models::GLM5_2,
};

let chat_body = ChatBody::new(GLM5_2 {}, TextMessage::user("Hello"))
    .add_message(TextMessage::assistant("How can I help?"))
    .with_temperature(0.7)
    .with_max_tokens(1_000);

Implementations§

Source§

impl<N, M> ChatBody<N, M>

Source

pub fn new(model: N, messages: M) -> Self

Create a new chat request body from a model and the first message batch.

Source

pub fn add_message(self, message: M) -> Self

Add one message to the conversation.

Source

pub fn extend_messages(self, messages: impl IntoIterator<Item = M>) -> Self

Add multiple messages to the conversation at once.

Source

pub fn with_request_id(self, request_id: impl Into<String>) -> Self

Set the client-side request id (used for tracing/dedup).

Source

pub fn with_do_sample(self, do_sample: bool) -> Self

Enable/disable sampling (do_sample).

Source

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

Set the sampling temperature.

Source

pub fn with_top_p(self, top_p: f64) -> Self

Set the nucleus-sampling probability (top_p).

Source

pub fn with_max_tokens(self, max_tokens: u32) -> Self

Set the maximum number of tokens to generate.

Source

pub fn with_user_id(self, user_id: impl Into<String>) -> Self

Set the end-user id (used for abuse monitoring).

Source

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

Add a stop sequence that halts generation when encountered.

Source

pub const fn model(&self) -> &N

Borrow the selected model.

Source

pub fn messages(&self) -> &[M]

Borrow the complete conversation in wire order.

Source

pub fn request_id(&self) -> Option<&str>

Client-provided request identifier.

Source

pub const fn thinking(&self) -> Option<&ThinkingType>

Thinking configuration, when supported and configured.

Source

pub const fn reasoning_effort(&self) -> Option<ReasoningEffort>

Reasoning depth, when supported and configured.

Source

pub const fn do_sample(&self) -> Option<bool>

Explicit sampling toggle.

Source

pub const fn stream(&self) -> Option<bool>

Streaming flag managed by the ChatCompletion type state.

Source

pub const fn tool_stream(&self) -> Option<bool>

Incremental tool-call flag managed by the streaming builder.

Source

pub const fn temperature(&self) -> Option<f64>

Configured sampling temperature.

Source

pub const fn top_p(&self) -> Option<f64>

Configured nucleus-sampling probability.

Source

pub const fn max_tokens(&self) -> Option<u32>

Configured output-token limit.

Source

pub fn tools(&self) -> Option<&[Tools]>

Attached tools, if this model family supports them.

Source

pub const fn tool_choice(&self) -> Option<ToolChoice>

Configured automatic tool-selection policy.

Source

pub fn user_id(&self) -> Option<&str>

End-user identifier used for abuse monitoring.

Source

pub fn stop(&self) -> Option<&[String]>

Borrow configured stop sequences.

Source

pub const fn response_format(&self) -> Option<ResponseFormat>

Text response format, when supported and configured.

Source

pub const fn watermark_enabled(&self) -> Option<bool>

Audio-model watermark setting, when configured.

Source§

impl<N, M> ChatBody<N, M>

Source

pub fn add_tool(self, tool: N::Tool) -> Self

Add one schema-compatible tool.

Source

pub fn add_tools(self, tools: impl IntoIterator<Item = N::Tool>) -> Self

Add multiple schema-compatible tools.

Source

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

Let the model choose automatically among the attached tools.

Source

pub fn clear_tools(self) -> Self

Remove attached tools and their selection policy.

Source§

impl<N, M> ChatBody<N, M>

Source

pub fn with_response_format(self, format: ResponseFormat) -> Self

Set the response format for a text chat model.

Source§

impl<N, M> ChatBody<N, M>

Source

pub fn with_watermark_enabled(self, enabled: bool) -> Self

Enable or disable provider watermarking for audio-model output.

Source§

impl<N, M> ChatBody<N, M>

Source

pub fn with_thinking(self, thinking: ThinkingType) -> Self

Configure extended reasoning for a model that implements ThinkEnable.

§Examples
use zai_rs::model::{
    chat_base_request::ChatBody,
    chat_message_types::TextMessage,
    chat_models::GLM5_2,
    tools::ThinkingType,
};

let chat_body = ChatBody::new(GLM5_2 {}, TextMessage::user("Solve this"))
    .with_thinking(ThinkingType::enabled());
Source§

impl<N, M> ChatBody<N, M>

Source

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

Set the reasoning_effort level that controls how much reasoning the model performs when thinking mode is enabled.

Available only for models implementing ReasoningEffortEnable. Typically combined with with_thinking to enable thinking first.

§Examples
use zai_rs::model::{
    GLM5_2, TextMessage,
    chat_base_request::ChatBody,
    tools::{ReasoningEffort, ThinkingType},
};

let chat_body = ChatBody::new(GLM5_2 {}, TextMessage::user("Solve this"))
    .with_thinking(ThinkingType::enabled())
    .with_reasoning_effort(ReasoningEffort::Max);

Trait Implementations§

Source§

impl<N, M> Clone for ChatBody<N, M>

Source§

fn clone(&self) -> ChatBody<N, M>

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<N, M> Debug for ChatBody<N, M>

Source§

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

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

impl<N, M> Serialize for ChatBody<N, M>

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<N, M> Validate for ChatBody<N, M>

Source§

impl<'v_a, N, M> ValidateArgs<'v_a> for ChatBody<N, M>

Auto Trait Implementations§

§

impl<N, M> Freeze for ChatBody<N, M>
where N: Freeze,

§

impl<N, M> RefUnwindSafe for ChatBody<N, M>

§

impl<N, M> Send for ChatBody<N, M>
where N: Send, M: Send,

§

impl<N, M> Sync for ChatBody<N, M>
where N: Sync, M: Sync,

§

impl<N, M> Unpin for ChatBody<N, M>
where N: Unpin, M: Unpin,

§

impl<N, M> UnsafeUnpin for ChatBody<N, M>
where N: UnsafeUnpin,

§

impl<N, M> UnwindSafe for ChatBody<N, M>
where N: UnwindSafe, M: UnwindSafe,

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> 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> 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 = 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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