Skip to main content

novel_openai/containers/
containers_.rs

1use crate::config::Config;
2use crate::error::OpenAIError;
3use crate::spec::containers::{
4    ContainerListResource, ContainerResource, CreateContainerRequest, DeleteContainerResponse,
5};
6use crate::{Client, ContainerFiles, RequestOptions};
7
8pub struct Containers<'c, C: Config> {
9    client: &'c Client<C>,
10    pub(crate) request_options: RequestOptions,
11}
12
13impl<'c, C: Config> Containers<'c, C> {
14    pub fn new(client: &'c Client<C>) -> Self {
15        Self {
16            client,
17            request_options: RequestOptions::new(),
18        }
19    }
20
21    /// [ContainerFiles] API group
22    pub fn files(&self, container_id: &str) -> ContainerFiles<'_, C> {
23        ContainerFiles::new(self.client, container_id)
24    }
25
26    /// Create a container.
27    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
28    pub async fn create(
29        &self,
30        request: CreateContainerRequest,
31    ) -> Result<ContainerResource, OpenAIError> {
32        self.client
33            .post("/containers", request, &self.request_options)
34            .await
35    }
36
37    /// List containers.
38    #[crate::byot(R = serde::de::DeserializeOwned)]
39    pub async fn list(&self) -> Result<ContainerListResource, OpenAIError> {
40        self.client.get("/containers", &self.request_options).await
41    }
42
43    /// Retrieve a container.
44    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
45    pub async fn retrieve(&self, container_id: &str) -> Result<ContainerResource, OpenAIError> {
46        self.client
47            .get(
48                format!("/containers/{container_id}").as_str(),
49                &self.request_options,
50            )
51            .await
52    }
53
54    /// Delete a container.
55    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
56    pub async fn delete(&self, container_id: &str) -> Result<DeleteContainerResponse, OpenAIError> {
57        self.client
58            .delete(
59                format!("/containers/{container_id}").as_str(),
60                &self.request_options,
61            )
62            .await
63    }
64}