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