Skip to main content

ChatCompletionRequest

Struct ChatCompletionRequest 

Source
pub struct ChatCompletionRequest {
Show 16 fields pub messages: Vec<Message>, pub model: Model, pub thinking: Option<Thinking>, pub frequency_penalty: Option<f32>, pub max_tokens: Option<u32>, pub presence_penalty: Option<f32>, pub response_format: Option<ResponseFormat>, pub stop: Option<Stop>, pub stream: Option<bool>, pub stream_options: Option<StreamOptions>, pub temperature: Option<f32>, pub top_p: Option<f32>, pub tools: Option<Vec<Tool>>, pub tool_choice: Option<ToolChoice>, pub logprobs: Option<bool>, pub top_logprobs: Option<u32>,
}

Fields§

§messages: Vec<Message>

对话的消息列表。

§model: Model

使用的模型的 ID。您可以使用 deepseek-chat 来获得更快的响应速度,或者使用 deepseek-reasoner 来获得更深入的推理能力。

§thinking: Option<Thinking>

控制思考模式与非思考模式的转换

§frequency_penalty: Option<f32>

Possible values: >= -2 and <= 2 Default value: 0 介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其在已有文本中的出现频率受到相应的惩罚,降低模型重复相同内容的可能性。

§max_tokens: Option<u32>

限制一次请求中模型生成 completion 的最大 token 数。输入 token 和输出 token 的总长度受模型的上下文长度的限制。取值范围与默认值详见文档。

§presence_penalty: Option<f32>

Possible values: >= -2 and <= 2 Default value: 0 介于 -2.0 和 2.0 之间的数字。如果该值为正,那么新 token 会根据其是否已在已有文本中出现受到相应的惩罚,从而增加模型谈论新主题的可能性。

§response_format: Option<ResponseFormat>

一个 object,指定模型必须输出的格式。 设置为 { “type”: “json_object” } 以启用 JSON 模式,该模式保证模型生成的消息是有效的 JSON。 注意: 使用 JSON 模式时,你还必须通过系统或用户消息指示模型生成 JSON。否则,模型可能会生成不断的空白字符,直到生成达到令牌限制,从而导致请求长时间运行并显得“卡住”。此外,如果 finish_reason=“length”,这表示生成超过了 max_tokens 或对话超过了最大上下文长度,消息内容可能会被部分截断。

§stop: Option<Stop>

一个 string 或最多包含 16 个 string 的 list,在遇到这些词时,API 将停止生成更多的 token。

§stream: Option<bool>

如果设置为 True,将会以 SSE(server-sent events)的形式以流式发送消息增量。消息流以 data: [DONE] 结尾。

§stream_options: Option<StreamOptions>

流式输出相关选项。只有在 stream 参数为 true 时,才可设置此参数。 include_usage: boolean 如果设置为 true,在流式消息最后的 data: [DONE] 之前将会传输一个额外的块。此块上的 usage 字段显示整个请求的 token 使用统计信息,而 choices 字段将始终是一个空数组。所有其他块也将包含一个 usage 字段,但其值为 null。

§temperature: Option<f32>

Possible values: <= 2 Default value: 1 采样温度,介于 0 和 2 之间。更高的值,如 0.8,会使输出更随机,而更低的值,如 0.2,会使其更加集中和确定。 我们通常建议可以更改这个值或者更改 top_p,但不建议同时对两者进行修改。

§top_p: Option<f32>

Possible values: <= 1 Default value: 1 作为调节采样温度的替代方案,模型会考虑前 top_p 概率的 token 的结果。所以 0.1 就意味着只有包括在最高 10% 概率中的 token 会被考虑。 我们通常建议修改这个值或者更改 temperature,但不建议同时对两者进行修改。

§tools: Option<Vec<Tool>>

模型可能会调用的 tool 的列表。目前,仅支持 function 作为工具。使用此参数来提供以 JSON 作为输入参数的 function 列表。最多支持 128 个 function。

§tool_choice: Option<ToolChoice>

控制模型调用 tool 的行为。 none 意味着模型不会调用任何 tool,而是生成一条消息。 auto 意味着模型可以选择生成一条消息或调用一个或多个 tool。 required 意味着模型必须调用一个或多个 tool。 通过 {“type”: “function”, “function”: {“name”: “my_function”}} 指定特定 tool,会强制模型调用该 tool。 当没有 tool 时,默认值为 none。如果有 tool 存在,默认值为 auto。

§logprobs: Option<bool>

logprobs boolean NULLABLE 是否返回所输出 token 的对数概率。如果为 true,则在 message 的 content 中返回每个输出 token 的对数概率。

§top_logprobs: Option<u32>

Possible values: <= 20 一个介于 0 到 20 之间的整数 N,指定每个输出位置返回输出概率 top N 的 token,且返回这些 token 的对数概率。指定此参数时,logprobs 必须为 true。

Trait Implementations§

Source§

impl Debug for ChatCompletionRequest

Source§

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

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

impl Default for ChatCompletionRequest

Source§

fn default() -> ChatCompletionRequest

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for ChatCompletionRequest

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 Serialize for ChatCompletionRequest

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

Auto Trait Implementations§

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<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: 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: 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, 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<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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,