dynamo_async_openai/
users.rs

1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Based on https://github.com/64bit/async-openai/ by Himanshu Neema
5// Original Copyright (c) 2022 Himanshu Neema
6// Licensed under MIT License (see ATTRIBUTIONS-Rust.md)
7//
8// Modifications Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
9// Licensed under Apache 2.0
10
11use serde::Serialize;
12
13use crate::{
14    Client,
15    config::Config,
16    error::OpenAIError,
17    types::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest},
18};
19
20/// Manage users and their role in an organization. Users will be automatically added to the Default project.
21pub struct Users<'c, C: Config> {
22    client: &'c Client<C>,
23}
24
25impl<'c, C: Config> Users<'c, C> {
26    pub fn new(client: &'c Client<C>) -> Self {
27        Self { client }
28    }
29
30    /// Lists all of the users in the organization.
31    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
32    pub async fn list<Q>(&self, query: &Q) -> Result<UserListResponse, OpenAIError>
33    where
34        Q: Serialize + ?Sized,
35    {
36        self.client
37            .get_with_query("/organization/users", &query)
38            .await
39    }
40
41    /// Modifies a user's role in the organization.
42    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
43    pub async fn modify(
44        &self,
45        user_id: &str,
46        request: UserRoleUpdateRequest,
47    ) -> Result<User, OpenAIError> {
48        self.client
49            .post(format!("/organization/users/{user_id}").as_str(), request)
50            .await
51    }
52
53    /// Retrieve a user by their identifier
54    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
55    pub async fn retrieve(&self, user_id: &str) -> Result<User, OpenAIError> {
56        self.client
57            .get(format!("/organization/users/{user_id}").as_str())
58            .await
59    }
60
61    /// Deletes a user from the organization.
62    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
63    pub async fn delete(&self, user_id: &str) -> Result<UserDeleteResponse, OpenAIError> {
64        self.client
65            .delete(format!("/organizations/users/{user_id}").as_str())
66            .await
67    }
68}