Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions async-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
| **Realtime** | Realtime Calls, Client secrets, Client events, Server events |
| **Chat Completions** | Chat Completions, Streaming |
| **Assistants** <sub>(Beta)</sub> | Assistants, Threads, Messages, Runs, Run steps, Streaming |
| **Administration** | Admin API Keys, Invites, Users, Projects, Project users, Project service accounts, Project API keys, Project rate limits, Audit logs, Usage, Certificates |
| **Administration** | Admin API Keys, Invites, Users, Groups, Roles, Role assignments, Projects, Project users, Project groups, Project service accounts, Project API keys, Project rate limits, Audit logs, Usage, Certificates |
| **Legacy** | Completions |

Features that makes `async-openai` unique:
- Bring your own custom types for Request or Response objects.
- SSE streaming on available APIs.
- Customize query and headers per request, customize headers globally.
- Customize path, query and headers per request; customize path and headers globally (for all requests).
- Requests (except SSE streaming) including form submissions are retried with exponential backoff when [rate limited](https://platform.openai.com/docs/guides/rate-limits).
- Ergonomic builder pattern for all request objects.
- Microsoft Azure OpenAI Service (only for APIs matching OpenAI spec).
Expand Down
15 changes: 13 additions & 2 deletions async-openai/src/admin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{
admin_api_keys::AdminAPIKeys, audit_logs::AuditLogs, certificates::Certificates,
config::Config, invites::Invites, projects::Projects, users::Users, Client,
config::Config, groups::Groups, invites::Invites, projects::Projects, roles::Roles,
users::Users, Client,
};

/// Admin group for all administration APIs.
/// This groups together admin API keys, invites, users, projects, audit logs, and certificates.
/// This groups together admin API keys, invites, users, projects, audit logs, certificates, roles, and groups.
pub struct Admin<'c, C: Config> {
client: &'c Client<C>,
}
Expand Down Expand Up @@ -43,4 +44,14 @@ impl<'c, C: Config> Admin<'c, C> {
pub fn certificates(&self) -> Certificates<'_, C> {
Certificates::new(self.client)
}

/// To call [Roles] group related APIs using this client.
pub fn roles(&self) -> Roles<'_, C> {
Roles::new(self.client)
}

/// To call [Groups] group related APIs using this client.
pub fn groups(&self) -> Groups<'_, C> {
Groups::new(self.client)
}
}
64 changes: 64 additions & 0 deletions async-openai/src/group_roles.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use crate::{
config::Config,
error::OpenAIError,
types::admin::groups::{GroupRoleAssignment, PublicAssignOrganizationGroupRoleBody},
types::admin::roles::{DeletedRoleAssignmentResource, RoleListResource},
Client, RequestOptions,
};

/// Manage role assignments for groups in the organization.
pub struct GroupRoles<'c, C: Config> {
client: &'c Client<C>,
pub group_id: String,
pub(crate) request_options: RequestOptions,
}

impl<'c, C: Config> GroupRoles<'c, C> {
pub fn new(client: &'c Client<C>, group_id: &str) -> Self {
Self {
client,
group_id: group_id.into(),
request_options: RequestOptions::new(),
}
}

/// Lists all role assignments for a group.
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<RoleListResource, OpenAIError> {
self.client
.get(
format!("/organization/groups/{}/roles", self.group_id).as_str(),
&self.request_options,
)
.await
}

/// Assigns a role to a group.
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn assign(
&self,
request: PublicAssignOrganizationGroupRoleBody,
) -> Result<GroupRoleAssignment, OpenAIError> {
self.client
.post(
format!("/organization/groups/{}/roles", self.group_id).as_str(),
request,
&self.request_options,
)
.await
}

/// Unassigns a role from a group.
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn unassign(
&self,
role_id: &str,
) -> Result<DeletedRoleAssignmentResource, OpenAIError> {
self.client
.delete(
format!("/organization/groups/{}/roles/{}", self.group_id, role_id).as_str(),
&self.request_options,
)
.await
}
}
62 changes: 62 additions & 0 deletions async-openai/src/group_users.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use crate::{
config::Config,
error::OpenAIError,
types::admin::groups::{
CreateGroupUserBody, GroupUserAssignment, GroupUserDeletedResource, UserListResource,
},
Client, RequestOptions,
};

/// Manage users within a group, including adding and removing users.
pub struct GroupUsers<'c, C: Config> {
client: &'c Client<C>,
pub group_id: String,
pub(crate) request_options: RequestOptions,
}

