openai-interface 0.14.0

A low-level Rust interface for the OpenAI API
Documentation
//! Module for deleting a stored chat completion.
//!
//! This module is untested! If you encounter any issues,
//! please report them on the repository.

pub mod request {
    use url::Url;

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

    /// Delete a stored chat completion.
    ///
    /// Only Chat Completions that have been created
    /// with the `store` parameter set to `true` can be deleted.
    #[derive(Debug, Clone)]
    pub struct ChatDeleteRequest<'a> {
        pub completion_id: &'a str,
    }

    impl Delete for ChatDeleteRequest<'_> {
        /// 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, crate::errors::OapiError> {
            let mut url = Url::parse(base_url).map_err(OapiError::UrlError)?;
            url.path_segments_mut()
                .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
                .push("chat")
                .push("completions")
                .push(self.completion_id);
            Ok(url.to_string())
        }
    }

    impl DeleteNoStream for ChatDeleteRequest<'_> {
        type Response = ChatCompletionDeleted;
    }
}

pub mod response {
    use serde::Deserialize;

    /// The response of a chat completion deletion, e.g.
    /// `{"object": "chat.completion.deleted", "id": "...", "deleted": true}`.
    #[derive(Debug, Clone, Deserialize)]
    pub struct ChatCompletionDeleted {
        /// The ID of the chat completion that was deleted.
        pub id: String,
        /// Whether the chat completion was deleted.
        pub deleted: bool,
        /// The type of the object, which is always `chat.completion.deleted`.
        pub object: ChatCompletionDeletedObject,
    }

    #[derive(Debug, Clone, Deserialize)]
    pub enum ChatCompletionDeletedObject {
        #[serde(rename = "chat.completion.deleted")]
        ChatCompletionDeleted,
    }

    crate::impl_from_str!(ChatCompletionDeleted);
}