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