async_openai/
containers.rs

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