async_openai/
users.rs

1use serde::Serialize;
2
3use crate::{
4    config::Config,
5    error::OpenAIError,
6    types::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest},
7    Client,
8};
9
10/// Manage users and their role in an organization. Users will be automatically added to the Default project.
11pub struct Users<'c, C: Config> {
12    client: &'c Client<C>,
13}
14
15impl<'c, C: Config> Users<'c, C> {
16    pub fn new(client: &'c Client<C>) -> Self {
17        Self { client }
18    }
19
20    /// Lists all of the users in the organization.
21    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
22    pub async fn list<Q>(&self, query: &Q) -> Result<UserListResponse, OpenAIError>
23    where
24        Q: Serialize + ?Sized,
25    {
26        self.client
27            .get_with_query("/organization/users", &query)
28            .await
29    }
30
31    /// Modifies a user's role in the organization.
32    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
33    pub async fn modify(
34        &self,
35        user_id: &str,
36        request: UserRoleUpdateRequest,
37    ) -> Result<User, OpenAIError> {
38        self.client
39            .post(format!("/organization/users/{user_id}").as_str(), request)
40            .await
41    }
42
43    /// Retrieve a user by their identifier
44    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
45    pub async fn retrieve(&self, user_id: &str) -> Result<User, OpenAIError> {
46        self.client
47            .get(format!("/organization/users/{user_id}").as_str())
48            .await
49    }
50
51    /// Deletes a user from the organization.
52    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
53    pub async fn delete(&self, user_id: &str) -> Result<UserDeleteResponse, OpenAIError> {
54        self.client
55            .delete(format!("/organizations/users/{user_id}").as_str())
56            .await
57    }
58}