Skip to content

Commit eb10e6a

Browse files
committed
Merge remote-tracking branch 'origin/main' into spiceai
2 parents aae153d + bd7a87e commit eb10e6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+11721
-4964
lines changed

async-openai/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "async-openai"
3-
version = "0.24.1"
3+
version = "0.26.0"
44
authors = ["Himanshu Neema"]
55
categories = ["api-bindings", "web-programming", "asynchronous"]
66
keywords = ["openai", "async", "openapi", "ai"]
@@ -22,6 +22,7 @@ rustls-webpki-roots = ["reqwest/rustls-tls-webpki-roots"]
2222
native-tls = ["reqwest/native-tls"]
2323
# Remove dependency on OpenSSL
2424
native-tls-vendored = ["reqwest/native-tls-vendored"]
25+
realtime = ["dep:tokio-tungstenite"]
2526

2627
[dependencies]
2728
backoff = { version = "0.4.0", features = ["tokio"] }
@@ -46,6 +47,11 @@ async-convert = "1.0.0"
4647
secrecy = { version = "0.8.0", features = ["serde"] }
4748
bytes = "1.6.0"
4849
eventsource-stream = "0.2.3"
50+
tokio-tungstenite = { version = "0.24.0", optional = true, default-features = false }
4951

5052
[dev-dependencies]
5153
tokio-test = "0.4.4"
54+
55+
[package.metadata.docs.rs]
56+
all-features = true
57+
rustdoc-args = ["--cfg", "docsrs"]

