-
-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathcontainers.rs
More file actions
60 lines (52 loc) · 1.8 KB
/
containers.rs
File metadata and controls
60 lines (52 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use serde::Serialize;
use crate::{
config::Config,
container_files::ContainerFiles,
error::OpenAIError,
types::{
ContainerListResource, ContainerResource, CreateContainerRequest, DeleteContainerResponse,
},
Client,
};
pub struct Containers<'c, C: Config> {
client: &'c Client<C>,
}
impl<'c, C: Config> Containers<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self { client }
}
/// [ContainerFiles] API group
pub fn files(&self, container_id: &str) -> ContainerFiles<'_, C> {
ContainerFiles::new(self.client, container_id)
}
/// Create a container.
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn create(
&self,
request: CreateContainerRequest,
) -> Result<ContainerResource, OpenAIError> {
self.client.post("/containers", request).await
}
/// List containers.
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn list<Q>(&self, query: &Q) -> Result<ContainerListResource, OpenAIError>
where
Q: Serialize + ?Sized,
{
self.client.get_with_query("/containers", &query).await
}
/// Retrieve a container.
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn retrieve(&self, container_id: &str) -> Result<ContainerResource, OpenAIError> {
self.client
.get(format!("/containers/{container_id}").as_str())
.await
}
/// Delete a container.
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn delete(&self, container_id: &str) -> Result<DeleteContainerResponse, OpenAIError> {
self.client
.delete(format!("/containers/{container_id}").as_str())
.await
}
}