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>
impl<N, M> ChatBody<N, M>
Sourcepub fn new(model: N, messages: M) -> Self
pub fn new(model: N, messages: M) -> Self
Create a new chat request body from a model and the first message batch.
Sourcepub fn add_message(self, message: M) -> Self
pub fn add_message(self, message: M) -> Self
Add one message to the conversation.
Sourcepub fn extend_messages(self, messages: impl IntoIterator<Item = M>) -> Self
pub fn extend_messages(self, messages: impl IntoIterator<Item = M>) -> Self
Add multiple messages to the conversation at once.
Sourcepub fn with_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_request_id(self, request_id: impl Into<String>) -> Self
Set the client-side request id (used for tracing/dedup).
Sourcepub fn with_do_sample(self, do_sample: bool) -> Self
pub fn with_do_sample(self, do_sample: bool) -> Self
Enable/disable sampling (do_sample).
Sourcepub fn with_temperature(self, temperature: f64) -> Self
pub fn with_temperature(self, temperature: f64) -> Self
Set the sampling temperature.
Sourcepub fn with_top_p(self, top_p: f64) -> Self
pub fn with_top_p(self, top_p: f64) -> Self
Set the nucleus-sampling probability (top_p).
Sourcepub fn with_max_tokens(self, max_tokens: u32) -> Self
pub fn with_max_tokens(self, max_tokens: u32) -> Self
Set the maximum number of tokens to generate.
Sourcepub fn with_user_id(self, user_id: impl Into<String>) -> Self
pub fn with_user_id(self, user_id: impl Into<String>) -> Self
Set the end-user id (used for abuse monitoring).
Sourcepub fn with_stop(self, stop: impl Into<String>) -> Self
pub fn with_stop(self, stop: impl Into<String>) -> Self
Add a stop sequence that halts generation when encountered.
Sourcepub fn request_id(&self) -> Option<&str>
pub fn request_id(&self) -> Option<&str>
Client-provided request identifier.
Sourcepub const fn thinking(&self) -> Option<&ThinkingType>
pub const fn thinking(&self) -> Option<&ThinkingType>
Thinking configuration, when supported and configured.
Sourcepub const fn reasoning_effort(&self) -> Option<ReasoningEffort>
pub const fn reasoning_effort(&self) -> Option<ReasoningEffort>
Reasoning depth, when supported and configured.
Sourcepub const fn stream(&self) -> Option<bool>
pub const fn stream(&self) -> Option<bool>
Streaming flag managed by the ChatCompletion
type state.
Sourcepub const fn tool_stream(&self) -> Option<bool>
pub const fn tool_stream(&self) -> Option<bool>
Incremental tool-call flag managed by the streaming builder.
Sourcepub const fn temperature(&self) -> Option<f64>
pub const fn temperature(&self) -> Option<f64>
Configured sampling temperature.
Sourcepub const fn max_tokens(&self) -> Option<u32>
pub const fn max_tokens(&self) -> Option<u32>
Configured output-token limit.
Sourcepub const fn tool_choice(&self) -> Option<ToolChoice>
pub const fn tool_choice(&self) -> Option<ToolChoice>
Configured automatic tool-selection policy.
Sourcepub const fn response_format(&self) -> Option<ResponseFormat>
pub const fn response_format(&self) -> Option<ResponseFormat>
Text response format, when supported and configured.
Sourcepub const fn watermark_enabled(&self) -> Option<bool>
pub const fn watermark_enabled(&self) -> Option<bool>
Audio-model watermark setting, when configured.
Source§impl<N, M> ChatBody<N, M>
impl<N, M> ChatBody<N, M>
Sourcepub fn add_tools(self, tools: impl IntoIterator<Item = N::Tool>) -> Self
pub fn add_tools(self, tools: impl IntoIterator<Item = N::Tool>) -> Self
Add multiple schema-compatible tools.
Sourcepub fn with_tool_choice(self, tool_choice: ToolChoice) -> Self
pub fn with_tool_choice(self, tool_choice: ToolChoice) -> Self
Let the model choose automatically among the attached tools.
Sourcepub fn clear_tools(self) -> Self
pub fn clear_tools(self) -> Self
Remove attached tools and their selection policy.
Source§impl<N, M> ChatBody<N, M>
impl<N, M> ChatBody<N, M>
Sourcepub fn with_response_format(self, format: ResponseFormat) -> Self
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>
impl<N, M> ChatBody<N, M>
Sourcepub fn with_watermark_enabled(self, enabled: bool) -> Self
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>
impl<N, M> ChatBody<N, M>
Sourcepub fn with_thinking(self, thinking: ThinkingType) -> Self
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>
impl<N, M> ChatBody<N, M>
Sourcepub fn with_reasoning_effort(self, effort: ReasoningEffort) -> Self
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);