Struct ChatCompletionRequest

Source
pub struct ChatCompletionRequest {
    pub model: String,
    pub messages: Vec<ChatCompletionMessage>,
    pub temperature: Option<f64>,
    pub max_tokens: Option<u32>,
    pub top_p: Option<f64>,
    pub stream: Option<bool>,
    pub stop: Option<Vec<String>>,
    pub seed: Option<u64>,
}
Expand description

Represents a request to the OpenAI chat completion API.

  • model: The language model to use for the chat completion.
  • messages: The messages to provide as context for the chat completion.
  • temperature: The temperature parameter to control the randomness of the generated response.
  • max_tokens: The maximum number of tokens to generate in the response.
  • top_p: The top-p parameter to control the nucleus sampling.
  • stream: Whether to stream the response or return it all at once.
  • stop: A list of strings to stop the generation when encountered.
  • seed: The seed value to use for the random number generator.

Fields§

§model: String§messages: Vec<ChatCompletionMessage>§temperature: Option<f64>§max_tokens: Option<u32>§top_p: Option<f64>§stream: Option<bool>§stop: Option<Vec<String>>§seed: Option<u64>

Implementations§

Source§

impl ChatCompletionRequest

Represents a request to the OpenAI chat completion API.

This struct provides a builder-style API for constructing a ChatCompletionRequest with various optional parameters. The new method creates a new instance with default values, and the other methods allow modifying individual parameters.

  • model: The language model to use for the chat completion.
  • messages: The messages to provide as context for the chat completion.
  • temperature: The temperature parameter to control the randomness of the generated response.
  • max_tokens: The maximum number of tokens to generate in the response.
  • top_p: The top-p parameter to control the nucleus sampling.
  • stream: Whether to stream the response or return it all at once.
  • stop: A list of strings to stop the generation when encountered.
  • seed: The seed value to use for the random number generator.
Source

pub fn new(model: &str, messages: Vec<ChatCompletionMessage>) -> Self

Creates a new ChatCompletionRequest instance with the given model and messages.

§Arguments
  • model - The language model to use for the chat completion.
  • messages - The messages to provide as context for the chat completion.
Source

pub fn temperature(self, temperature: f64) -> Self

Sets the temperature parameter for the chat completion request.

The temperature parameter controls the randomness of the generated response. Higher values (up to 1.0) make the output more random, while lower values make it more deterministic.

§Arguments
  • temperature - The temperature value to use.
Source

pub fn max_tokens(self, max_tokens: u32) -> Self

Sets the maximum number of tokens to generate in the response.

§Arguments
  • max_tokens - The maximum number of tokens to generate.
Source

pub fn top_p(self, top_p: f64) -> Self

Sets the top-p parameter for the chat completion request.

The top-p parameter controls the nucleus sampling, which is a technique for sampling from the most likely tokens.

§Arguments
  • top_p - The top-p value to use.
Source

pub fn stream(self, stream: bool) -> Self

Sets whether to stream the response or return it all at once.

§Arguments
  • stream - Whether to stream the response or not.
Source

pub fn stop(self, stop: Vec<String>) -> Self

Sets the list of strings to stop the generation when encountered.

§Arguments
  • stop - The list of stop strings.
Source

pub fn seed(self, seed: u64) -> Self

Sets the seed value to use for the random number generator.

§Arguments
  • seed - The seed value to use.

Trait Implementations§

Source§

impl Clone for ChatCompletionRequest

Source§

fn clone(&self) -> ChatCompletionRequest

Returns a copy of the value. Read more
1.0.0 · 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

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

impl<T> ErasedDestructor for T
where T: 'static,