async_openai/containers/
containers_.rs

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