async_openai_alt/
projects.rs1use serde::Serialize;
2
3use crate::{
4 config::Config,
5 error::OpenAIError,
6 project_api_keys::ProjectAPIKeys,
7 types::{Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest},
8 Client, ProjectServiceAccounts, ProjectUsers,
9};
10
11pub struct Projects<'c, C: Config> {
14 client: &'c Client<C>,
15}
16
17impl<'c, C: Config> Projects<'c, C> {
18 pub fn new(client: &'c Client<C>) -> Self {
19 Self { client }
20 }
21
22 pub fn users(&self, project_id: &str) -> ProjectUsers<C> {
24 ProjectUsers::new(self.client, project_id)
25 }
26
27 pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<C> {
29 ProjectServiceAccounts::new(self.client, project_id)
30 }
31
32 pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<C> {
34 ProjectAPIKeys::new(self.client, project_id)
35 }
36
37 pub async fn list<Q>(&self, query: &Q) -> Result<ProjectListResponse, OpenAIError>
39 where
40 Q: Serialize + ?Sized,
41 {
42 self.client
43 .get_with_query("/organization/projects", query)
44 .await
45 }
46
47 pub async fn create(&self, request: ProjectCreateRequest) -> Result<Project, OpenAIError> {
49 self.client.post("/organization/projects", request).await
50 }
51
52 pub async fn retrieve(&self, project_id: String) -> Result<Project, OpenAIError> {
54 self.client
55 .get(format!("/organization/projects/{project_id}").as_str())
56 .await
57 }
58
59 pub async fn modify(
61 &self,
62 project_id: String,
63 request: ProjectUpdateRequest,
64 ) -> Result<Project, OpenAIError> {
65 self.client
66 .post(
67 format!("/organization/projects/{project_id}").as_str(),
68 request,
69 )
70 .await
71 }
72
73 pub async fn archive(&self, project_id: String) -> Result<Project, OpenAIError> {
75 self.client
76 .post(
77 format!("/organization/projects/{project_id}/archive").as_str(),
78 (),
79 )
80 .await
81 }
82}