Skip to main content

ChatCompletionRequest

Struct ChatCompletionRequest 

Source
pub struct ChatCompletionRequest {
Show 14 fields pub model: String, pub messages: Vec<Message>, pub stream: Option<bool>, pub stream_options: Option<StreamOptions>, pub temperature: Option<f32>, pub top_p: Option<f32>, pub top_k: Option<u32>, pub seed: Option<u64>, pub max_tokens: Option<u32>, pub max_completion_tokens: Option<u32>, pub stop: Option<StringOrArray>, pub n: Option<u32>, pub tools: Option<Vec<Value>>, pub tool_choice: Option<Value>,
}
Expand description

A POST /v1/chat/completions body.

Unknown fields are ignored rather than rejected — a client that sends a parameter this build does not implement gets an answer, not a 400 — so the fields listed here are the ones that change behaviour, not the ones that are legal.

Fields§

§model: String

Whatever the client called the model. Echoed back unexamined: this server serves exactly one install, so validating the name could only refuse requests it is able to answer.

§messages: Vec<Message>

The conversation. Must be non-empty.

§stream: Option<bool>

Stream the reply as SSE.

§stream_options: Option<StreamOptions>

Streaming extras.

§temperature: Option<f32>

Softmax temperature.

§top_p: Option<f32>

Nucleus-sampling mass.

§top_k: Option<u32>

Top-k cutoff. Not an OpenAI field; accepted because llama.cpp accepts it and local tooling sends it.

§seed: Option<u64>

PRNG seed.

§max_tokens: Option<u32>

Reply length cap, the older spelling.

§max_completion_tokens: Option<u32>

Reply length cap, the current spelling. Wins when both appear.

§stop: Option<StringOrArray>

Stop sequences.

§n: Option<u32>

How many completions to return. Anything above 1 is refused.

§tools: Option<Vec<Value>>

Tool definitions, preserved verbatim.

Held as raw JSON rather than a typed schema because the renderer takes them that way: each definition is serialized into the # Tools system block exactly as it arrived, so a Rust shape here could only lose fields (strict, vendor extensions) that the reference template keeps.

§tool_choice: Option<Value>

Tool selection policy. Only auto and none are honourable here; see ChatCompletionRequest::check_tool_choice.

Implementations§

Source§

impl ChatCompletionRequest

Source

pub fn from_json(body: &str) -> Result<Self, ServerError>

Parse a request body.

Every byte here is untrusted, so serde’s failure is captured as a message rather than propagated as a panic or an opaque 500.

Source

pub fn validate(&self) -> Result<(), ServerError>

Check everything that can be checked without a tokenizer.

Called before any work is scheduled, so a request that cannot be served never reaches the decode loop and never occupies the single session.

Source

pub fn tools(&self) -> &[Value]

The tool definitions, empty when none were sent.

Source

pub fn check_tools(&self) -> Result<(), ServerError>

Refuse a tool definition whose name the model could not call back.

Separate from validate so crate::prompt::build, which is the thing that actually renders these, enforces it too rather than trusting that validation ran.

Source

pub fn check_tool_choice(&self) -> Result<(), ServerError>

Refuse a tool_choice this build cannot honour.

auto, none and absent are accepted and all render the same prompt, because that is what the template does: it branches on tools alone and has no way to say “you must call something”. required and a named function therefore cannot be expressed at all, and serving them by letting the model choose freely would drop the one constraint the request was about.

Source

pub fn stream(&self) -> bool

Whether to stream. Absent means false.

Source

pub fn include_usage(&self) -> bool

Whether to emit the usage-only chunk. Absent means false.

Source

pub fn max_new_tokens(&self) -> Option<u32>

The reply length cap.

max_completion_tokens is the current spelling and max_tokens the deprecated alias; when both arrive the newer one wins, because a client that sends both is an SDK filling in a compatibility field behind a caller who set the modern one.

Source

pub fn stop_sequences(&self) -> &[String]

The stop sequences, empty when none were sent.

Read by validate only, to refuse a non-empty one. When the runtime grows stop strings this becomes the accessor that feeds them; until then it exists so the refusal has one definition of “sent a stop sequence” across both stop spellings.

Trait Implementations§

Source§

impl Clone for ChatCompletionRequest

Source§

fn clone(&self) -> Self

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 ChatCompletionRequest

Source§

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

Formats the value using the given formatter. 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 PartialEq for ChatCompletionRequest

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

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

impl StructuralPartialEq for ChatCompletionRequest

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<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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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