openai_responses 0.1.0

Rust SDK for the OpenAI Responses API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
use super::{APIInputMessage, Role};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Content items generated by the model.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OutputItem {
    /// An output message from the model.
    Message(OutputMessage),
    /// The results of a file search tool call. See the [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
    #[serde(rename = "file_search_call")]
    FileSearch(FileSearchCall),
    /// A tool call to run a function. See the [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
    FunctionCall(FunctionCall),
    /// The results of a web search tool call. See the [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for more information.
    #[serde(rename = "web_search_call")]
    WebSearchResults(WebSearchCall),
    /// A tool call to a computer use tool. See the [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
    #[serde(rename = "computer_call")]
    ComputerToolCall(ComputerToolCall),
    /// A description of the chain of thought used by a reasoning model while generating a response.
    Reasoning(Reasoning),
}

/// An item representing part of the context for the response to be generated by the model.
///
/// Can contain text, images, and audio inputs, as well as previous assistant responses and tool call outputs.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum InputItem {
    /// A message input to the model with a role indicating instruction following hierarchy.
    ///
    /// Instructions given with the `Developer` or `System` role take precedence over instructions given with the `User` role.
    #[serde(rename = "message")]
    InputMessage(APIInputMessage),
    /// An output message from the model.
    #[serde(rename = "message")]
    OutputMessage(OutputMessage),
    /// The results of a file search tool call.
    ///
    /// See the [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
    #[serde(rename = "file_search_call")]
    FileSearch(FileSearchCall),
    /// A tool call to a computer use tool.
    ///
    /// See the [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
    #[serde(rename = "computer_call")]
    ComputerToolCall(ComputerToolCall),
    /// The output of a computer tool call.
    #[serde(rename = "computer_call_output")]
    ComputerToolCallOutput(ComputerToolCallOutput),
    /// The results of a web search tool call.
    ///
    /// See the [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for more information.
    #[serde(rename = "web_search_call")]
    WebSearchResults(WebSearchCall),
    /// A tool call to run a function.
    ///
    /// See the [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
    FunctionCall(FunctionCall),
    /// The output of a function tool call.
    FunctionCallOutput(FunctionCallOutput),
    /// A description of the chain of thought used by a reasoning model while generating a response.
    Reasoning(Reasoning),
}

/// An output message from the model.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OutputMessage {
    /// The content of the output message.
    pub content: Vec<OutputContent>,
    /// The unique ID of the output message.
    pub id: String,
    /// The role of the output message. Always `Assistant`.
    pub role: Role,
    /// The status of the message input.
    pub status: MessageStatus,
}

/// The content of the output message.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OutputContent {
    /// A text output from the model.
    #[serde(rename = "output_text")]
    Text {
        /// The text output from the model.
        text: String,
        /// The annotations of the text output.
        annotations: Vec<Annotation>,
    },
    /// A refusal from the model.
    Refusal {
        /// The refusal explanation from the model.
        refusal: String,
    },
}

/// An annotation of the text output.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Annotation {
    /// A citation to a file.
    FileCitation {
        /// The ID of the file.
        file_id: String,
        /// The index of the file in the list of files.
        index: u64,
    },
    #[serde(rename = "url_citation")]
    /// A citation for a web resource used to generate a model response.
    URLCitation {
        /// The index of the last character of the URL citation in the message.
        end_index: u64,
        /// The index of the first character of the URL citation in the message.
        start_index: u64,
        /// The title of the web resource.
        title: String,
        /// The URL of the web resource.
        url: String,
    },
    /// A path to a file.
    FilePath {
        /// The ID of the file.
        file_id: String,
        /// The index of the file in the list of files.
        index: u64,
    },
}

/// The status of a message.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MessageStatus {
    InProgress,
    Completed,
    Incomplete,
}

/// The results of a file search tool call.
///
/// See the [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileSearchCall {
    /// The unique ID of the file search tool call.
    pub id: String,
    /// The queries used to search for files.
    pub queries: Vec<String>,
    /// The status of the file search tool call.
    pub status: FileSearchStatus,
    /// The results of the file search tool call.
    pub results: Option<Vec<FileSearchResult>>,
}

/// A result of the file search tool call.
///
/// See the [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileSearchResult {
    /// Set of 16 key-value pairs that can be attached to an object.
    ///
    /// This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.
    /// Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters, booleans, or numbers.
    pub attributes: HashMap<String, String>,
    /// The unique ID of the file.
    pub file_id: String,
    /// The name of the file.
    pub filename: String,
    /// The relevance score of the file - a value between 0 and 1.
    pub score: f32,
    /// The text that was retrieved from the file.
    pub text: String,
}

/// The status of the file search tool call.
///
/// See the [file search guide](https://platform.openai.com/docs/guides/tools-file-search) for more information.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FileSearchStatus {
    Completed,
    InProgress,
    Searching,
    Incomplete,
    Failed,
}

/// A tool call to run a function.
///
/// See the [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCall {
    /// A JSON string of the arguments to pass to the function.
    pub arguments: String,
    /// The unique ID of the function tool call generated by the model.
    pub call_id: String,
    /// The unique ID of the function tool call.
    pub id: String,
    /// The name of the function to run.
    pub name: String,
    /// The status of the item.
    pub status: FunctionCallStatus,
}

