Skip to main content

openai_types/chat/
_gen.rs

1// AUTO-GENERATED by py2rust — do not edit.
2// Re-generate: python3 scripts/py2rust.py sync <python_dir> <rust_dir>
3// Domain: chat
4#![allow(unused_imports)]
5
6use serde::{Deserialize, Serialize};
7use super::*;
8
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
11#[non_exhaustive]
12pub enum ChatCompletionChoiceFinishReason {
13    #[serde(rename = "stop")]
14    Stop,
15    #[serde(rename = "length")]
16    Length,
17    #[serde(rename = "tool_calls")]
18    ToolCalls,
19    #[serde(rename = "content_filter")]
20    ContentFilter,
21    #[serde(rename = "function_call")]
22    FunctionCall,
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
26#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
27#[non_exhaustive]
28pub enum ChatCompletionServiceTier {
29    #[serde(rename = "auto")]
30    Auto,
31    #[serde(rename = "default")]
32    Default,
33    #[serde(rename = "flex")]
34    Flex,
35    #[serde(rename = "scale")]
36    Scale,
37    #[serde(rename = "priority")]
38    Priority,
39}
40
41/// Represents a chat completion response returned by model, based on the provided input.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
44pub struct ChatCompletion {
45    /// A unique identifier for the chat completion.
46    pub id: String,
47    /// A list of chat completion choices.
48    pub choices: Vec<serde_json::Value>,
49    /// The Unix timestamp (in seconds) of when the chat completion was created.
50    pub created: i64,
51    /// The model used for the chat completion.
52    pub model: String,
53    /// The object type, which is always `chat.completion`.
54    pub object: String,
55    /// Specifies the processing type used for serving the request.
56    #[serde(skip_serializing_if = "Option::is_none", default)]
57    pub service_tier: Option<ChatCompletionServiceTier>,
58    /// This fingerprint represents the backend configuration that the model runs with.
59    #[serde(skip_serializing_if = "Option::is_none", default)]
60    pub system_fingerprint: Option<String>,
61    /// Usage statistics for the completion request.
62    #[serde(skip_serializing_if = "Option::is_none", default)]
63    pub usage: Option<serde_json::Value>,
64}
65
66/// If the audio output modality is requested, this object contains data
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
69pub struct ChatCompletionAudio {
70    /// Unique identifier for this audio response.
71    pub id: String,
72    /// Base64 encoded audio bytes generated by the model, in the format specified in
73    pub data: String,
74    /// The Unix timestamp (in seconds) for when this audio response will no longer be
75    pub expires_at: i64,
76    /// Transcript of the audio generated by the model.
77    pub transcript: String,
78}
79
80/// Deprecated and replaced by `tool_calls`.
81#[derive(Debug, Clone, Serialize, Deserialize)]
82#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
83pub struct ChoiceDeltaFunctionCall {
84    /// The arguments to call the function with, as generated by the model in JSON
85    #[serde(skip_serializing_if = "Option::is_none", default)]
86    pub arguments: Option<String>,
87    /// The name of the function to call.
88    #[serde(skip_serializing_if = "Option::is_none", default)]
89    pub name: Option<String>,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
94pub struct ChoiceDeltaToolCallFunction {
95    /// The arguments to call the function with, as generated by the model in JSON
96    #[serde(skip_serializing_if = "Option::is_none", default)]
97    pub arguments: Option<String>,
98    /// The name of the function to call.
99    #[serde(skip_serializing_if = "Option::is_none", default)]
100    pub name: Option<String>,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
105pub struct ChoiceDeltaToolCall {
106    pub index: i64,
107    /// The ID of the tool call.
108    #[serde(skip_serializing_if = "Option::is_none", default)]
109    pub id: Option<String>,
110    #[serde(skip_serializing_if = "Option::is_none", default)]
111    pub function: Option<ChoiceDeltaToolCallFunction>,
112    /// The type of the tool. Currently, only `function` is supported.
113    #[serde(rename = "type", skip_serializing_if = "Option::is_none", default)]
114    pub type_: Option<String>,
115}
116
117#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
118#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
119#[non_exhaustive]
120pub enum ChoiceDeltaRole {
121    #[serde(rename = "developer")]
122    Developer,
123    #[serde(rename = "system")]
124    System,
125    #[serde(rename = "user")]
126    User,
127    #[serde(rename = "assistant")]
128    Assistant,
129    #[serde(rename = "tool")]
130    Tool,
131}
132
133#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
134#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
135#[non_exhaustive]
136pub enum ChunkChoiceFinishReason {
137    #[serde(rename = "stop")]
138    Stop,
139    #[serde(rename = "length")]
140    Length,
141    #[serde(rename = "tool_calls")]
142    ToolCalls,
143    #[serde(rename = "content_filter")]
144    ContentFilter,
145    #[serde(rename = "function_call")]
146    FunctionCall,
147}
148
149#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
150#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
151#[non_exhaustive]
152pub enum ChatCompletionChunkServiceTier {
153    #[serde(rename = "auto")]
154    Auto,
155    #[serde(rename = "default")]
156    Default,
157    #[serde(rename = "flex")]
158    Flex,
159    #[serde(rename = "scale")]
160    Scale,
161    #[serde(rename = "priority")]
162    Priority,
163}
164
165#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
166#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
167#[non_exhaustive]
168pub enum ImageURLDetail {
169    #[serde(rename = "auto")]
170    Auto,
171    #[serde(rename = "low")]
172    Low,
173    #[serde(rename = "high")]
174    High,
175}
176
177#[derive(Debug, Clone, Serialize, Deserialize)]
178#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
179pub struct ImageURL {
180    /// Either a URL of the image or the base64 encoded image data.
181    pub url: String,
182    /// Specifies the detail level of the image.
183    #[serde(skip_serializing_if = "Option::is_none", default)]
184    pub detail: Option<ImageURLDetail>,
185}
186
187/// Learn about [image inputs](https://platform.openai.com/docs/guides/vision).
188#[derive(Debug, Clone, Serialize, Deserialize)]
189#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
190pub struct ChatCompletionContentPartImage {
191    pub image_url: ImageURL,
192    /// The type of the content part.
193    #[serde(rename = "type")]
194    pub type_: String,
195}
196
197/// Learn about [text inputs](https://platform.openai.com/docs/guides/text-generation).
198#[derive(Debug, Clone, Serialize, Deserialize)]
199#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
200pub struct ChatCompletionContentPartText {
201    /// The text content.
202    pub text: String,
203    /// The type of the content part.
204    #[serde(rename = "type")]
205    pub type_: String,
206}
207
208#[derive(Debug, Clone, Serialize, Deserialize)]
209#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
210pub struct ChatCompletionDeleted {
211    /// The ID of the chat completion that was deleted.
212    pub id: String,
213    /// Whether the chat completion was deleted.
214    pub deleted: bool,
215    /// The type of object being deleted.
216    pub object: String,
217}
218
219/// A function tool that can be used to generate a response.
220#[derive(Debug, Clone, Serialize, Deserialize)]
221#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
222pub struct ChatCompletionFunctionTool {
223    pub function: serde_json::Value,
224    /// The type of the tool. Currently, only `function` is supported.
225    #[serde(rename = "type")]
226    pub type_: String,
227}
228
229/// A URL citation when using web search.
230#[derive(Debug, Clone, Serialize, Deserialize)]
231#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
232pub struct AnnotationURLCitation {
233    /// The index of the last character of the URL citation in the message.
234    pub end_index: i64,
235    /// The index of the first character of the URL citation in the message.
236    pub start_index: i64,
237    /// The title of the web resource.
238    pub title: String,
239    /// The URL of the web resource.
240    pub url: String,
241}
242
243/// The custom tool that the model called.
244#[derive(Debug, Clone, Serialize, Deserialize)]
245#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
246pub struct Custom {
247    /// The input for the custom tool call generated by the model.
248    pub input: String,
249    /// The name of the custom tool to call.
250    pub name: String,
251}
252
253/// A call to a custom tool created by the model.
254#[derive(Debug, Clone, Serialize, Deserialize)]
255#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
256pub struct ChatCompletionMessageCustomToolCall {
257    /// The ID of the tool call.
258    pub id: String,
259    /// The custom tool that the model called.
260    pub custom: Custom,
261    /// The type of the tool. Always `custom`.
262    #[serde(rename = "type")]
263    pub type_: String,
264}
265
266/// The function that the model called.
267#[derive(Debug, Clone, Serialize, Deserialize)]
268#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
269pub struct MessageFunctionFunction {
270    /// The arguments to call the function with, as generated by the model in JSON
271    pub arguments: String,
272    /// The name of the function to call.
273    pub name: String,
274}
275
276/// A call to a function tool created by the model.
277#[derive(Debug, Clone, Serialize, Deserialize)]
278#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
279pub struct ChatCompletionMessageFunctionToolCall {
280    /// The ID of the tool call.
281    pub id: String,
282    /// The function that the model called.
283    pub function: serde_json::Value,
284    /// The type of the tool. Currently, only `function` is supported.
285    #[serde(rename = "type")]
286    pub type_: String,
287}
288
289pub type ChatCompletionMessageToolCallUnion = serde_json::Value;
290
291pub type ChatCompletionMessageToolCall = ChatCompletionMessageFunctionToolCall;
292
293#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
294#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
295#[non_exhaustive]
296pub enum ChatCompletionModality {
297    #[serde(rename = "text")]
298    Text,
299    #[serde(rename = "audio")]
300    Audio,
301}
302
303#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
304#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
305#[non_exhaustive]
306pub enum ChatCompletionRole {
307    #[serde(rename = "developer")]
308    Developer,
309    #[serde(rename = "system")]
310    System,
311    #[serde(rename = "user")]
312    User,
313    #[serde(rename = "assistant")]
314    Assistant,
315    #[serde(rename = "tool")]
316    Tool,
317    #[serde(rename = "function")]
318    Function,
319}
320
321pub type ChatCompletionStoreMessageContentPart = serde_json::Value;
322
323#[derive(Debug, Clone, Serialize, Deserialize)]
324#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
325pub struct ChatCompletionTokenLogprob {
326    /// The token.
327    pub token: String,
328    /// A list of integers representing the UTF-8 bytes representation of the token.
329    #[serde(skip_serializing_if = "Option::is_none", default)]
330    pub bytes: Option<Vec<i64>>,
331    /// The log probability of this token, if it is within the top 20 most likely
332    pub logprob: f64,
333    /// List of the most likely tokens and their log probability, at this token
334    pub top_logprobs: Vec<TopLogprob>,
335}
336
337#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
338#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
339#[non_exhaustive]
340pub enum CompletionCreateParamsBasePromptCacheRetention {
341    #[serde(rename = "in-memory")]
342    InMemory,
343    #[serde(rename = "24h")]
344    V24h,
345}
346
347#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
348#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
349#[non_exhaustive]
350pub enum CompletionCreateParamsBaseServiceTier {
351    #[serde(rename = "auto")]
352    Auto,
353    #[serde(rename = "default")]
354    Default,
355    #[serde(rename = "flex")]
356    Flex,
357    #[serde(rename = "scale")]
358    Scale,
359    #[serde(rename = "priority")]
360    Priority,
361}
362
363#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
364#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
365#[non_exhaustive]
366pub enum CompletionCreateParamsBaseVerbosity {
367    #[serde(rename = "low")]
368    Low,
369    #[serde(rename = "medium")]
370    Medium,
371    #[serde(rename = "high")]
372    High,
373}
374
375#[derive(Debug, Clone, Serialize, Deserialize)]
376#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
377pub struct CompletionCreateParamsBase {
378    /// A list of messages comprising the conversation so far.
379    pub messages: Vec<serde_json::Value>,
380    /// Model ID used to generate the response, like `gpt-4o` or `o3`.
381    pub model: String,
382    /// Parameters for audio output.
383    #[serde(skip_serializing_if = "Option::is_none", default)]
384    pub audio: Option<serde_json::Value>,
385    /// Number between -2.0 and 2.0.
386    #[serde(skip_serializing_if = "Option::is_none", default)]
387    pub frequency_penalty: Option<f64>,
388    /// Deprecated in favor of `tool_choice`.
389    #[serde(skip_serializing_if = "Option::is_none", default)]
390    pub function_call: Option<FunctionCall>,
391    /// Deprecated in favor of `tools`.
392    #[serde(skip_serializing_if = "Option::is_none", default)]
393    pub functions: Option<Vec<serde_json::Value>>,
394    /// Modify the likelihood of specified tokens appearing in the completion.
395    #[serde(skip_serializing_if = "Option::is_none", default)]
396    pub logit_bias: Option<std::collections::HashMap<String, i64>>,
397    /// Whether to return log probabilities of the output tokens or not.
398    #[serde(skip_serializing_if = "Option::is_none", default)]
399    pub logprobs: Option<bool>,
400    /// An upper bound for the number of tokens that can be generated for a completion,
401    #[serde(skip_serializing_if = "Option::is_none", default)]
402    pub max_completion_tokens: Option<i64>,
403    /// The maximum number of [tokens](/tokenizer) that can be generated in the chat
404    #[serde(skip_serializing_if = "Option::is_none", default)]
405    pub max_tokens: Option<i64>,
406    /// Set of 16 key-value pairs that can be attached to an object.
407    #[serde(skip_serializing_if = "Option::is_none", default)]
408    pub metadata: Option<serde_json::Value>,
409    /// Output types that you would like the model to generate. Most models are capable
410    #[serde(skip_serializing_if = "Option::is_none", default)]
411    pub modalities: Option<Vec<serde_json::Value>>,
412    /// How many chat completion choices to generate for each input message.
413    #[serde(skip_serializing_if = "Option::is_none", default)]
414    pub n: Option<i64>,
415    /// Whether to enable
416    #[serde(skip_serializing_if = "Option::is_none", default)]
417    pub parallel_tool_calls: Option<bool>,
418    /// Static predicted output content, such as the content of a text file that is
419    #[serde(skip_serializing_if = "Option::is_none", default)]
420    pub prediction: Option<serde_json::Value>,
421    /// Number between -2.0 and 2.0.
422    #[serde(skip_serializing_if = "Option::is_none", default)]
423    pub presence_penalty: Option<f64>,
424    /// Used by OpenAI to cache responses for similar requests to optimize your cache
425    #[serde(skip_serializing_if = "Option::is_none", default)]
426    pub prompt_cache_key: Option<String>,
427    /// The retention policy for the prompt cache.
428    #[serde(skip_serializing_if = "Option::is_none", default)]
429    pub prompt_cache_retention: Option<CompletionCreateParamsBasePromptCacheRetention>,
430    /// Constrains effort on reasoning for
431    #[serde(skip_serializing_if = "Option::is_none", default)]
432    pub reasoning_effort: Option<serde_json::Value>,
433    /// An object specifying the format that the model must output.
434    #[serde(skip_serializing_if = "Option::is_none", default)]
435    pub response_format: Option<ResponseFormat>,
436    /// A stable identifier used to help detect users of your application that may be
437    #[serde(skip_serializing_if = "Option::is_none", default)]
438    pub safety_identifier: Option<String>,
439    /// This feature is in Beta. If specified, our system will make a best effort to
440    #[serde(skip_serializing_if = "Option::is_none", default)]
441    pub seed: Option<i64>,
442    /// Specifies the processing type used for serving the request.
443    #[serde(skip_serializing_if = "Option::is_none", default)]
444    pub service_tier: Option<CompletionCreateParamsBaseServiceTier>,
445    /// Not supported with latest reasoning models `o3` and `o4-mini`.
446    #[serde(skip_serializing_if = "Option::is_none", default)]
447    pub stop: Option<serde_json::Value>,
448    /// Whether or not to store the output of this chat completion request for use in
449    #[serde(skip_serializing_if = "Option::is_none", default)]
450    pub store: Option<bool>,
451    /// Options for streaming response. Only set this when you set `stream: true`.
452    #[serde(skip_serializing_if = "Option::is_none", default)]
453    pub stream_options: Option<serde_json::Value>,
454    /// What sampling temperature to use, between 0 and 2.
455    #[serde(skip_serializing_if = "Option::is_none", default)]
456    pub temperature: Option<f64>,
457    /// Controls which (if any) tool is called by the model. `none` means the model will
458    #[serde(skip_serializing_if = "Option::is_none", default)]
459    pub tool_choice: Option<serde_json::Value>,
460    /// A list of tools the model may call.
461    #[serde(skip_serializing_if = "Option::is_none", default)]
462    pub tools: Option<Vec<serde_json::Value>>,
463    /// An integer between 0 and 20 specifying the number of most likely tokens to
464    #[serde(skip_serializing_if = "Option::is_none", default)]
465    pub top_logprobs: Option<i64>,
466    /// An alternative to sampling with temperature, called nucleus sampling, where the
467    #[serde(skip_serializing_if = "Option::is_none", default)]
468    pub top_p: Option<f64>,
469    /// This field is being replaced by `safety_identifier` and `prompt_cache_key`.
470    #[serde(skip_serializing_if = "Option::is_none", default)]
471    pub user: Option<String>,
472    /// Constrains the verbosity of the model's response.
473    #[serde(skip_serializing_if = "Option::is_none", default)]
474    pub verbosity: Option<CompletionCreateParamsBaseVerbosity>,
475    /// This tool searches the web for relevant results to use in a response. Learn more
476    #[serde(skip_serializing_if = "Option::is_none", default)]
477    pub web_search_options: Option<WebSearchOptions>,
478}
479
480#[derive(Debug, Clone, Serialize, Deserialize)]
481#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
482pub struct CompletionCreateFunction {
483    /// The name of the function to be called.
484    pub name: String,
485    /// A description of what the function does, used by the model to choose when and
486    #[serde(skip_serializing_if = "Option::is_none", default)]
487    pub description: Option<String>,
488    /// The parameters the functions accepts, described as a JSON Schema object.
489    #[serde(skip_serializing_if = "Option::is_none", default)]
490    pub parameters: Option<serde_json::Value>,
491}
492
493/// Approximate location parameters for the search.
494#[derive(Debug, Clone, Serialize, Deserialize)]
495#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
496pub struct WebSearchOptionsUserLocationApproximate {
497    /// Free text input for the city of the user, e.g. `San Francisco`.
498    #[serde(skip_serializing_if = "Option::is_none", default)]
499    pub city: Option<String>,
500    /// The two-letter [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1) of
501    #[serde(skip_serializing_if = "Option::is_none", default)]
502    pub country: Option<String>,
503    /// Free text input for the region of the user, e.g. `California`.
504    #[serde(skip_serializing_if = "Option::is_none", default)]
505    pub region: Option<String>,
506    /// The [IANA timezone](https://timeapi.io/documentation/iana-timezones) of the
507    #[serde(skip_serializing_if = "Option::is_none", default)]
508    pub timezone: Option<String>,
509}
510
511/// Approximate location parameters for the search.
512#[derive(Debug, Clone, Serialize, Deserialize)]
513#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
514pub struct WebSearchOptionsUserLocation {
515    /// Approximate location parameters for the search.
516    pub approximate: WebSearchOptionsUserLocationApproximate,
517    /// The type of location approximation. Always `approximate`.
518    #[serde(rename = "type")]
519    pub type_: String,
520}
521
522#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
523#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
524#[non_exhaustive]
525pub enum WebSearchOptionsSearchContextSize {
526    #[serde(rename = "low")]
527    Low,
528    #[serde(rename = "medium")]
529    Medium,
530    #[serde(rename = "high")]
531    High,
532}
533
534pub type CompletionCreateParams = serde_json::Value;
535
536#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
537#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
538#[non_exhaustive]
539pub enum CompletionListParamsOrder {
540    #[serde(rename = "asc")]
541    Asc,
542    #[serde(rename = "desc")]
543    Desc,
544}
545
546#[derive(Debug, Clone, Serialize, Deserialize)]
547#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
548pub struct CompletionListParams {
549    /// Identifier for the last chat completion from the previous pagination request.
550    #[serde(skip_serializing_if = "Option::is_none", default)]
551    pub after: Option<String>,
552    /// Number of Chat Completions to retrieve.
553    #[serde(skip_serializing_if = "Option::is_none", default)]
554    pub limit: Option<i64>,
555    /// A list of metadata keys to filter the Chat Completions by. Example:
556    #[serde(skip_serializing_if = "Option::is_none", default)]
557    pub metadata: Option<serde_json::Value>,
558    /// The model used to generate the Chat Completions.
559    #[serde(skip_serializing_if = "Option::is_none", default)]
560    pub model: Option<String>,
561    /// Sort order for Chat Completions by timestamp.
562    #[serde(skip_serializing_if = "Option::is_none", default)]
563    pub order: Option<CompletionListParamsOrder>,
564}
565
566#[derive(Debug, Clone, Serialize, Deserialize)]
567#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
568pub struct CompletionUpdateParams {
569    /// Set of 16 key-value pairs that can be attached to an object.
570    pub metadata: Option<serde_json::Value>,
571}