openai-interface 0.10.0

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

use url::Url;

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

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

impl Delete for DeleteConversationItemRequest<'_> {
    /// 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)
            .push("items")
            .push(self.item_id);
        Ok(url.to_string())
    }
}

impl DeleteNoStream for DeleteConversationItemRequest<'_> {
    type Response = DeleteConversationItemResponse;
}

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

crate::impl_from_str!(DeleteConversationItemResponse);