openai-interface 0.13.0

A low-level Rust interface for the OpenAI API
Documentation
//! Delete a conversation via `DELETE /conversations/{conversation_id}`.
//!
//! > ![warn] This module is untested!
//! > If you encounter any issues, please report them on the repository.
//!
//! Deleting a conversation also deletes its items.

use url::Url;

use crate::{
    errors::OapiError,
    rest::delete::{Delete, DeleteNoStream},
};

/// Deletes a conversation by its ID.
#[derive(Debug, Clone)]
pub struct DeleteConversationRequest<'a> {
    /// The ID of the conversation to delete, e.g. `conv_...`.
    pub conversation_id: &'a str,
}

impl Delete for DeleteConversationRequest<'_> {
    /// Builds the URL for the request.
    ///
    /// `base_url` should be like <https://api.openai.com/v1>
    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
        url.path_segments_mut()
            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
            .push("conversations")
            .push(self.conversation_id);
        Ok(url.to_string())
    }
}

impl DeleteNoStream for DeleteConversationRequest<'_> {
    type Response = DeleteConversationResponse;
}

/// The response of a conversation deletion.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct DeleteConversationResponse {
    /// The ID of the conversation that was deleted.
    pub id: String,
    /// Whether the conversation was deleted successfully.
    pub deleted: bool,
    /// The object type (`conversation.deleted`), if the provider sends
    /// it.
    #[serde(default)]
    pub object: Option<String>,
}

crate::impl_from_str!(DeleteConversationResponse);