Skip to content

Commit d59ee80

Browse files
committed
update example
1 parent c41000f commit d59ee80

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

examples/conversations/src/main.rs

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use async_openai::{
22
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,
66
},
77
Client,
88
};
@@ -120,27 +120,53 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
120120

121121
println!("Updated metadata: {:?}\n", updated_conversation.metadata);
122122

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
128160
.conversations()
129161
.items(&conversation.id)
130-
.delete(item_to_delete)
162+
.delete(&item_id)
131163
.await?;
132164
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
135167
);
136168
}
137169

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-
144170
// 8. Delete the conversation
145171
println!("8. Deleting the conversation...");
146172
let deleted = client.conversations().delete(&conversation.id).await?;

0 commit comments

Comments
 (0)