async_openai/admin/
groups.rs1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::admin::groups::{
5 CreateGroupBody, GroupDeletedResource, GroupListResource, GroupResourceWithSuccess,
6 GroupResponse,
7 },
8 Client, GroupRoles, GroupUsers, RequestOptions,
9};
10
11pub struct Groups<'c, C: Config> {
13 client: &'c Client<C>,
14 pub(crate) request_options: RequestOptions,
15}
16
17impl<'c, C: Config> Groups<'c, C> {
18 pub fn new(client: &'c Client<C>) -> Self {
19 Self {
20 client,
21 request_options: RequestOptions::new(),
22 }
23 }
24
25 pub fn users(&self, group_id: &str) -> GroupUsers<'_, C> {
27 GroupUsers::new(self.client, group_id)
28 }
29
30 pub fn roles(&self, group_id: &str) -> GroupRoles<'_, C> {
32 GroupRoles::new(self.client, group_id)
33 }
34
35 #[crate::byot(R = serde::de::DeserializeOwned)]
37 pub async fn list(&self) -> Result<GroupListResource, OpenAIError> {
38 self.client
39 .get("/organization/groups", &self.request_options)
40 .await
41 }
42
43 #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
45 pub async fn create(&self, request: CreateGroupBody) -> Result<GroupResponse, OpenAIError> {
46 self.client
47 .post("/organization/groups", request, &self.request_options)
48 .await
49 }
50
51 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
53 pub async fn update(
54 &self,
55 group_id: &str,
56 request: crate::types::admin::groups::UpdateGroupBody,
57 ) -> Result<GroupResourceWithSuccess, OpenAIError> {
58 self.client
59 .post(
60 format!("/organization/groups/{group_id}").as_str(),
61 request,
62 &self.request_options,
63 )
64 .await
65 }
66
67 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
69 pub async fn delete(&self, group_id: &str) -> Result<GroupDeletedResource, OpenAIError> {
70 self.client
71 .delete(
72 format!("/organization/groups/{group_id}").as_str(),
73 &self.request_options,
74 )
75 .await
76 }
77}