Skip to main content

openai_interface/conversations/
delete.rs

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