async_openai/types/responses/
conversation.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5    error::OpenAIError,
6    types::responses::{
7        AnyItemReference, CodeInterpreterToolCall, ComputerToolCall, CustomToolCall,
8        CustomToolCallOutput, FileSearchToolCall, ImageGenToolCall, InputFileContent,
9        InputImageContent, InputItem, InputTextContent, LocalShellToolCall,
10        LocalShellToolCallOutput, MCPApprovalRequest, MCPApprovalResponse, MCPListTools,
11        MCPToolCall, OutputTextContent, ReasoningItem, ReasoningTextContent, RefusalContent,
12        WebSearchToolCall,
13    },
14};
15
16use crate::types::common::Metadata;
17
18/// Represents a conversation object.
19#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
20pub struct ConversationResource {
21    /// The unique ID of the conversation.
22    pub id: String,
23    /// The object type, which is always `conversation`.
24    pub object: String,
25    /// Set of 16 key-value pairs that can be attached to an object.
26    pub metadata: Metadata,
27    /// The time at which the conversation was created, measured in seconds since the Unix epoch.
28    pub created_at: i64,
29}
30
31/// Request to create a conversation.
32/// openapi spec type: CreateConversationBody
33#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
34#[builder(name = "CreateConversationRequestArgs")]
35#[builder(pattern = "mutable")]
36#[builder(setter(into, strip_option), default)]
37#[builder(derive(Debug))]
38#[builder(build_fn(error = "OpenAIError"))]
39pub struct CreateConversationRequest {
40    /// Set of 16 key-value pairs that can be attached to an object.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    pub metadata: Option<Metadata>,
43
44    /// Initial items to include in the conversation context. You may add up to 20 items at a time.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub items: Option<Vec<InputItem>>,
47}
48
49/// Request to update a conversation.
50#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
51#[builder(name = "UpdateConversationRequestArgs")]
52#[builder(pattern = "mutable")]
53#[builder(setter(into, strip_option), default)]
54#[builder(derive(Debug))]
55#[builder(build_fn(error = "OpenAIError"))]
56pub struct UpdateConversationRequest {
57    /// Set of 16 key-value pairs that can be attached to an object.
58    pub metadata: Metadata,
59}
60
61/// Represents a deleted conversation.
62#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
63pub struct DeleteConversationResponse {
64    /// The unique ID of the deleted conversation.
65    pub id: String,
66    /// The object type, which is always `conversation.deleted`.
67    pub object: String,
68    /// Whether the conversation was successfully deleted.
69    pub deleted: bool,
70}
71
72/// Request to create conversation items.
73#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
74#[builder(name = "CreateConversationItemsRequestArgs")]
75#[builder(pattern = "mutable")]
76#[builder(setter(into, strip_option), default)]
77#[builder(derive(Debug))]
78#[builder(build_fn(error = "OpenAIError"))]
79pub struct CreateConversationItemsRequest {
80    /// The items to add to the conversation. You may add up to 20 items at a time.
81    pub items: Vec<InputItem>,
82}
83
84/// A list of Conversation items.
85#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
86pub struct ConversationItemList {
87    /// The type of object returned, must be `list`.
88    pub object: String,
89    /// A list of conversation items.
90    pub data: Vec<ConversationItem>,
91    /// Whether there are more items available.
92    pub has_more: bool,
93    /// The ID of the first item in the list.
94    pub first_id: String,
95    /// The ID of the last item in the list.
96    pub last_id: String,
97}
98
99#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
100#[serde(rename_all = "snake_case")]
101pub enum MessageStatus {
102    InProgress,
103    Incomplete,
104    Completed,
105}
106
107#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
108#[serde(rename_all = "snake_case")]
109pub enum MessageRole {
110    Unknown,
111    User,
112    Assistant,
113    System,
114    Critic,
115    Discriminator,
116    Developer,
117    Tool,
118}
119
120#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
121pub struct TextContent {
122    pub text: String,
123}
124
125#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
126pub struct SummaryTextContent {
127    /// A summary of the reasoning output from the model so far.
128    pub text: String,
129}
130
131#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
132pub struct ComputerScreenContent {
133    /// The URL of the screenshot image.
134    pub image_url: Option<String>,
135    ///  The identifier of an uploaded file that contains the screenshot.
136    pub file_id: Option<String>,
137}
138
139#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
140#[serde(tag = "type", rename_all = "snake_case")]
141pub enum MessageContent {
142    InputText(InputTextContent),
143    OutputText(OutputTextContent),
144    Text(TextContent),
145    SummaryText(SummaryTextContent),
146    ReasoningText(ReasoningTextContent),
147    Refusal(RefusalContent),
148    InputImage(InputImageContent),
149    ComputerScreen(ComputerScreenContent),
150    InputFile(InputFileContent),
151}
152
153#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
154pub struct Message {
155    /// The unique ID of the message.
156    pub id: String,
157    /// The status of item. One of `in_progress`, `completed`, or `incomplete`. Populated when items are
158    /// returned via API.
159    pub status: MessageStatus,
160    /// The role of the message. One of `unknown`, `user`, `assistant`, `system`, `critic`,
161    /// `discriminator`, `developer`, or `tool`.
162    pub role: MessageRole,
163    /// The content of the message.
164    pub content: Vec<MessageContent>,
165}
166
167#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
168#[serde(tag = "type", rename_all = "snake_case")]
169pub enum ConversationItem {
170    Message(Message),
171    FileSearchCall(FileSearchToolCall),
172    WebSearchCall(WebSearchToolCall),
173    ImageGenerationCall(ImageGenToolCall),
174    ComputerCall(ComputerToolCall),
175    Reasoning(ReasoningItem),
176    CodeInterpreterCall(CodeInterpreterToolCall),
177    LocalShellCall(LocalShellToolCall),
178    LocalShellCallOutput(LocalShellToolCallOutput),
179    McpListTools(MCPListTools),
180    McpApprovalRequest(MCPApprovalRequest),
181    McpApprovalResponse(MCPApprovalResponse),
182    McpCall(MCPToolCall),
183    CustomToolCall(CustomToolCall),
184    CustomToolCallOutput(CustomToolCallOutput),
185    #[serde(untagged)]
186    ItemReference(AnyItemReference),
187}
188
189/// Additional fields to include in the response.
190#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
191#[serde(rename_all = "snake_case")]
192pub enum IncludeParam {
193    /// Include the sources of the web search tool call.
194    #[serde(rename = "web_search_call.action.sources")]
195    WebSearchCallActionSources,
196    /// Include the outputs of python code execution in code interpreter tool call items.
197    #[serde(rename = "code_interpreter_call.outputs")]
198    CodeInterpreterCallOutputs,
199    /// Include image urls from the computer call output.
200    #[serde(rename = "computer_call_output.output.image_url")]
201    ComputerCallOutputOutputImageUrl,
202    /// Include the search results of the file search tool call.
203    #[serde(rename = "file_search_call.results")]
204    FileSearchCallResults,
205    /// Include image urls from the input message.
206    #[serde(rename = "message.input_image.image_url")]
207    MessageInputImageImageUrl,
208    /// Include logprobs with assistant messages.
209    #[serde(rename = "message.output_text.logprobs")]
210    MessageOutputTextLogprobs,
211    /// Include an encrypted version of reasoning tokens in reasoning item outputs.
212    #[serde(rename = "reasoning.encrypted_content")]
213    ReasoningEncryptedContent,
214}
215
216/// Query parameters for listing conversation items.
217#[derive(Clone, Serialize, Default, Debug, Deserialize, Builder, PartialEq)]
218#[builder(name = "ListConversationItemsQueryArgs")]
219#[builder(pattern = "mutable")]
220#[builder(setter(into, strip_option), default)]
221#[builder(derive(Debug))]
222#[builder(build_fn(error = "OpenAIError"))]
223pub struct ListConversationItemsQuery {
224    /// A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
225    #[serde(skip_serializing_if = "Option::is_none")]
226    pub limit: Option<u32>,
227
228    /// The order to return the input items in. Default is `desc`.
229    #[serde(skip_serializing_if = "Option::is_none")]
230    pub order: Option<ListOrder>,
231
232    /// An item ID to list items after, used in pagination.
233    #[serde(skip_serializing_if = "Option::is_none")]
234    pub after: Option<String>,
235
236    /// Specify additional output data to include in the model response.
237    #[serde(skip_serializing_if = "Option::is_none")]
238    pub include: Option<Vec<IncludeParam>>,
239}
240
241/// The order to return items in.
242#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
243#[serde(rename_all = "lowercase")]
244pub enum ListOrder {
245    /// Return items in ascending order.
246    Asc,
247    /// Return items in descending order.
248    Desc,
249}