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: 4 additions & 0 deletions async-openai/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ native-tls-vendored = ["reqwest/native-tls-vendored"]
realtime = ["dep:tokio-tungstenite"]
# Bring your own types
byot = []
webhook = ["dep:hmac", "dep:sha2", "dep:hex"]

[dependencies]
async-openai-macros = { path = "../async-openai-macros", version = "0.1.0" }
Expand All @@ -50,6 +51,9 @@ secrecy = { version = "0.10.3", features = ["serde"] }
bytes = "1.9.0"
eventsource-stream = "0.2.3"
tokio-tungstenite = { version = "0.26.1", optional = true, default-features = false }
hmac = { version = "0.12", optional = true, default-features = false}
sha2 = { version = "0.10", optional = true, default-features = false }
hex = { version = "0.4", optional = true, default-features = false }

[dev-dependencies]
tokio-test = "0.4.4"
Expand Down
4 changes: 4 additions & 0 deletions async-openai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ $Env:OPENAI_API_KEY='sk-...'

Only types for Realtime API are implemented, and can be enabled with feature flag `realtime`.

## Webhooks

Support for webhook event types, signature verification, and building webhook events from payloads can be enabled by using the `webhook` feature flag.

## Image Generation Example

```rust
Expand Down
1 change: 1 addition & 0 deletions async-openai/src/embedding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl<'c, C: Config> Embeddings<'c, C> {

#[cfg(test)]
mod tests {
use crate::error::OpenAIError;
use crate::types::{CreateEmbeddingResponse, Embedding, EncodingFormat};
use crate::{types::CreateEmbeddingRequestArgs, Client};

Expand Down
2 changes: 2 additions & 0 deletions async-openai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ mod vector_store_file_batches;
mod vector_store_files;
mod vector_stores;
mod video;
#[cfg(feature = "webhook")]
pub mod webhooks;

pub use assistants::Assistants;
pub use audio::Audio;
Expand Down
12 changes: 12 additions & 0 deletions async-openai/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ pub trait AsyncTryFrom<T>: Sized {
/// Performs the conversion.
fn try_from(value: T) -> impl std::future::Future<Output = Result<Self, Self::Error>> + Send;
}

/// Trait for events to get their event type string.
pub trait EventType {
/// Returns the event type string (e.g., "batch.cancelled")
fn event_type(&self) -> &'static str;
}

/// Trait for events to get their event ID.
pub trait EventId {
/// Returns the event ID
fn event_id(&self) -> &str;
}
3 changes: 3 additions & 0 deletions async-openai/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ mod upload;
mod users;
mod vector_store;
mod video;
#[cfg_attr(docsrs, doc(cfg(feature = "webhook")))]
#[cfg(feature = "webhook")]
pub mod webhooks;

pub use assistant::*;
pub use assistant_stream::*;
Expand Down
Loading
Loading