CreateChatCompletionRequestArgs

Struct CreateChatCompletionRequestArgs 

Source
pub struct CreateChatCompletionRequestArgs { /* private fields */ }
Expand description

Implementations§

Source§

impl CreateChatCompletionRequestArgs

Source

pub fn messages<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs

A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, images, and audio.

Source

pub fn model<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<String>,

ID of the model to use. See the model endpoint compatibility table for details on which models work with the Chat API.

Source

pub fn store<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<bool>,

Whether or not to store the output of this chat completion request

for use in our model distillation or evals products.

Source

pub fn reasoning_effort<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<ReasoningEffort>,

o1 models only

Constrains effort on reasoning for reasoning models.

Currently supported values are low, medium, and high. Reducing

reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.

Source

pub fn metadata<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<Value>,

Developer-defined tags and values used for filtering completions in the dashboard.

Source

pub fn frequency_penalty<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<f32>,

Number between -2.0 and 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.

Source

pub fn logit_bias<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<HashMap<String, Value>>,

Modify the likelihood of specified tokens appearing in the completion.

Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.

Source

pub fn logprobs<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<bool>,

Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the content of message.

Source

pub fn top_logprobs<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<u8>,

An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used.

Source

pub fn max_tokens<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<u32>,

The maximum number of tokens that can be generated in the chat completion.

This value can be used to control costs for text generated via API. This value is now deprecated in favor of max_completion_tokens, and is not compatible with o1 series models.

Source

pub fn max_completion_tokens<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<u32>,

An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.

Source

pub fn n<VALUE>(&mut self, value: VALUE) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<u8>,

How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep n as 1 to minimize costs.

Source

pub fn modalities<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs

Source

pub fn prediction<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<PredictionContent>,

Configuration for a Predicted Output,which can greatly improve response times when large parts of the model response are known ahead of time. This is most common when you are regenerating a file with only minor changes to most of the content.

Source

pub fn audio<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<ChatCompletionAudio>,

Parameters for audio output. Required when audio output is requested with modalities: ["audio"]. Learn more.

Source

pub fn presence_penalty<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<f32>,

Number between -2.0 and 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.

Source

pub fn response_format<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<ResponseFormat>,

An object specifying the format that the model must output. Compatible with GPT-4o, GPT-4o mini, GPT-4 Turbo and all GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106.

Setting to { "type": "json_schema", "json_schema": {...} } enables Structured Outputs which guarantees the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.

Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON.

Important: when using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly “stuck” request. Also note that the message content may be partially cut off if finish_reason="length", which indicates the generation exceeded max_tokens or the conversation exceeded the max context length.

Source

pub fn seed<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<i64>,

This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed, and you should refer to the system_fingerprint response parameter to monitor changes in the backend.

Source

pub fn service_tier<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<ServiceTier>,

Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service:

  • If set to ‘auto’, the system will utilize scale tier credits until they are exhausted.
  • If set to ‘default’, the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee.
  • When not set, the default behavior is ‘auto’.

When this parameter is set, the response body will include the service_tier utilized.

Source

pub fn stop<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<Stop>,

Up to 4 sequences where the API will stop generating further tokens.

Source

pub fn stream<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<bool>,

If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Example Python code.

Source

pub fn stream_options<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs

Source

pub fn temperature<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<f32>,

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

We generally recommend altering this or top_p but not both.

Source

pub fn top_p<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<f32>,

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.

We generally recommend altering this or temperature but not both.

Source

pub fn tools<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<Vec<ChatCompletionTool>>,

A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.

Source

pub fn tool_choice<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs

Source

pub fn parallel_tool_calls<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<bool>,

Whether to enable parallel function calling during tool use.

Source

pub fn user<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<String>,

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

Source

pub fn web_search_options<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs
where VALUE: Into<WebSearchOptions>,

This tool searches the web for relevant results to use in a response. Learn more about the web search tool.

Source

pub fn function_call<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs

Deprecated in favor of tool_choice.

Controls which (if any) function is called by the model. none means the model will not call a function and instead generates a message. auto means the model can pick between generating a message or calling a function. Specifying a particular function via {"name": "my_function"} forces the model to call that function.

none is the default when no functions are present. auto is the default if functions are present.

Source

pub fn functions<VALUE>( &mut self, value: VALUE, ) -> &mut CreateChatCompletionRequestArgs

Deprecated in favor of tools.

A list of functions the model may generate JSON inputs for.

Source

pub fn build(&self) -> Result<CreateChatCompletionRequest, OpenAIError>

Builds a new CreateChatCompletionRequest.

§Errors

If a required field has not been initialized.

Trait Implementations§

Source§

impl Clone for CreateChatCompletionRequestArgs

Source§

fn clone(&self) -> CreateChatCompletionRequestArgs

Returns a duplicate 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 CreateChatCompletionRequestArgs

Source§

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

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

impl Default for CreateChatCompletionRequestArgs

Source§

fn default() -> CreateChatCompletionRequestArgs

Returns the “default value” for a type. 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<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
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<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<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
Source§

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