|
1 | 1 | use async_openai::{ |
2 | 2 | types::responses::{ |
3 | | - CreateConversationItemsRequestArgs, CreateConversationRequestArgs, EasyInputContent, |
4 | | - EasyInputMessage, InputItem, ListConversationItemsQuery, MessageType, Role, |
5 | | - UpdateConversationRequestArgs, |
| 3 | + ConversationItem, CreateConversationItemsRequestArgs, CreateConversationRequestArgs, |
| 4 | + EasyInputContent, EasyInputMessage, InputItem, ListConversationItemsQuery, MessageType, |
| 5 | + Role, UpdateConversationRequestArgs, |
6 | 6 | }, |
7 | 7 | Client, |
8 | 8 | }; |
@@ -120,27 +120,53 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { |
120 | 120 |
|
121 | 121 | println!("Updated metadata: {:?}\n", updated_conversation.metadata); |
122 | 122 |
|
123 | | - // 6. Delete an item from the conversation |
124 | | - if !all_items.data.is_empty() { |
125 | | - println!("6. Deleting an item from the conversation..."); |
126 | | - let item_to_delete = &all_items.last_id; |
127 | | - let updated_conv = client |
| 123 | + // 6. Retrieve the conversation |
| 124 | + println!("6. Retrieving the conversation..."); |
| 125 | + let retrieved_conversation = client.conversations().retrieve(&conversation.id).await?; |
| 126 | + println!("Retrieved conversation: {}", retrieved_conversation.id); |
| 127 | + println!("Metadata: {:?}\n", retrieved_conversation.metadata); |
| 128 | + |
| 129 | + // 7. Delete the conversation items. |
| 130 | + println!("7. Deleting the conversation items..."); |
| 131 | + for item in all_items.data { |
| 132 | + let item_id = match item { |
| 133 | + ConversationItem::Message(message) => message.id, |
| 134 | + ConversationItem::FileSearchCall(file_search_tool_call) => file_search_tool_call.id, |
| 135 | + ConversationItem::WebSearchCall(web_search_tool_call) => web_search_tool_call.id, |
| 136 | + ConversationItem::ImageGenerationCall(image_gen_tool_call) => image_gen_tool_call.id, |
| 137 | + ConversationItem::ComputerCall(computer_tool_call) => computer_tool_call.id, |
| 138 | + ConversationItem::Reasoning(reasoning_item) => reasoning_item.id, |
| 139 | + ConversationItem::CodeInterpreterCall(code_interpreter_tool_call) => { |
| 140 | + code_interpreter_tool_call.id |
| 141 | + } |
| 142 | + ConversationItem::LocalShellCall(local_shell_tool_call) => local_shell_tool_call.id, |
| 143 | + ConversationItem::LocalShellCallOutput(local_shell_tool_call_output) => { |
| 144 | + local_shell_tool_call_output.id |
| 145 | + } |
| 146 | + ConversationItem::McpListTools(mcplist_tools) => mcplist_tools.id, |
| 147 | + ConversationItem::McpApprovalRequest(mcpapproval_request) => mcpapproval_request.id, |
| 148 | + ConversationItem::McpApprovalResponse(mcpapproval_response) => { |
| 149 | + mcpapproval_response.id.unwrap() |
| 150 | + } |
| 151 | + ConversationItem::McpCall(mcptool_call) => mcptool_call.id, |
| 152 | + ConversationItem::CustomToolCall(custom_tool_call) => custom_tool_call.id, |
| 153 | + ConversationItem::CustomToolCallOutput(custom_tool_call_output) => { |
| 154 | + custom_tool_call_output.id.unwrap() |
| 155 | + } |
| 156 | + ConversationItem::ItemReference(any_item_reference) => any_item_reference.id, |
| 157 | + }; |
| 158 | + |
| 159 | + let conversation_resource = client |
128 | 160 | .conversations() |
129 | 161 | .items(&conversation.id) |
130 | | - .delete(item_to_delete) |
| 162 | + .delete(&item_id) |
131 | 163 | .await?; |
132 | 164 | println!( |
133 | | - "Item deleted. Conversation still exists: {}\n", |
134 | | - updated_conv.id |
| 165 | + "Item deleted: item id: {item_id}, conversation id: {}", |
| 166 | + conversation_resource.id |
135 | 167 | ); |
136 | 168 | } |
137 | 169 |
|
138 | | - // 7. Retrieve the conversation |
139 | | - println!("7. Retrieving the conversation..."); |
140 | | - let retrieved_conversation = client.conversations().retrieve(&conversation.id).await?; |
141 | | - println!("Retrieved conversation: {}", retrieved_conversation.id); |
142 | | - println!("Metadata: {:?}\n", retrieved_conversation.metadata); |
143 | | - |
144 | 170 | // 8. Delete the conversation |
145 | 171 | println!("8. Deleting the conversation..."); |
146 | 172 | let deleted = client.conversations().delete(&conversation.id).await?; |
|
0 commit comments