openai-interface 0.10.0

A low-level Rust interface for the OpenAI API
Documentation
//! Delete a container via `DELETE /containers/{container_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 a container by its ID.
#[derive(Debug, Clone)]
pub struct DeleteContainerRequest<'a> {
    /// The ID of the container to delete, e.g. `cntr_...`.
    pub container_id: &'a str,
}

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

impl DeleteNoStream for DeleteContainerRequest<'_> {
    type Response = DeleteContainerResponse;
}

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

crate::impl_from_str!(DeleteContainerResponse);