Skip to main content

CompletionRequest

Struct CompletionRequest 

Source
pub struct CompletionRequest {
Show 25 fields pub model: Option<String>, pub messages: Vec<Message>, pub tools: Option<Vec<ToolDefinition>>, pub tool_choice: Option<ToolChoice>, pub response_format: Option<ResponseFormat>, pub temperature: Option<f32>, pub max_tokens: Option<usize>, pub max_completion_tokens: Option<usize>, pub top_p: Option<f32>, pub top_k: Option<u32>, pub stop: Option<Vec<String>>, pub frequency_penalty: Option<f32>, pub presence_penalty: Option<f32>, pub seed: Option<u64>, pub reasoning_effort: Option<ReasoningEffort>, pub logprobs: Option<bool>, pub logit_bias: Option<HashMap<String, f32>>, pub stream_include_usage: Option<bool>, pub parallel_tool_calls: Option<bool>, pub user: Option<String>, pub metadata: Option<HashMap<String, Value>>, pub store: Option<bool>, pub service_tier: Option<ServiceTier>, pub thinking: Option<ThinkingConfig>, pub request_id: String,
}
Expand description

统一请求类型 —— 数据平面(发给 LLM 的内容) 所有能力通过 option 字段开启,不需要多个方法

Fields§

§model: Option<String>

目标模型。为 None 时由路由层根据 RouteContext 决定。

§messages: Vec<Message>§tools: Option<Vec<ToolDefinition>>

提供可用工具列表

§tool_choice: Option<ToolChoice>

控制工具调用行为

§response_format: Option<ResponseFormat>

要求 LLM 按 JSON Schema 输出

§temperature: Option<f32>§max_tokens: Option<usize>§max_completion_tokens: Option<usize>

OpenAI o-series 使用 max_completion_tokens 而非 max_tokens

§top_p: Option<f32>§top_k: Option<u32>

top_k 采样参数(Claude、Gemini 支持)

§stop: Option<Vec<String>>§frequency_penalty: Option<f32>§presence_penalty: Option<f32>§seed: Option<u64>

随机种子,用于可复现输出(评测、调试场景必需)

§reasoning_effort: Option<ReasoningEffort>

推理努力程度(OpenAI o-series reasoning_effort / Claude thinking budget)

§logprobs: Option<bool>

返回 log probabilities(调试、结构化分析场景)

§logit_bias: Option<HashMap<String, f32>>

token 偏置(调整特定 token 的出现概率)

§stream_include_usage: Option<bool>

流式模式下是否在末尾返回 usage

§parallel_tool_calls: Option<bool>

并行工具调用控制(OpenAI parallel_tool_calls)

§user: Option<String>

终端用户标识(用于监控/滥用检测)

§metadata: Option<HashMap<String, Value>>

请求级元数据(OpenAI/Anthropic 支持,用于追踪/蒸馏)

§store: Option<bool>

是否存储请求以供蒸馏/评测(OpenAI store)

§service_tier: Option<ServiceTier>

服务处理层级(OpenAI/Anthropic)

§thinking: Option<ThinkingConfig>

思考模式控制(DeepSeek R1 thinking)

§request_id: String

请求唯一标识(用于 tracing,自动生成)

Implementations§

Source§

impl CompletionRequest

Source

pub fn new(model: impl Into<String>, messages: Vec<Message>) -> Self

Trait Implementations§

Source§

impl Clone for CompletionRequest

Source§

fn clone(&self) -> CompletionRequest

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 Debug for CompletionRequest

Source§

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

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

impl Default for CompletionRequest

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for CompletionRequest

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 CompletionRequest

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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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<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