async_openai/
projects.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use serde::Serialize;

use crate::{
    config::Config,
    error::OpenAIError,
    project_api_keys::ProjectAPIKeys,
    types::{Project, ProjectCreateRequest, ProjectListResponse, ProjectUpdateRequest},
    Client, ProjectServiceAccounts, ProjectUsers,
};

/// Manage the projects within an organization includes creation, updating, and archiving or projects.
/// The Default project cannot be modified or archived.
pub struct Projects<'c, C: Config> {
    client: &'c Client<C>,
}

impl<'c, C: Config> Projects<'c, C> {
    pub fn new(client: &'c Client<C>) -> Self {
        Self { client }
    }

    // call [ProjectUsers] group APIs
    pub fn users(&self, project_id: &str) -> ProjectUsers<C> {
        ProjectUsers::new(self.client, project_id)
    }

    // call [ProjectServiceAccounts] group APIs
    pub fn service_accounts(&self, project_id: &str) -> ProjectServiceAccounts<C> {
        ProjectServiceAccounts::new(self.client, project_id)
    }

    // call [ProjectAPIKeys] group APIs
    pub fn api_keys(&self, project_id: &str) -> ProjectAPIKeys<C> {
        ProjectAPIKeys::new(self.client, project_id)
    }

    /// Returns a list of projects.
    pub async fn list<Q>(&self, query: &Q) -> Result<ProjectListResponse, OpenAIError>
    where
        Q: Serialize + ?Sized,
    {
        self.client
            .get_with_query("/organization/projects", query)
            .await
    }

    /// Create a new project in the organization. Projects can be created and archived, but cannot be deleted.
    pub async fn create(&self, request: ProjectCreateRequest) -> Result<Project, OpenAIError> {
        self.client.post("/organization/projects", request).await
    }

    /// Retrieves a project.
    pub async fn retrieve(&self, project_id: String) -> Result<Project, OpenAIError> {
        self.client
            .get(format!("/organization/projects/{project_id}").as_str())
            .await
    }

    /// Modifies a project in the organization.
    pub async fn modify(
        &self,
        project_id: String,
        request: ProjectUpdateRequest,
    ) -> Result<Project, OpenAIError> {
        self.client
            .post(
                format!("/organization/projects/{project_id}").as_str(),
                request,
            )
            .await
    }

    /// Archives a project in the organization. Archived projects cannot be used or updated.
    pub async fn archive(&self, project_id: String) -> Result<Project, OpenAIError> {
        self.client
            .post(
                format!("/organization/projects/{project_id}/archive").as_str(),
                (),
            )
            .await
    }
}