Skip to main content

openai_types/completion/
_gen.rs

1// AUTO-GENERATED by py2rust — do not edit.
2// Re-generate: python3 scripts/py2rust.py sync <python_dir> <rust_dir>
3// Domain: completion
4
5use serde::{Deserialize, Serialize};
6
7/// Represents a completion response from the API.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
10pub struct Completion {
11    /// A unique identifier for the completion.
12    pub id: String,
13    /// The list of completion choices the model generated for the input prompt.
14    pub choices: Vec<CompletionChoice>,
15    /// The Unix timestamp (in seconds) of when the completion was created.
16    pub created: i64,
17    /// The model used for completion.
18    pub model: String,
19    /// The object type, which is always "text_completion"
20    pub object: String,
21    /// This fingerprint represents the backend configuration that the model runs with.
22    #[serde(skip_serializing_if = "Option::is_none", default)]
23    pub system_fingerprint: Option<String>,
24    /// Usage statistics for the completion request.
25    #[serde(skip_serializing_if = "Option::is_none", default)]
26    pub usage: Option<CompletionUsage>,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
31pub struct Logprobs {
32    #[serde(skip_serializing_if = "Option::is_none", default)]
33    pub text_offset: Option<Vec<i64>>,
34    #[serde(skip_serializing_if = "Option::is_none", default)]
35    pub token_logprobs: Option<Vec<f64>>,
36    #[serde(skip_serializing_if = "Option::is_none", default)]
37    pub tokens: Option<Vec<String>>,
38    #[serde(skip_serializing_if = "Option::is_none", default)]
39    pub top_logprobs: Option<Vec<std::collections::HashMap<String, f64>>>,
40}
41
42#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
43#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
44#[non_exhaustive]
45pub enum CompletionChoiceFinishReason {
46    #[serde(rename = "stop")]
47    Stop,
48    #[serde(rename = "length")]
49    Length,
50    #[serde(rename = "content_filter")]
51    ContentFilter,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
56pub struct CompletionChoice {
57    /// The reason the model stopped generating tokens.
58    pub finish_reason: CompletionChoiceFinishReason,
59    pub index: i64,
60    #[serde(skip_serializing_if = "Option::is_none", default)]
61    pub logprobs: Option<Logprobs>,
62    pub text: String,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
66#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
67pub struct CompletionCreateParamsBase {
68    /// ID of the model to use.
69    pub model: Option<String>,
70    /// The prompt(s) to generate completions for, encoded as a string, array of
71    pub prompt: serde_json::Value,
72    /// Generates `best_of` completions server-side and returns the "best" (the one with
73    #[serde(skip_serializing_if = "Option::is_none", default)]
74    pub best_of: Option<i64>,
75    /// Echo back the prompt in addition to the completion
76    #[serde(skip_serializing_if = "Option::is_none", default)]
77    pub echo: Option<bool>,
78    /// Number between -2.0 and 2.0.
79    #[serde(skip_serializing_if = "Option::is_none", default)]
80    pub frequency_penalty: Option<f64>,
81    /// Modify the likelihood of specified tokens appearing in the completion.
82    #[serde(skip_serializing_if = "Option::is_none", default)]
83    pub logit_bias: Option<std::collections::HashMap<String, i64>>,
84    /// Include the log probabilities on the `logprobs` most likely output tokens, as
85    #[serde(skip_serializing_if = "Option::is_none", default)]
86    pub logprobs: Option<i64>,
87    /// The maximum number of [tokens](/tokenizer) that can be generated in the
88    #[serde(skip_serializing_if = "Option::is_none", default)]
89    pub max_tokens: Option<i64>,
90    /// How many completions to generate for each prompt.
91    #[serde(skip_serializing_if = "Option::is_none", default)]
92    pub n: Option<i64>,
93    /// Number between -2.0 and 2.0.
94    #[serde(skip_serializing_if = "Option::is_none", default)]
95    pub presence_penalty: Option<f64>,
96    /// If specified, our system will make a best effort to sample deterministically,
97    #[serde(skip_serializing_if = "Option::is_none", default)]
98    pub seed: Option<i64>,
99    /// Not supported with latest reasoning models `o3` and `o4-mini`.
100    #[serde(skip_serializing_if = "Option::is_none", default)]
101    pub stop: Option<serde_json::Value>,
102    /// Options for streaming response. Only set this when you set `stream: true`.
103    #[serde(skip_serializing_if = "Option::is_none", default)]
104    pub stream_options: Option<serde_json::Value>,
105    /// The suffix that comes after a completion of inserted text.
106    #[serde(skip_serializing_if = "Option::is_none", default)]
107    pub suffix: Option<String>,
108    /// What sampling temperature to use, between 0 and 2.
109    #[serde(skip_serializing_if = "Option::is_none", default)]
110    pub temperature: Option<f64>,
111    /// An alternative to sampling with temperature, called nucleus sampling, where the
112    #[serde(skip_serializing_if = "Option::is_none", default)]
113    pub top_p: Option<f64>,
114    /// A unique identifier representing your end-user, which can help OpenAI to monitor
115    #[serde(skip_serializing_if = "Option::is_none", default)]
116    pub user: Option<String>,
117}
118
119pub type CompletionCreateParams = serde_json::Value;
120
121/// Breakdown of tokens used in a completion.
122#[derive(Debug, Clone, Serialize, Deserialize)]
123#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
124pub struct CompletionTokensDetails {
125    /// When using Predicted Outputs, the number of tokens in the prediction that
126    #[serde(skip_serializing_if = "Option::is_none", default)]
127    pub accepted_prediction_tokens: Option<i64>,
128    /// Audio input tokens generated by the model.
129    #[serde(skip_serializing_if = "Option::is_none", default)]
130    pub audio_tokens: Option<i64>,
131    /// Tokens generated by the model for reasoning.
132    #[serde(skip_serializing_if = "Option::is_none", default)]
133    pub reasoning_tokens: Option<i64>,
134    /// When using Predicted Outputs, the number of tokens in the prediction that did
135    #[serde(skip_serializing_if = "Option::is_none", default)]
136    pub rejected_prediction_tokens: Option<i64>,
137}
138
139/// Breakdown of tokens used in the prompt.
140#[derive(Debug, Clone, Serialize, Deserialize)]
141#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
142pub struct PromptTokensDetails {
143    /// Audio input tokens present in the prompt.
144    #[serde(skip_serializing_if = "Option::is_none", default)]
145    pub audio_tokens: Option<i64>,
146    /// Cached tokens present in the prompt.
147    #[serde(skip_serializing_if = "Option::is_none", default)]
148    pub cached_tokens: Option<i64>,
149}
150
151/// Usage statistics for the completion request.
152#[derive(Debug, Clone, Serialize, Deserialize)]
153#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
154pub struct CompletionUsage {
155    /// Number of tokens in the generated completion.
156    pub completion_tokens: i64,
157    /// Number of tokens in the prompt.
158    pub prompt_tokens: i64,
159    /// Total number of tokens used in the request (prompt + completion).
160    pub total_tokens: i64,
161    /// Breakdown of tokens used in a completion.
162    #[serde(skip_serializing_if = "Option::is_none", default)]
163    pub completion_tokens_details: Option<CompletionTokensDetails>,
164    /// Breakdown of tokens used in the prompt.
165    #[serde(skip_serializing_if = "Option::is_none", default)]
166    pub prompt_tokens_details: Option<PromptTokensDetails>,
167}