pub struct ChatCompletionRequest {
pub model: String,
pub messages: Vec<Message>,
pub temperature: Option<f32>,
pub max_tokens: Option<u32>,
pub top_p: Option<f32>,
pub frequency_penalty: Option<f32>,
pub presence_penalty: Option<f32>,
pub stream: Option<bool>,
pub tools: Option<Vec<Tool>>,
}Expand description
Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Wire types for chat completion requests, responses, and streaming.
Chat completion request, response, and message types.
Request body for the POST chat/completions endpoint.
Uses the Former builder pattern for ergonomic construction.
§Examples
use api_openai_compatible::{ ChatCompletionRequest, Message };
let req = ChatCompletionRequest::former()
.model( "gpt-4o".to_string() )
.messages( vec![ Message::user( "Hello!" ) ] )
.max_tokens( 100_u32 )
.form();Fields§
§model: StringModel identifier (e.g. "gpt-4o", "grok-2-1212").
messages: Vec<Message>Ordered list of conversation messages.
temperature: Option<f32>Sampling temperature in [0.0, 2.0]. Higher = more random.
max_tokens: Option<u32>Maximum tokens to generate in the completion.
top_p: Option<f32>Nucleus sampling threshold in [0.0, 1.0].
frequency_penalty: Option<f32>Frequency penalty in [0.0, 2.0] (reduces token repetition).
presence_penalty: Option<f32>Presence penalty in [0.0, 2.0] (encourages topic diversity).
stream: Option<bool>When true, the response is streamed as Server-Sent Events.
tools: Option<Vec<Tool>>Tool definitions available for function calling.
Implementations§
Source§impl ChatCompletionRequest
impl ChatCompletionRequest
Sourcepub fn former() -> ChatCompletionRequestFormer<ChatCompletionRequestFormerDefinition<(), ChatCompletionRequest, ReturnPreformed>>
pub fn former() -> ChatCompletionRequestFormer<ChatCompletionRequestFormerDefinition<(), ChatCompletionRequest, ReturnPreformed>>
Provides a mechanism to initiate the formation process with a default completion behavior.
Trait Implementations§
Source§impl Clone for ChatCompletionRequest
impl Clone for ChatCompletionRequest
Source§fn clone(&self) -> ChatCompletionRequest
fn clone(&self) -> ChatCompletionRequest
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ChatCompletionRequest
impl Debug for ChatCompletionRequest
Source§impl<'de> Deserialize<'de> for ChatCompletionRequest
impl<'de> Deserialize<'de> for ChatCompletionRequest
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>,
Source§impl<__Context, __Formed, __End> EntityToDefinition<__Context, __Formed, __End> for ChatCompletionRequestwhere
__End: FormingEnd<ChatCompletionRequestFormerDefinitionTypes<__Context, __Formed>>,
impl<__Context, __Formed, __End> EntityToDefinition<__Context, __Formed, __End> for ChatCompletionRequestwhere
__End: FormingEnd<ChatCompletionRequestFormerDefinitionTypes<__Context, __Formed>>,
Source§type Definition = ChatCompletionRequestFormerDefinition<__Context, __Formed, __End>
type Definition = ChatCompletionRequestFormerDefinition<__Context, __Formed, __End>
FormerDefinition associated with this entity. Read moreSource§type Types = ChatCompletionRequestFormerDefinitionTypes<__Context, __Formed>
type Types = ChatCompletionRequestFormerDefinitionTypes<__Context, __Formed>
FormerDefinitionTypes associated with this entity. Read moreSource§impl<__Context, __Formed> EntityToDefinitionTypes<__Context, __Formed> for ChatCompletionRequest
impl<__Context, __Formed> EntityToDefinitionTypes<__Context, __Formed> for ChatCompletionRequest
Source§impl<Definition> EntityToFormer<Definition> for ChatCompletionRequestwhere
Definition: FormerDefinition<Storage = ChatCompletionRequestFormerStorage>,
impl<Definition> EntityToFormer<Definition> for ChatCompletionRequestwhere
Definition: FormerDefinition<Storage = ChatCompletionRequestFormerStorage>,
Source§impl PartialEq for ChatCompletionRequest
impl PartialEq for ChatCompletionRequest
Source§fn eq(&self, other: &ChatCompletionRequest) -> bool
fn eq(&self, other: &ChatCompletionRequest) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for ChatCompletionRequest
impl Serialize for ChatCompletionRequest
impl StructuralPartialEq for ChatCompletionRequest
Auto Trait Implementations§
impl Freeze for ChatCompletionRequest
impl RefUnwindSafe for ChatCompletionRequest
impl Send for ChatCompletionRequest
impl Sync for ChatCompletionRequest
impl Unpin for ChatCompletionRequest
impl UnsafeUnpin for ChatCompletionRequest
impl UnwindSafe for ChatCompletionRequest
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<C, E> EntryToVal<C> for Ewhere
C: Collection<Entry = E>,
impl<C, E> EntryToVal<C> for Ewhere
C: Collection<Entry = E>,
Source§type Val = <C as Collection>::Val
type Val = <C as Collection>::Val
Entry in complex collections.
For example, in a HashMap, while Entry might be a ( key, value ) tuple, Val might only be the value part.Source§fn entry_to_val(self) -> <E as EntryToVal<C>>::Val
fn entry_to_val(self) -> <E as EntryToVal<C>>::Val
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<C, Val> ValToEntry<C> for Valwhere
C: CollectionValToEntry<Val>,
impl<C, Val> ValToEntry<C> for Valwhere
C: CollectionValToEntry<Val>,
Source§fn val_to_entry(self) -> <C as CollectionValToEntry<Val>>::Entry
fn val_to_entry(self) -> <C as CollectionValToEntry<Val>>::Entry
Invokes the val_to_entry function of the CollectionValToEntry trait to convert the value to an entry.
Source§type Entry = <C as CollectionValToEntry<Val>>::Entry
type Entry = <C as CollectionValToEntry<Val>>::Entry
Entry is defined by the Collection trait.