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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
22pub struct ConversationResource {
23 pub id: String,
25 pub object: String,
27 pub metadata: Metadata,
29 pub created_at: u64,
31}
32
33#[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 #[serde(skip_serializing_if = "Option::is_none")]
44 pub metadata: Option<Metadata>,
45
46 #[serde(skip_serializing_if = "Option::is_none")]
48 pub items: Option<Vec<InputItem>>,
49}
50
51#[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 pub metadata: Metadata,
61}
62
63#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
65pub struct DeleteConversationResponse {
66 pub id: String,
68 pub object: String,
70 pub deleted: bool,
72}
73
74#[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 pub items: Vec<InputItem>,
84}
85
86#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
88pub struct ConversationItemList {
89 pub object: String,
91 pub data: Vec<ConversationItem>,
93 pub has_more: bool,
95 pub first_id: Option<String>,
97 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 pub text: String,
131}
132
133#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
134pub struct ComputerScreenContent {
135 pub image_url: Option<String>,
137 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 pub id: String,
159 pub status: MessageStatus,
162 pub role: MessageRole,
165 pub content: Vec<MessageContent>,
167 #[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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
207#[serde(rename_all = "snake_case")]
208pub enum IncludeParam {
209 #[serde(rename = "web_search_call.action.sources")]
211 WebSearchCallActionSources,
212 #[serde(rename = "code_interpreter_call.outputs")]
214 CodeInterpreterCallOutputs,
215 #[serde(rename = "computer_call_output.output.image_url")]
217 ComputerCallOutputOutputImageUrl,
218 #[serde(rename = "file_search_call.results")]
220 FileSearchCallResults,
221 #[serde(rename = "message.input_image.image_url")]
223 MessageInputImageImageUrl,
224 #[serde(rename = "message.output_text.logprobs")]
226 MessageOutputTextLogprobs,
227 #[serde(rename = "reasoning.encrypted_content")]
229 ReasoningEncryptedContent,
230}
231
232#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
234#[serde(rename_all = "lowercase")]
235pub enum ListOrder {
236 Asc,
238 Desc,
240}