Skip to main content

openai_interface/conversations/items/
delete.rs

1//! Delete a conversation item via
2//! `DELETE /conversations/{conversation_id}/items/{item_id}`.
3//!
4//! > ![warn] This module is untested!
5//! > If you encounter any issues, please report them on the repository.
6
7use url::Url;
8
9use crate::{
10    errors::OapiError,
11    rest::delete::{Delete, DeleteNoStream},
12};
13
14/// Deletes an item from a conversation.
15#[derive(Debug, Clone)]
16pub struct DeleteConversationItemRequest<'a> {
17    /// The ID of the conversation, e.g. `conv_...`.
18    pub conversation_id: &'a str,
19    /// The ID of the item to delete.
20    pub item_id: &'a str,
21}
22
23impl Delete for DeleteConversationItemRequest<'_> {
24    /// Builds the URL for the request.
25    ///
26    /// `base_url` should be like <https://api.openai.com/v1>
27    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
28        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
29        url.path_segments_mut()
30            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
31            .push("conversations")
32            .push(self.conversation_id)
33            .push("items")
34            .push(self.item_id);
35        Ok(url.to_string())
36    }
37}
38
39impl DeleteNoStream for DeleteConversationItemRequest<'_> {
40    type Response = DeleteConversationItemResponse;
41}
42
43/// The response of a conversation item deletion.
44#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
45pub struct DeleteConversationItemResponse {
46    /// The ID of the item that was deleted.
47    pub id: String,
48    /// Whether the item was deleted successfully.
49    pub deleted: bool,
50    /// The object type (`conversation.item.deleted`), if the provider
51    /// sends it.
52    #[serde(default)]
53    pub object: Option<String>,
54}
55
56crate::impl_from_str!(DeleteConversationItemResponse);