impl<'c, C: Config> GroupUsers<'c, C> {
pub fn new(client: &'c Client<C>, group_id: &str) -> Self {
Self {
client,
group_id: group_id.into(),
request_options: RequestOptions::new(),
}
}

/// Lists all users in a group.
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<UserListResource, OpenAIError> {
self.client
.get(
format!("/organization/groups/{}/users", self.group_id).as_str(),
&self.request_options,
)
.await
}

/// Adds a user to a group.
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn add(
&self,
request: CreateGroupUserBody,
) -> Result<GroupUserAssignment, OpenAIError> {
self.client
.post(
format!("/organization/groups/{}/users", self.group_id).as_str(),
request,
&self.request_options,
)
.await
}

/// Removes a user from a group.
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn remove(&self, user_id: &str) -> Result<GroupUserDeletedResource, OpenAIError> {
self.client
.delete(
format!("/organization/groups/{}/users/{user_id}", self.group_id).as_str(),
&self.request_options,
)
.await
}
}
79 changes: 79 additions & 0 deletions async-openai/src/groups.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use crate::{
config::Config,
error::OpenAIError,
group_roles::GroupRoles,
group_users::GroupUsers,
types::admin::groups::{
CreateGroupBody, GroupDeletedResource, GroupListResource, GroupResourceWithSuccess,
GroupResponse,
},
Client, RequestOptions,
};

/// Manage reusable collections of users for organization-wide access control and maintain their membership.
pub struct Groups<'c, C: Config> {
client: &'c Client<C>,
pub(crate) request_options: RequestOptions,
}

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

/// To call [GroupUsers] group related APIs using this client.
pub fn users(&self, group_id: &str) -> GroupUsers<'_, C> {
GroupUsers::new(self.client, group_id)
}

/// To call [GroupRoles] group related APIs using this client.
pub fn roles(&self, group_id: &str) -> GroupRoles<'_, C> {
GroupRoles::new(self.client, group_id)
}

/// Lists all groups in the organization.
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<GroupListResource, OpenAIError> {
self.client
.get("/organization/groups", &self.request_options)
.await
}

/// Creates a new group in the organization.
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn create(&self, request: CreateGroupBody) -> Result<GroupResponse, OpenAIError> {
self.client
.post("/organization/groups", request, &self.request_options)
.await
}

/// Updates a group's information.
#[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn update(
&self,
group_id: &str,
request: crate::types::admin::groups::UpdateGroupBody,
) -> Result<GroupResourceWithSuccess, OpenAIError> {
self.client
.post(
format!("/organization/groups/{group_id}").as_str(),
request,
&self.request_options,
)
.await
}

/// Deletes a group from the organization.
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn delete(&self, group_id: &str) -> Result<GroupDeletedResource, OpenAIError> {
self.client
.delete(
format!("/organization/groups/{group_id}").as_str(),
&self.request_options,
)
.await
}
}
18 changes: 18 additions & 0 deletions async-openai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,29 @@ mod eval_runs;
mod evals;
mod file;
mod fine_tuning;
mod group_roles;
mod group_users;
mod groups;
mod image;
mod invites;
mod messages;
mod model;
mod moderation;
mod project_api_keys;
mod project_certificates;
mod project_group_roles;
mod project_groups;
mod project_rate_limits;
mod project_roles;
mod project_service_accounts;
mod project_user_roles;
mod project_users;
mod projects;
#[cfg(feature = "realtime")]
mod realtime;
mod request_options;
mod responses;
mod roles;
mod runs;
mod speech;
mod steps;
Expand All @@ -189,6 +197,7 @@ mod translations;
pub mod types;
mod uploads;
mod usage;
mod user_roles;
mod users;
mod util;
mod vector_store_file_batches;
Expand Down Expand Up @@ -219,21 +228,29 @@ pub use eval_runs::EvalRuns;
pub use evals::Evals;
pub use file::Files;
pub use fine_tuning::FineTuning;
pub use group_roles::GroupRoles;
pub use group_users::GroupUsers;
pub use groups::Groups;
pub use image::Images;
pub use invites::Invites;
pub use messages::Messages;
pub use model::Models;
pub use moderation::Moderations;
pub use project_api_keys::ProjectAPIKeys;
pub use project_certificates::ProjectCertificates;
pub use project_group_roles::ProjectGroupRoles;
pub use project_groups::ProjectGroups;
pub use project_rate_limits::ProjectRateLimits;
pub use project_roles::ProjectRoles;
pub use project_service_accounts::ProjectServiceAccounts;
pub use project_user_roles::ProjectUserRoles;
pub use project_users::ProjectUsers;
pub use projects::Projects;
#[cfg(feature = "realtime")]
pub use realtime::Realtime;
pub use request_options::RequestOptions;
pub use responses::Responses;
pub use roles::Roles;
pub use runs::Runs;
pub use speech::Speech;
pub use steps::Steps;
Expand All @@ -242,6 +259,7 @@ pub use transcriptions::Transcriptions;
pub use translations::Translations;
pub use uploads::Uploads;
pub use usage::Usage;
pub use user_roles::UserRoles;
pub use users::Users;
pub use vector_store_file_batches::VectorStoreFileBatches;
pub use vector_store_files::VectorStoreFiles;
Expand Down
Loading
Loading