openai_types/responses/
create.rs1use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7use super::common::ReasoningEffort;
8use super::input::ResponseInput;
9use super::tools::{ResponseTool, ResponseToolChoice};
10
11pub use super::common::ReasoningSummary;
13
14#[derive(Debug, Clone, Default, Serialize, Deserialize)]
16#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
17pub struct Reasoning {
18 #[serde(default)]
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub effort: Option<ReasoningEffort>,
22 #[serde(default)]
24 #[serde(skip_serializing_if = "Option::is_none")]
25 pub summary: Option<ReasoningSummary>,
26}
27
28impl Reasoning {
29 pub fn effort(&mut self, effort: ReasoningEffort) -> &mut Self {
31 self.effort = Some(effort);
32 self
33 }
34 pub fn summary(&mut self, summary: ReasoningSummary) -> &mut Self {
36 self.summary = Some(summary);
37 self
38 }
39 pub fn build(&self) -> Result<Self, String> {
41 Ok(self.clone())
42 }
43}
44
45pub type ReasoningArgs = Reasoning;
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
51pub struct ResponseTextConfig {
52 #[serde(default)]
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub format: Option<ResponseTextFormat>,
56 #[serde(default)]
58 #[serde(skip_serializing_if = "Option::is_none")]
59 pub verbosity: Option<String>,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize)]
64#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
65#[serde(tag = "type")]
66#[non_exhaustive]
67pub enum ResponseTextFormat {
68 #[serde(rename = "text")]
70 Text,
71 #[serde(rename = "json_object")]
73 JsonObject,
74 #[serde(rename = "json_schema")]
76 JsonSchema {
77 name: String,
79 #[serde(default)]
81 #[serde(skip_serializing_if = "Option::is_none")]
82 description: Option<String>,
83 #[serde(default)]
85 #[serde(skip_serializing_if = "Option::is_none")]
86 schema: Option<serde_json::Value>,
87 #[serde(default)]
89 #[serde(skip_serializing_if = "Option::is_none")]
90 strict: Option<bool>,
91 },
92}
93
94#[derive(Debug, Clone, Default, Serialize)]
96#[cfg_attr(feature = "structured", derive(schemars::JsonSchema))]
97pub struct ResponseCreateRequest {
98 #[serde(default)]
100 pub model: String,
101
102 #[serde(skip_serializing_if = "Option::is_none")]
104 pub input: Option<ResponseInput>,
105
106 #[serde(skip_serializing_if = "Option::is_none")]
108 pub instructions: Option<String>,
109
110 #[serde(skip_serializing_if = "Option::is_none")]
112 pub tools: Option<Vec<ResponseTool>>,
113
114 #[serde(skip_serializing_if = "Option::is_none")]
116 pub tool_choice: Option<ResponseToolChoice>,
117
118 #[serde(skip_serializing_if = "Option::is_none")]
120 pub parallel_tool_calls: Option<bool>,
121
122 #[serde(skip_serializing_if = "Option::is_none")]
124 pub previous_response_id: Option<String>,
125
126 #[serde(skip_serializing_if = "Option::is_none")]
128 pub temperature: Option<f64>,
129
130 #[serde(skip_serializing_if = "Option::is_none")]
132 pub top_p: Option<f64>,
133
134 #[serde(skip_serializing_if = "Option::is_none")]
136 pub max_output_tokens: Option<i64>,
137
138 #[serde(skip_serializing_if = "Option::is_none")]
140 pub truncation: Option<String>,
141
142 #[serde(skip_serializing_if = "Option::is_none")]
144 pub reasoning: Option<Reasoning>,
145
146 #[serde(skip_serializing_if = "Option::is_none")]
148 pub store: Option<bool>,
149
150 #[serde(skip_serializing_if = "Option::is_none")]
152 pub metadata: Option<HashMap<String, String>>,
153
154 #[serde(skip_serializing_if = "Option::is_none")]
156 pub include: Option<Vec<String>>,
157
158 #[serde(skip_serializing_if = "Option::is_none")]
160 pub stream: Option<bool>,
161
162 #[serde(skip_serializing_if = "Option::is_none")]
164 pub service_tier: Option<String>,
165
166 #[serde(skip_serializing_if = "Option::is_none")]
168 pub user: Option<String>,
169
170 #[serde(skip_serializing_if = "Option::is_none")]
172 pub text: Option<ResponseTextConfig>,
173
174 #[serde(skip_serializing_if = "Option::is_none")]
176 pub prompt_cache_key: Option<String>,
177
178 #[serde(skip_serializing_if = "Option::is_none")]
180 pub prompt_cache_retention: Option<String>,
181
182 #[serde(skip_serializing_if = "Option::is_none")]
184 pub background: Option<bool>,
185}
186
187impl ResponseCreateRequest {
188 pub fn new(model: impl Into<String>) -> Self {
190 Self {
191 model: model.into(),
192 ..Default::default()
193 }
194 }
195
196 pub fn input(mut self, input: impl Into<ResponseInput>) -> Self {
198 self.input = Some(input.into());
199 self
200 }
201
202 pub fn instructions(mut self, instructions: impl Into<String>) -> Self {
204 self.instructions = Some(instructions.into());
205 self
206 }
207
208 pub fn tools(mut self, tools: Vec<ResponseTool>) -> Self {
210 self.tools = Some(tools);
211 self
212 }
213
214 pub fn tool_choice(mut self, choice: ResponseToolChoice) -> Self {
216 self.tool_choice = Some(choice);
217 self
218 }
219
220 pub fn previous_response_id(mut self, id: impl Into<String>) -> Self {
222 self.previous_response_id = Some(id.into());
223 self
224 }
225
226 pub fn temperature(mut self, temperature: f64) -> Self {
228 self.temperature = Some(temperature);
229 self
230 }
231
232 pub fn max_output_tokens(mut self, max: i64) -> Self {
234 self.max_output_tokens = Some(max);
235 self
236 }
237
238 pub fn reasoning(mut self, reasoning: Reasoning) -> Self {
240 self.reasoning = Some(reasoning);
241 self
242 }
243
244 pub fn truncation(mut self, truncation: impl Into<String>) -> Self {
246 self.truncation = Some(truncation.into());
247 self
248 }
249
250 pub fn store(mut self, store: bool) -> Self {
252 self.store = Some(store);
253 self
254 }
255
256 pub fn model(mut self, model: impl Into<String>) -> Self {
258 self.model = model.into();
259 self
260 }
261
262 pub fn text(mut self, text: ResponseTextConfig) -> Self {
264 self.text = Some(text);
265 self
266 }
267
268 pub fn top_p(mut self, top_p: f64) -> Self {
270 self.top_p = Some(top_p);
271 self
272 }
273
274 pub fn parallel_tool_calls(mut self, parallel: bool) -> Self {
276 self.parallel_tool_calls = Some(parallel);
277 self
278 }
279
280 pub fn metadata(mut self, metadata: HashMap<String, String>) -> Self {
282 self.metadata = Some(metadata);
283 self
284 }
285
286 pub fn include(mut self, include: Vec<String>) -> Self {
288 self.include = Some(include);
289 self
290 }
291
292 pub fn service_tier(mut self, tier: impl Into<String>) -> Self {
294 self.service_tier = Some(tier.into());
295 self
296 }
297
298 pub fn user(mut self, user: impl Into<String>) -> Self {
300 self.user = Some(user.into());
301 self
302 }
303
304 pub fn prompt_cache_key(mut self, key: impl Into<String>) -> Self {
306 self.prompt_cache_key = Some(key.into());
307 self
308 }
309
310 pub fn prompt_cache_retention(mut self, retention: impl Into<String>) -> Self {
312 self.prompt_cache_retention = Some(retention.into());
313 self
314 }
315
316 pub fn background(mut self, background: bool) -> Self {
318 self.background = Some(background);
319 self
320 }
321}
322
323pub type CreateResponse = ResponseCreateRequest;
328pub type CreateResponseArgs = ResponseCreateRequest;