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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
20pub struct ConversationResource {
21 pub id: String,
23 pub object: String,
25 pub metadata: Metadata,
27 pub created_at: i64,
29}
30
31#[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 #[serde(skip_serializing_if = "Option::is_none")]
42 pub metadata: Option<Metadata>,
43
44 #[serde(skip_serializing_if = "Option::is_none")]
46 pub items: Option<Vec<InputItem>>,
47}
48
49#[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 pub metadata: Metadata,
59}
60
61#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
63pub struct DeleteConversationResponse {
64 pub id: String,
66 pub object: String,
68 pub deleted: bool,
70}
71
72#[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 pub items: Vec<InputItem>,
82}
83
84#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
86pub struct ConversationItemList {
87 pub object: String,
89 pub data: Vec<ConversationItem>,
91 pub has_more: bool,
93 pub first_id: String,
95 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 pub text: String,
129}
130
131#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
132pub struct ComputerScreenContent {
133 pub image_url: Option<String>,
135 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 pub id: String,
157 pub status: MessageStatus,
160 pub role: MessageRole,
163 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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
191#[serde(rename_all = "snake_case")]
192pub enum IncludeParam {
193 #[serde(rename = "web_search_call.action.sources")]
195 WebSearchCallActionSources,
196 #[serde(rename = "code_interpreter_call.outputs")]
198 CodeInterpreterCallOutputs,
199 #[serde(rename = "computer_call_output.output.image_url")]
201 ComputerCallOutputOutputImageUrl,
202 #[serde(rename = "file_search_call.results")]
204 FileSearchCallResults,
205 #[serde(rename = "message.input_image.image_url")]
207 MessageInputImageImageUrl,
208 #[serde(rename = "message.output_text.logprobs")]
210 MessageOutputTextLogprobs,
211 #[serde(rename = "reasoning.encrypted_content")]
213 ReasoningEncryptedContent,
214}
215
216#[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 #[serde(skip_serializing_if = "Option::is_none")]
226 pub limit: Option<u32>,
227
228 #[serde(skip_serializing_if = "Option::is_none")]
230 pub order: Option<ListOrder>,
231
232 #[serde(skip_serializing_if = "Option::is_none")]
234 pub after: Option<String>,
235
236 #[serde(skip_serializing_if = "Option::is_none")]
238 pub include: Option<Vec<IncludeParam>>,
239}
240
241#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
243#[serde(rename_all = "lowercase")]
244pub enum ListOrder {
245 Asc,
247 Desc,
249}