pub struct ChatRequest {Show 13 fields
pub model: String,
pub messages: Vec<Message>,
pub tools: Option<Vec<ToolDefinition>>,
pub temperature: Option<f64>,
pub max_tokens: Option<u32>,
pub top_p: Option<f64>,
pub seed: Option<u64>,
pub tool_choice: Option<ToolChoice>,
pub stop_sequences: Option<Vec<String>>,
pub prefill: Option<String>,
pub reasoning: Option<ReasoningConfig>,
pub max_reasoning_tokens: Option<u32>,
pub extra: Option<Map<String, Value>>,
}Expand description
统一的聊天请求。
Fields§
§model: String§messages: Vec<Message>§tools: Option<Vec<ToolDefinition>>§temperature: Option<f64>§max_tokens: Option<u32>§top_p: Option<f64>§seed: Option<u64>§tool_choice: Option<ToolChoice>§stop_sequences: Option<Vec<String>>§prefill: Option<String>§reasoning: Option<ReasoningConfig>推理配置 — 控制模型是否进行深度推理。
None = 不干预 Provider 默认行为
Some(Disabled) = 显式关闭推理
Some(Low/Medium/High) = 开启对应级别的推理
max_reasoning_tokens: Option<u32>单次 LLM 调用的推理 Token 上限(可选,默认无限制)。
与 max_tokens 分离:reasoning 是模型内部推理,不计入输出预算。
透传给 Provider Adapter,由 Adapter 映射为协议特定字段。
两种语义:
- 流式: Hard limit — 达到限额当场切断 stream,省钱
- 非流式: Soft limit — response 已完整返回,事后检测并标记
Adapter 映射示例:
- DeepSeek:
max_thinking_tokens - OpenAI: 无直接对应,由
reasoning级别间接控制 - 其他: 放入
extra或忽略
extra: Option<Map<String, Value>>Provider 特有参数(如 OpenAI 的 presence_penalty),由 Adapter 自行处理。
Implementations§
Source§impl ChatRequest
impl ChatRequest
Sourcepub fn user_prompt(prompt: String) -> Self
pub fn user_prompt(prompt: String) -> Self
便捷构造:单条用户消息
pub fn with_temperature(self, temp: f64) -> Self
pub fn with_max_tokens(self, max: u32) -> Self
pub fn with_top_p(self, top_p: f64) -> Self
pub fn with_seed(self, seed: u64) -> Self
pub fn with_model(self, model: String) -> Self
pub fn with_tools(self, tools: Vec<ToolDefinition>) -> Self
Sourcepub fn with_system_prompt(self, prompt: String) -> Self
pub fn with_system_prompt(self, prompt: String) -> Self
便捷构造:单条系统消息
Sourcepub fn with_reasoning(self, reasoning: ReasoningConfig) -> Self
pub fn with_reasoning(self, reasoning: ReasoningConfig) -> Self
设置推理配置
Sourcepub fn with_max_reasoning_tokens(self, max: u32) -> Self
pub fn with_max_reasoning_tokens(self, max: u32) -> Self
设置单次调用的推理 Token 上限
Sourcepub fn with_extra(self, extra: Map<String, Value>) -> Self
pub fn with_extra(self, extra: Map<String, Value>) -> Self
设置 Provider 特有参数
Trait Implementations§
Source§impl Clone for ChatRequest
impl Clone for ChatRequest
Source§fn clone(&self) -> ChatRequest
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ChatRequest
impl Debug for ChatRequest
Source§impl Default for ChatRequest
impl Default for ChatRequest
Source§fn default() -> ChatRequest
fn default() -> ChatRequest
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for ChatRequest
impl<'de> Deserialize<'de> for ChatRequest
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for ChatRequest
impl RefUnwindSafe for ChatRequest
impl Send for ChatRequest
impl Sync for ChatRequest
impl Unpin for ChatRequest
impl UnsafeUnpin for ChatRequest
impl UnwindSafe for ChatRequest
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
Mutably borrows from an owned value. Read more