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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
21pub struct ConversationResource {
22 pub id: String,
24 pub object: String,
26 pub metadata: Metadata,
28 pub created_at: u64,
30}
31
32#[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 #[serde(skip_serializing_if = "Option::is_none")]
43 pub metadata: Option<Metadata>,
44
45 #[serde(skip_serializing_if = "Option::is_none")]
47 pub items: Option<Vec<InputItem>>,
48}
49
50#[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 pub metadata: Metadata,
60}
61
62#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
64pub struct DeleteConversationResponse {
65 pub id: String,
67 pub object: String,
69 pub deleted: bool,
71}
72
73#[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 pub items: Vec<InputItem>,
83}
84
85#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
87pub struct ConversationItemList {
88 pub object: String,
90 pub data: Vec<ConversationItem>,
92 pub has_more: bool,
94 pub first_id: Option<String>,
96 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 pub text: String,
130}
131
132#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
133pub struct ComputerScreenContent {
134 pub image_url: Option<String>,
136 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 pub id: String,
158 pub status: MessageStatus,
161 pub role: MessageRole,
164 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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
198#[serde(rename_all = "snake_case")]
199pub enum IncludeParam {
200 #[serde(rename = "web_search_call.action.sources")]
202 WebSearchCallActionSources,
203 #[serde(rename = "code_interpreter_call.outputs")]
205 CodeInterpreterCallOutputs,
206 #[serde(rename = "computer_call_output.output.image_url")]
208 ComputerCallOutputOutputImageUrl,
209 #[serde(rename = "file_search_call.results")]
211 FileSearchCallResults,
212 #[serde(rename = "message.input_image.image_url")]
214 MessageInputImageImageUrl,
215 #[serde(rename = "message.output_text.logprobs")]
217 MessageOutputTextLogprobs,
218 #[serde(rename = "reasoning.encrypted_content")]
220 ReasoningEncryptedContent,
221}
222
223#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
225#[serde(rename_all = "lowercase")]
226pub enum ListOrder {
227 Asc,
229 Desc,
231}