dynamo_async_openai/
projects.rs1use serde::Serialize;
12
13use crate::{
14 config::Config,
15 error::OpenAIError,
16 project_api_keys::ProjectAPIKeys,
17 types::{Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest},
18 Client, ProjectServiceAccounts, ProjectUsers,
19};
20
21pub struct Projects<'c, C: Config> {
24 client: &'c Client<C>,
25}
26
27impl<'c, C: Config> Projects<'c, C> {
28 pub fn new(client: &'c Client<C>) -> Self {
29 Self { client }
30 }
31
32 pub fn users(&self, project_id: &str) -> ProjectUsers<C> {
34 ProjectUsers::new(self.client, project_id)
35 }
36
37 pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<C> {
39 ProjectServiceAccounts::new(self.client, project_id)
40 }
41
42 pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<C> {
44 ProjectAPIKeys::new(self.client, project_id)
45 }
46
47 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
49 pub async fn list<Q>(&self, query: &Q) -> Result<ProjectListResponse, OpenAIError>
50 where
51 Q: Serialize + ?Sized,
52 {
53 self.client
54 .get_with_query("/organization/projects", &query)
55 .await
56 }
57
58 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
60 pub async fn create(&self, request: ProjectCreateRequest) -> Result<Project, OpenAIError> {
61 self.client.post("/organization/projects", request).await
62 }
63
64 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
66 pub async fn retrieve(&self, project_id: String) -> Result<Project, OpenAIError> {
67 self.client
68 .get(format!("/organization/projects/{project_id}").as_str())
69 .await
70 }
71
72 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
74 pub async fn modify(
75 &self,
76 project_id: String,
77 request: ProjectUpdateRequest,
78 ) -> Result<Project, OpenAIError> {
79 self.client
80 .post(
81 format!("/organization/projects/{project_id}").as_str(),
82 request,
83 )
84 .await
85 }
86
87 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
89 pub async fn archive(&self, project_id: String) -> Result<Project, OpenAIError> {
90 self.client
91 .post(
92 format!("/organization/projects/{project_id}/archive").as_str(),
93 (),
94 )
95 .await
96 }
97}