/// The status of the function call.
///
/// See the [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum FunctionCallStatus {
    InProgress,
    Completed,
    Incomplete,
}

/// The output of a function call.
///
/// See the [function calling guide](https://platform.openai.com/docs/guides/function-calling) for more information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCallOutput {
    /// The unique ID of the function tool call output. Populated when this item is returned via API.
    pub id: Option<String>,
    /// The status of the item. Populated when items are returned via API.
    pub status: Option<FunctionCallStatus>,
    /// The ID of the computer tool call that produced the output.
    pub call_id: String,
    /// A JSON string of the output of the function tool call.
    pub output: String,
}

/// A tool call to run a web search.
///
/// See the [web search guide](https://platform.openai.com/docs/guides/tools-web-search) for more information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WebSearchCall {
    /// The unique ID of the web search tool call.
    pub id: String,
    /// The status of the web search tool call.
    pub status: String,
}

/// A tool call to run a computer action.
///
/// See the [computer action guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComputerToolCall {
    /// The action to execute.
    pub action: ComputerAction,
    /// The unique ID of the computer call.
    pub call_id: String,
    /// The pending safety checks for the computer call.
    pub pending_safety_checks: Vec<SafetyCheck>,
    /// The status of the item.
    pub status: ComputerCallStatus,
}

/// The action of the computer call.
///
/// See the [computer action guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ComputerAction {
    /// A click action.
    Click {
        /// Indicates which mouse button was pressed during the click.
        button: ClickButton,
        /// The x-coordinate where the click occurred.
        x: u64,
        /// The y-coordinate where the click occurred.
        y: u64,
    },
    /// A double click action.
    DoubleClick {
        /// The x-coordinate where the double click occurred.
        x: u64,
        /// The y-coordinate where the double click occurred.
        y: u64,
    },
    /// A drag action.
    Drag {
        /// An array of coordinates representing the path of the drag action.
        path: Vec<DragCoordinate>,
    },
    #[serde(rename = "keypress")]
    KeyPress {
        /// The combination of keys the model is requesting to be pressed.
        keys: Vec<String>,
    },
    /// A mouse move action.
    Move {
        /// The x-coordinate to move to.
        x: u64,
        /// The y-coordinate to move to.
        y: u64,
    },
    /// A screenshot action.
    Screenshot,
    /// A scroll action.
    Scroll {
        /// The horizontal scroll distance.
        scroll_x: u64,
        /// The vertical scroll distance.
        scroll_y: u64,
        /// The x-coordinate where the scroll occurred.
        x: u64,
        /// The y-coordinate where the scroll occurred.
        y: u64,
    },
    /// An action to type in text.
    Type {
        /// The text to type.
        text: String,
    },
    /// A wait action.
    Wait,
}

/// Indicates which mouse button was pressed during the click.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ClickButton {
    Left,
    Right,
    Wheel,
    Back,
    Forward,
}

/// Represents a coordinate in a drag action.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DragCoordinate {
    /// The x-coordinate of the drag action.
    pub x: u64,
    /// The y-coordinate of the drag action.
    pub y: u64,
}

/// Represents a pending safety check for a computer use call.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SafetyCheck {
    /// The type of the pending safety check.
    pub code: String,
    /// The ID of the pending safety check.
    pub id: String,
    /// Details about the pending safety check.
    pub message: String,
}

/// The status of the computer use call.
///
/// See the [computer use guide](https://platform.openai.com/docs/guides/tools-computer-use) for more information.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ComputerCallStatus {
    InProgress,
    Completed,
    Incomplete,
}

/// The output of a computer use call.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComputerToolCallOutput {
    /// The ID of the computer tool call output. Populated when this item is returned via API.
    pub id: Option<String>,
    /// The status of the item. Populated when items are returned via API.
    pub status: Option<ComputerCallStatus>,
    /// The ID of the computer tool call that produced the output.
    pub call_id: String,
    /// A computer screenshot image used with the computer use tool.
    pub output: ComputerCallOutput,
    /// The safety checks reported by the API that have been acknowledged by the developer.
    pub acknowledged_safety_checks: Option<Vec<SafetyCheck>>,
}

/// A computer screenshot image used with the computer use tool.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ComputerCallOutput {
    /// A computer screenshot image used with the computer use tool.
    #[serde(rename = "computer_screenshot")]
    Screenshot {
        /// The identifier of an uploaded file that contains the screenshot.
        file_id: Option<String>,
        /// The URL of the screenshot image.
        image_url: Option<String>,
    },
}

/// A description of the chain of thought used by a reasoning model while generating a response.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Reasoning {
    /// The unique identifier of the reasoning content.
    pub id: String,
    /// Reasoning text contents.
    pub summary: Vec<ReasoningSummary>,
    /// The status of the item.
    pub status: ReasoningStatus,
}

/// Reasoning text contents.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum ReasoningSummary {
    #[serde(rename = "summary_text")]
    Text {
        /// A short summary of the reasoning used by the model when generating the response.
        text: String,
    },
}

/// The status of the reasoning data.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ReasoningStatus {
    InProgress,
    Completed,
    Incomplete,
}