Skip to main content

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