async-openai/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
- [x] Images
3535
- [x] Models
3636
- [x] Moderations
37-
- [ ] Organizations | Administration
38-
- [ ] Uploads
37+
- [x] Organizations | Administration
38+
- [x] Realtime API types (Beta)
39+
- [x] Uploads
3940
- SSE streaming on available APIs
4041
- Requests (except SSE streaming) including form submissions are retried with exponential backoff when [rate limited](https://platform.openai.com/docs/guides/rate-limits).
4142
- Ergonomic builder pattern for all request objects.
@@ -58,6 +59,11 @@ $Env:OPENAI_API_KEY='sk-...'
5859
- Visit [examples](https://github.com/64bit/async-openai/tree/main/examples) directory on how to use `async-openai`.
5960
- Visit [docs.rs/async-openai](https://docs.rs/async-openai) for docs.
6061

62+
## Realtime API
63+
64+
Only types for Realtime API are implemented, and can be enabled with feature flag `realtime`.
65+
These types may change if/when OpenAI releases official specs for them.
66+
6167
## Image Generation Example
6268

6369
```rust

async-openai/src/audit_logs.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use serde::Serialize;
2+
3+
use crate::{config::Config, error::OpenAIError, types::ListAuditLogsResponse, Client};
4+
5+
/// Logs of user actions and configuration changes within this organization.
6+
/// To log events, you must activate logging in the [Organization Settings](https://platform.openai.com/settings/organization/general).
7+
/// Once activated, for security reasons, logging cannot be deactivated.
8+
pub struct AuditLogs<'c, C: Config> {
9+
client: &'c Client<C>,
10+
}
11+
12+
impl<'c, C: Config> AuditLogs<'c, C> {
13+
pub fn new(client: &'c Client<C>) -> Self {
14+
Self { client }
15+
}
16+
17+
/// List user actions and configuration changes within this organization.
18+
pub async fn get<Q>(&self, query: &Q) -> Result<ListAuditLogsResponse, OpenAIError>
19+
where
20+
Q: Serialize + ?Sized,
21+
{
22+
self.client
23+
.get_with_query("/organization/audit_logs", query)
24+
.await
25+
}
26+
}

async-openai/src/client.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use crate::{
1111
file::Files,
1212
image::Images,
1313
moderation::Moderations,
14-
Assistants, Audio, Batches, Chat, Completions, Embeddings, FineTuning, Models, Threads,
15-
VectorStores,
14+
Assistants, Audio, AuditLogs, Batches, Chat, Completions, Embeddings, FineTuning, Invites,
15+
Models, Projects, Threads, Users, VectorStores,
1616
};
1717

1818
#[derive(Debug, Clone, Default)]
@@ -135,6 +135,26 @@ impl<C: Config> Client<C> {
135135
Batches::new(self)
136136
}
137137

138+
/// To call [AuditLogs] group related APIs using this client.
139+
pub fn audit_logs(&self) -> AuditLogs<C> {
140+
AuditLogs::new(self)
141+
}
142+
143+
/// To call [Invites] group related APIs using this client.
144+
pub fn invites(&self) -> Invites<C> {
145+
Invites::new(self)
146+
}
147+
148+
/// To call [Users] group related APIs using this client.
149+
pub fn users(&self) -> Users<C> {
150+
Users::new(self)
151+
}
152+
153+
/// To call [Projects] group related APIs using this client.
154+
pub fn projects(&self) -> Projects<C> {
155+
Projects::new(self)
156+
}
157+
138158
pub fn config(&self) -> &C {
139159
&self.config
140160
}

async-openai/src/invites.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use serde::Serialize;
2+
3+
use crate::{
4+
config::Config,
5+
error::OpenAIError,
6+
types::{Invite, InviteDeleteResponse, InviteListResponse, InviteRequest},
7+
Client,
8+
};
9+
10+
/// Invite and manage invitations for an organization. Invited users are automatically added to the Default project.
11+
pub struct Invites<'c, C: Config> {
12+
client: &'c Client<C>,
13+
}
14+
15+
impl<'c, C: Config> Invites<'c, C> {
16+
pub fn new(client: &'c Client<C>) -> Self {
17+
Self { client }
18+
}
19+
20+
/// Returns a list of invites in the organization.
21+
pub async fn list<Q>(&self, query: &Q) -> Result<InviteListResponse, OpenAIError>
22+
where
23+
Q: Serialize + ?Sized,
24+
{
25+
self.client
26+
.get_with_query("/organization/invites", query)
27+
.await
28+
}
29+
30+
/// Retrieves an invite.
31+
pub async fn retrieve(&self, invite_id: &str) -> Result<Invite, OpenAIError> {
32+
self.client
33+
.get(format!("/organization/invites/{invite_id}").as_str())
34+
.await
35+
}
36+
37+
/// Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization.
38+
pub async fn create(&self, request: InviteRequest) -> Result<Invite, OpenAIError> {
39+
self.client.post("/organization/invites", request).await
40+
}
41+
42+
/// Delete an invite. If the invite has already been accepted, it cannot be deleted.
43+
pub async fn delete(&self, invite_id: &str) -> Result<InviteDeleteResponse, OpenAIError> {
44+
self.client
45+
.delete(format!("/organization/invites/{invite_id}").as_str())
46+
.await
47+
}
48+
}

async-openai/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@
7676
//! ## Examples
7777
//! For full working examples for all supported features see [examples](https://github.com/64bit/async-openai/tree/main/examples) directory in the repository.
7878
//!
79+
#![cfg_attr(docsrs, feature(doc_cfg))]
7980
mod assistant_files;
8081
mod assistants;
8182
mod audio;
83+
mod audit_logs;
8284
mod batches;
8385
mod chat;
8486
mod client;
@@ -90,14 +92,21 @@ pub mod error;
9092
mod file;
9193
mod fine_tuning;
9294
mod image;
95+
mod invites;
9396
mod message_files;
9497
mod messages;
9598
mod model;
9699
mod moderation;
100+
mod project_api_keys;
101+
mod project_service_accounts;
102+
mod project_users;
103+
mod projects;
97104
mod runs;
98105
mod steps;
99106
mod threads;
100107
pub mod types;
108+
mod uploads;
109+
mod users;
101110
mod util;
102111
mod vector_store_file_batches;
103112
mod vector_store_files;
@@ -106,6 +115,7 @@ mod vector_stores;
106115
pub use assistant_files::AssistantFiles;
107116
pub use assistants::Assistants;
108117
pub use audio::Audio;
118+
pub use audit_logs::AuditLogs;
109119
pub use batches::Batches;
110120
pub use chat::Chat;
111121
pub use client::Client;
@@ -114,13 +124,20 @@ pub use embedding::Embeddings;
114124
pub use file::Files;
115125
pub use fine_tuning::FineTuning;
116126
pub use image::Images;
127+
pub use invites::Invites;
117128
pub use message_files::MessageFiles;
118129
pub use messages::Messages;
119130
pub use model::Models;
120131
pub use moderation::Moderations;
132+
pub use project_api_keys::ProjectAPIKeys;
133+
pub use project_service_accounts::ProjectServiceAccounts;
134+
pub use project_users::ProjectUsers;
135+
pub use projects::Projects;
121136
pub use runs::Runs;
122137
pub use steps::Steps;
123138
pub use threads::Threads;
139+
pub use uploads::Uploads;
140+
pub use users::Users;
124141
pub use vector_store_file_batches::VectorStoreFileBatches;
125142
pub use vector_store_files::VectorStoreFiles;
126143
pub use vector_stores::VectorStores;

async-openai/src/moderation.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
Client,
66
};
77

8-
/// Given some input text, outputs if the model classifies it as potentially harmful across several categories.
8+
/// Given text and/or image inputs, classifies if those inputs are potentially harmful across several categories.
99
///
1010
/// Related guide: [Moderations](https://platform.openai.com/docs/guides/moderation)
1111
pub struct Moderations<'c, C: Config> {
@@ -17,7 +17,8 @@ impl<'c, C: Config> Moderations<'c, C> {
1717
Self { client }
1818
}
1919

20-
/// Classifies if text is potentially harmful.
20+
/// Classifies if text and/or image inputs are potentially harmful. Learn
21+
/// more in the [moderation guide](https://platform.openai.com/docs/guides/moderation).
2122
pub async fn create(
2223
&self,
2324
request: CreateModerationRequest,

async-openai/src/project_api_keys.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use serde::Serialize;
2+
3+
use crate::{
4+
config::Config,
5+
error::OpenAIError,
6+
types::{ProjectApiKey, ProjectApiKeyDeleteResponse, ProjectApiKeyListResponse},
7+
Client,
8+
};
9+
10+
/// Manage API keys for a given project. Supports listing and deleting keys for users.
11+
/// This API does not allow issuing keys for users, as users need to authorize themselves to generate keys.
12+
pub struct ProjectAPIKeys<'c, C: Config> {
13+
client: &'c Client<C>,
14+
pub project_id: String,
15+
}
16+
17+
impl<'c, C: Config> ProjectAPIKeys<'c, C> {
18+
pub fn new(client: &'c Client<C>, project_id: &str) -> Self {
19+
Self {
20+
client,
21+
project_id: project_id.into(),
22+
}
23+
}
24+
25+
/// Returns a list of API keys in the project.
26+
pub async fn list<Q>(&self, query: &Q) -> Result<ProjectApiKeyListResponse, OpenAIError>
27+
where
28+
Q: Serialize + ?Sized,
29+
{
30+
self.client
31+
.get_with_query(
32+
format!("/organization/projects/{}/api_keys", self.project_id).as_str(),
33+
query,
34+
)
35+
.await
36+
}
37+
38+
/// Retrieves an API key in the project.
39+
pub async fn retrieve(&self, api_key: &str) -> Result<ProjectApiKey, OpenAIError> {
40+
self.client
41+
.get(
42+
format!(
43+
"/organization/projects/{}/api_keys/{api_key}",
44+
self.project_id
45+
)
46+
.as_str(),
47+
)
48+
.await
49+
}
50+
51+
/// Deletes an API key from the project.
52+
pub async fn delete(&self, api_key: &str) -> Result<ProjectApiKeyDeleteResponse, OpenAIError> {
53+
self.client
54+
.delete(
55+
format!(
56+
"/organization/projects/{}/api_keys/{api_key}",
57+
self.project_id
58+
)
59+
.as_str(),
60+
)
61+
.await
62+
}
63+
}

0 commit comments

Comments
 (0)