Struct ChatCompletionRequestBody

Source
pub struct ChatCompletionRequestBody {
Show 13 fields pub model: String, pub messages: Vec<Message>, pub store: Option<bool>, pub frequency_penalty: Option<f32>, pub logit_bias: Option<FxHashMap<String, i32>>, pub logprobs: Option<bool>, pub top_logprobs: Option<u8>, pub max_completion_tokens: Option<u64>, pub n: Option<u32>, pub modalities: Option<Vec<String>>, pub presence_penalty: Option<f32>, pub temperature: Option<f32>, pub response_format: Option<ChatCompletionResponseFormat>,
}
Expand description

Request body structure for OpenAI Chat Completion API.

This structure contains all the parameters that can be sent to the OpenAI Chat Completion endpoint. Most fields are optional and will be omitted from the JSON if not set.

§Fields

  • model - ID of the model to use (required)
  • messages - List of conversation messages (required)
  • store - Whether to store the output for the user
  • frequency_penalty - Penalty for token frequency (-2.0 to 2.0)
  • logit_bias - Modify likelihood of specified tokens
  • logprobs - Whether to return log probabilities
  • top_logprobs - Number of most likely tokens to return (0-20)
  • max_completion_tokens - Maximum tokens to generate
  • n - Number of completion choices to generate
  • modalities - Output types the model should generate
  • presence_penalty - Penalty for token presence (-2.0 to 2.0)
  • temperature - Sampling temperature (0-2)
  • response_format - Output format specification

§Example

use openai_tools::chat::ChatCompletionRequestBody;
use openai_tools::common::Message;

let mut body = ChatCompletionRequestBody::new("gpt-4o-mini".to_string());
body.messages = vec![Message::from_string("user".to_string(), "Hello!".to_string())];
body.temperature = Some(0.7);

Fields§

§model: String

ID of the model to use. (https://platform.openai.com/docs/models#model-endpoint-compatibility)

§messages: Vec<Message>

A list of messages comprising the conversation so far.

§store: Option<bool>

Whether or not to store the output of this chat completion request for user. false by default.

§frequency_penalty: Option<f32>

-2.0 ~ 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model’s likelihood to repeat the same line verbatim.

§logit_bias: Option<FxHashMap<String, i32>>

Modify the likelihood of specified tokens appearing in the completion. Accepts a JSON object that maps tokens to an associated bias value from 100 to 100.

§logprobs: Option<bool>

Whether to return log probabilities of the output tokens or not.

§top_logprobs: Option<u8>

0 ~ 20. Specify the number of most likely tokens to return at each token position, each with an associated log probability.

§max_completion_tokens: Option<u64>

An upper bound for the number of tokens that can be generated for a completion.

§n: Option<u32>

How many chat completion choices to generate for each input message. 1 by default.

§modalities: Option<Vec<String>>

Output types that you would like the model to generate for this request. [“text”] for most models.

§presence_penalty: Option<f32>

-2.0 ~ 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model’s likelihood to talk about new topics.

§temperature: Option<f32>

0 ~ 2. What sampling temperature to use. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

§response_format: Option<ChatCompletionResponseFormat>

An object specifying the format that the model must output. (https://platform.openai.com/docs/guides/structured-outputs)

Implementations§

Source§

impl ChatCompletionRequestBody

Source

pub fn new(model_id: String) -> Self

Creates a new ChatCompletionRequestBody with the specified model ID.

All other fields are initialized to their default values and can be configured using the builder pattern methods.

§Arguments
  • model_id - The ID of the OpenAI model to use
§Returns

A new ChatCompletionRequestBody instance with the model ID set.

§Example
use openai_tools::chat::ChatCompletionRequestBody;

let body = ChatCompletionRequestBody::new("gpt-4o-mini".to_string());
assert_eq!(body.model, "gpt-4o-mini");
Source

pub fn default() -> Self

Creates a new ChatCompletionRequestBody with all fields set to default values.

This is equivalent to using Default::default() but provides a more explicit way to create an empty request body.

§Returns

A new ChatCompletionRequestBody instance with default values.

Trait Implementations§

Source§

impl Clone for ChatCompletionRequestBody

Source§

fn clone(&self) -> ChatCompletionRequestBody

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChatCompletionRequestBody

Source§

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

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

impl Default for ChatCompletionRequestBody

Source§

fn default() -> ChatCompletionRequestBody

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

impl<'de> Deserialize<'de> for ChatCompletionRequestBody

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 ChatCompletionRequestBody

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> 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> 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<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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