async_openai/
project_groups.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::admin::projects::{
5 InviteProjectGroupBody, ProjectGroup, ProjectGroupDeletedResource, ProjectGroupListResource,
6 },
7 Client, RequestOptions,
8};
9
10pub struct ProjectGroups<'c, C: Config> {
12 client: &'c Client<C>,
13 pub project_id: String,
14 pub(crate) request_options: RequestOptions,
15}
16
17impl<'c, C: Config> ProjectGroups<'c, C> {
18 pub fn new(client: &'c Client<C>, project_id: &str) -> Self {
19 Self {
20 client,
21 project_id: project_id.into(),
22 request_options: RequestOptions::new(),
23 }
24 }
25
26 #[crate::byot(R = serde::de::DeserializeOwned)]
28 pub async fn list(&self) -> Result<ProjectGroupListResource, OpenAIError> {
29 self.client
30 .get(
31 format!("/organization/projects/{}/groups", self.project_id).as_str(),
32 &self.request_options,
33 )
34 .await
35 }
36
37 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
39 pub async fn add(&self, request: InviteProjectGroupBody) -> Result<ProjectGroup, OpenAIError> {
40 self.client
41 .post(
42 format!("/organization/projects/{}/groups", self.project_id).as_str(),
43 request,
44 &self.request_options,
45 )
46 .await
47 }
48
49 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
51 pub async fn remove(&self, group_id: &str) -> Result<ProjectGroupDeletedResource, OpenAIError> {
52 self.client
53 .delete(
54 format!(
55 "/organization/projects/{}/groups/{group_id}",
56 self.project_id
57 )
58 .as_str(),
59 &self.request_options,
60 )
61 .await
62 }
63}