async_openai_alt/
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    pub async fn list<Q>(&self, query: &Q) -> Result<UserListResponse, OpenAIError>
22    where
23        Q: Serialize + ?Sized,
24    {
25        self.client
26            .get_with_query("/organization/users", query)
27            .await
28    }
29
30    /// Modifies a user's role in the organization.
31    pub async fn modify(
32        &self,
33        user_id: &str,
34        request: UserRoleUpdateRequest,
35    ) -> Result<User, OpenAIError> {
36        self.client
37            .post(format!("/organization/users/{user_id}").as_str(), request)
38            .await
39    }
40
41    /// Retrieve a user by their identifier
42    pub async fn retrieve(&self, user_id: &str) -> Result<User, OpenAIError> {
43        self.client
44            .get(format!("/organization/users/{user_id}").as_str())
45            .await
46    }
47
48    /// Deletes a user from the organization.
49    pub async fn delete(&self, user_id: &str) -> Result<UserDeleteResponse, OpenAIError> {
50        self.client
51            .delete(format!("/organizations/users/{user_id}").as_str())
52            .await
53    }
54}