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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
23pub struct ConversationResource {
24 pub id: String,
26 pub object: String,
28 pub metadata: Metadata,
30 pub created_at: u64,
32}
33
34#[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 #[serde(skip_serializing_if = "Option::is_none")]
45 pub metadata: Option<Metadata>,
46
47 #[serde(skip_serializing_if = "Option::is_none")]
49 pub items: Option<Vec<InputItem>>,
50}
51
52#[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 pub metadata: Metadata,
62}
63
64#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
66pub struct DeleteConversationResponse {
67 pub id: String,
69 pub object: String,
71 pub deleted: bool,
73}
74
75#[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 pub items: Vec<InputItem>,
85}
86
87#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
89pub struct ConversationItemList {
90 pub object: String,
92 pub data: Vec<ConversationItem>,
94 pub has_more: bool,
96 pub first_id: Option<String>,
98 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 pub text: String,
132}
133
134#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
135pub struct ComputerScreenContent {
136 pub image_url: Option<String>,
138 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 pub id: String,
160 pub status: MessageStatus,
163 pub role: MessageRole,
166 pub content: Vec<MessageContent>,
168 #[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#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
212#[serde(rename_all = "snake_case")]
213pub enum IncludeParam {
214 #[serde(rename = "web_search_call.action.sources")]
216 WebSearchCallActionSources,
217 #[serde(rename = "code_interpreter_call.outputs")]
219 CodeInterpreterCallOutputs,
220 #[serde(rename = "computer_call_output.output.image_url")]
222 ComputerCallOutputOutputImageUrl,
223 #[serde(rename = "file_search_call.results")]
225 FileSearchCallResults,
226 #[serde(rename = "message.input_image.image_url")]
228 MessageInputImageImageUrl,
229 #[serde(rename = "message.output_text.logprobs")]
231 MessageOutputTextLogprobs,
232 #[serde(rename = "reasoning.encrypted_content")]
234 ReasoningEncryptedContent,
235}
236
237#[derive(Clone, Serialize, Debug, Deserialize, PartialEq)]
239#[serde(rename_all = "lowercase")]
240pub enum ListOrder {
241 Asc,
243 Desc,
245}