forked from 64bit/async-openai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spec sync: Uploads + Administration APIs (64bit#286)
* uploads API * moderations API update * CreateFineTuningJobRequest comment docs updated * added Audit Logs API * organization invite API updated * organization users API updated * updated project APIs * fix project archive url * update Client to create audit_logs, invites, users, and projects API groups * updated ProjectUsers APIs * addeds project service account APIs * ProjectServiceAccounts api group * added project api keys APIs * updated README * updated spec from upstream https://github.com/openai/openai-openapi/blob/d033c364c6574068ee89f3d5f845a4830bddd503/openapi.yaml * fix PromptTokensDetails and CompletionTokensDetails * update function-call and function-call-stream examples to use non-deprecated model: gpt-4o-mini * fix moderation types * update moderation example * add missing doc comments * fix: add missing pub modifier
- Loading branch information
Showing
30 changed files
with
9,895 additions
and
5,097 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use serde::Serialize; | ||
|
||
use crate::{config::Config, error::OpenAIError, types::ListAuditLogsResponse, Client}; | ||
|
||
/// Logs of user actions and configuration changes within this organization. | ||
/// To log events, you must activate logging in the [Organization Settings](https://platform.openai.com/settings/organization/general). | ||
/// Once activated, for security reasons, logging cannot be deactivated. | ||
pub struct AuditLogs<'c, C: Config> { | ||
client: &'c Client<C>, | ||
} | ||
|
||
impl<'c, C: Config> AuditLogs<'c, C> { | ||
pub fn new(client: &'c Client<C>) -> Self { | ||
Self { client } | ||
} | ||
|
||
/// List user actions and configuration changes within this organization. | ||
pub async fn get<Q>(&self, query: &Q) -> Result<ListAuditLogsResponse, OpenAIError> | ||
where | ||
Q: Serialize + ?Sized, | ||
{ | ||
self.client | ||
.get_with_query("/organization/audit_logs", query) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use serde::Serialize; | ||
|
||
use crate::{ | ||
config::Config, | ||
error::OpenAIError, | ||
types::{ProjectApiKey, ProjectApiKeyDeleteResponse, ProjectApiKeyListResponse}, | ||
Client, | ||
}; | ||
|
||
/// Manage API keys for a given project. Supports listing and deleting keys for users. | ||
/// This API does not allow issuing keys for users, as users need to authorize themselves to generate keys. | ||
pub struct ProjectAPIKeys<'c, C: Config> { | ||
client: &'c Client<C>, | ||
pub project_id: String, | ||
} | ||
|
||
impl<'c, C: Config> ProjectAPIKeys<'c, C> { | ||
pub fn new(client: &'c Client<C>, project_id: &str) -> Self { | ||
Self { | ||
client, | ||
project_id: project_id.into(), | ||
} | ||
} | ||
|
||
/// Returns a list of API keys in the project. | ||
pub async fn list<Q>(&self, query: &Q) -> Result<ProjectApiKeyListResponse, OpenAIError> | ||
where | ||
Q: Serialize + ?Sized, | ||
{ | ||
self.client | ||
.get_with_query( | ||
format!("/organization/projects/{}/api_keys", self.project_id).as_str(), | ||
query, | ||
) | ||
.await | ||
} | ||
|
||
/// Retrieves an API key in the project. | ||
pub async fn retrieve(&self, api_key: &str) -> Result<ProjectApiKey, OpenAIError> { | ||
self.client | ||
.get( | ||
format!( | ||
"/organization/projects/{}/api_keys/{api_key}", | ||
self.project_id | ||
) | ||
.as_str(), | ||
) | ||
.await | ||
} | ||
|
||
/// Deletes an API key from the project. | ||
pub async fn delete(&self, api_key: &str) -> Result<ProjectApiKeyDeleteResponse, OpenAIError> { | ||
self.client | ||
.delete( | ||
format!( | ||
"/organization/projects/{}/api_keys/{api_key}", | ||
self.project_id | ||
) | ||
.as_str(), | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use serde::Serialize; | ||
|
||
use crate::{ | ||
config::Config, | ||
error::OpenAIError, | ||
types::{ | ||
ProjectServiceAccount, ProjectServiceAccountCreateRequest, | ||
ProjectServiceAccountCreateResponse, ProjectServiceAccountDeleteResponse, | ||
ProjectServiceAccountListResponse, | ||
}, | ||
Client, | ||
}; | ||
|
||
/// Manage service accounts within a project. A service account is a bot user that is not | ||
/// associated with a user. If a user leaves an organization, their keys and membership in projects | ||
/// will no longer work. Service accounts do not have this limitation. | ||
/// However, service accounts can also be deleted from a project. | ||
pub struct ProjectServiceAccounts<'c, C: Config> { | ||
client: &'c Client<C>, | ||
pub project_id: String, | ||
} | ||
|
||
impl<'c, C: Config> ProjectServiceAccounts<'c, C> { | ||
pub fn new(client: &'c Client<C>, project_id: &str) -> Self { | ||
Self { | ||
client, | ||
project_id: project_id.into(), | ||
} | ||
} | ||
|
||
/// Returns a list of service accounts in the project. | ||
pub async fn list<Q>(&self, query: &Q) -> Result<ProjectServiceAccountListResponse, OpenAIError> | ||
where | ||
Q: Serialize + ?Sized, | ||
{ | ||
self.client | ||
.get_with_query( | ||
format!( | ||
"/organization/projects/{}/service_accounts", | ||
self.project_id | ||
) | ||
.as_str(), | ||
query, | ||
) | ||
.await | ||
} | ||
|
||
/// Creates a new service account in the project. This also returns an unredacted API key for the service account. | ||
pub async fn create( | ||
&self, | ||
request: ProjectServiceAccountCreateRequest, | ||
) -> Result<ProjectServiceAccountCreateResponse, OpenAIError> { | ||
self.client | ||
.post( | ||
format!( | ||
"/organization/projects/{}/service_accounts", | ||
self.project_id | ||
) | ||
.as_str(), | ||
request, | ||
) | ||
.await | ||
} | ||
|
||
/// Retrieves a service account in the project. | ||
pub async fn retrieve( | ||
&self, | ||
service_account_id: &str, | ||
) -> Result<ProjectServiceAccount, OpenAIError> { | ||
self.client | ||
.get( | ||
format!( | ||
"/organization/projects/{}/service_accounts/{service_account_id}", | ||
self.project_id | ||
) | ||
.as_str(), | ||
) | ||
.await | ||
} | ||
|
||
/// Deletes a service account from the project. | ||
pub async fn delete( | ||
&self, | ||
service_account_id: &str, | ||
) -> Result<ProjectServiceAccountDeleteResponse, OpenAIError> { | ||
self.client | ||
.delete( | ||
format!( | ||
"/organization/projects/{}/service_accounts/{service_account_id}", | ||
self.project_id | ||
) | ||
.as_str(), | ||
) | ||
.await | ||
} | ||
} |
Oops, something went wrong.