Skip to main content

openai_interface/containers/
delete.rs

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