Skip to content

Commit 9370378

Browse files
committed
fix issues due to cherry-pick
1 parent 8eaef1c commit 9370378

40 files changed

+70
-137
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ default-members = ["async-openai-wasm", "async-openai-*"]
55
resolver = "2"
66

77
[workspace.package]
8-
rust-version = "1.75"
8+
rust-version = "1.85"

async-openai-macros/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ struct BoundArgs {
1313
bounds: Vec<(String, syn::TypeParamBound)>,
1414
where_clause: Option<String>,
1515
stream: bool, // Add stream flag
16+
use_mapped_events: bool,
1617
}
1718

1819
impl Parse for BoundArgs {
1920
fn parse(input: ParseStream) -> syn::Result<Self> {
2021
let mut bounds = Vec::new();
2122
let mut where_clause = None;
2223
let mut stream = false; // Default to false
24+
let mut use_mapped_events = false; // Default to false
2325
let vars = Punctuated::<syn::MetaNameValue, Comma>::parse_terminated(input)?;
2426

2527
for var in vars {
@@ -31,6 +33,9 @@ impl Parse for BoundArgs {
3133
"stream" => {
3234
stream = var.value.into_token_stream().to_string().contains("true");
3335
}
36+
"use_mapped_events" => {
37+
use_mapped_events = var.value.into_token_stream().to_string().contains("true");
38+
}
3439
_ => {
3540
let bound: syn::TypeParamBound =
3641
syn::parse_str(&var.value.into_token_stream().to_string())?;
@@ -42,6 +47,7 @@ impl Parse for BoundArgs {
4247
bounds,
4348
where_clause,
4449
stream,
50+
use_mapped_events,
4551
})
4652
}
4753
}
@@ -124,7 +130,11 @@ pub fn byot(args: TokenStream, item: TokenStream) -> TokenStream {
124130

125131
// Generate return type based on stream flag
126132
let return_type = if bounds_args.stream {
127-
quote! { Result<::std::pin::Pin<Box<dyn ::futures::Stream<Item = Result<R, OpenAIError>> + Send>>, OpenAIError> }
133+
if bounds_args.use_mapped_events {
134+
quote! { Result<crate::client::OpenAIEventMappedStream<R>, OpenAIError> }
135+
} else {
136+
quote! { Result<crate::client::OpenAIEventStream<R>, OpenAIError> }
137+
}
128138
} else {
129139
quote! { Result<R, OpenAIError> }
130140
};

async-openai-wasm/Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "async-openai-wasm"
3-
version = "0.27.4"
3+
version = "0.28.0"
44
authors = [
55
"Contributors of the async-openai crate",
66
"ifsheldon <async_openai_wasm@reify.ing>"
@@ -9,7 +9,7 @@ categories = ["api-bindings", "web-programming", "asynchronous"]
99
keywords = ["openai", "async", "openapi", "ai", "wasm"]
1010
description = "Rust library for OpenAI on WASM"
1111
edition = "2024"
12-
rust-version = "1.85"
12+
rust-version = {workspace = true}
1313
license = "MIT"
1414
readme = "README.md"
1515
homepage = "https://github.com/ifsheldon/async-openai-wasm"
@@ -26,8 +26,10 @@ native-tls = ["reqwest/native-tls"]
2626
# Remove dependency on OpenSSL
2727
native-tls-vendored = ["reqwest/native-tls-vendored"]
2828
realtime = []
29+
byot = []
2930

3031
[dependencies]
32+
async-openai-macros = { path = "../async-openai-macros", version = "0.1.0" }
3133
base64 = "0.22"
3234
futures = "0.3"
3335
reqwest = { version = "0.12", features = ["json", "stream", "multipart"], default-features = false }
@@ -50,6 +52,11 @@ getrandom = { version = "0.2", features = ["js"] }
5052
[dev-dependencies]
5153
tokio-test = "0.4"
5254
tokio = { version = "1.43", features = ["fs", "macros"] }
55+
serde_json = "1.0"
56+
57+
[[test]]
58+
name = "bring-your-own-type"
59+
required-features = ["byot"]
5360

5461
[package.metadata.docs.rs]
5562
all-features = true

async-openai-wasm/src/assistants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use serde::Serialize;
22

33
use crate::{
4+
Client,
45
config::Config,
56
error::OpenAIError,
67
types::{
78
AssistantObject, CreateAssistantRequest, DeleteAssistantResponse, ListAssistantsResponse,
89
ModifyAssistantRequest,
910
},
10-
Client,
1111
};
1212

1313
/// Build assistants that can call models and use tools to perform tasks.

async-openai-wasm/src/audio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use bytes::Bytes;
22

33
use crate::{
4+
Client,
45
config::Config,
56
error::OpenAIError,
67
types::{
@@ -9,7 +10,6 @@ use crate::{
910
CreateTranslationRequest, CreateTranslationResponseJson,
1011
CreateTranslationResponseVerboseJson,
1112
},
12-
Client,
1313
};
1414

1515
/// Turn audio into text or text into audio.

async-openai-wasm/src/audit_logs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::Serialize;
22

3-
use crate::{config::Config, error::OpenAIError, types::ListAuditLogsResponse, Client};
3+
use crate::{Client, config::Config, error::OpenAIError, types::ListAuditLogsResponse};
44

55
/// Logs of user actions and configuration changes within this organization.
66
/// To log events, you must activate logging in the [Organization Settings](https://platform.openai.com/settings/organization/general).

async-openai-wasm/src/batches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use serde::Serialize;
22

33
use crate::{
4+
Client,
45
config::Config,
56
error::OpenAIError,
67
types::{Batch, BatchRequest, ListBatchesResponse},
7-
Client,
88
};
99

1010
/// Create large batches of API requests for asynchronous processing. The Batch API returns completions within 24 hours for a 50% discount.

async-openai-wasm/src/chat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::{
2+
Client,
23
config::Config,
34
error::OpenAIError,
45
types::{
56
ChatCompletionResponseStream, CreateChatCompletionRequest, CreateChatCompletionResponse,
67
},
7-
Client,
88
};
99

1010
/// Given a list of messages comprising a conversation, the model will return a response.

async-openai-wasm/src/client.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,21 @@ use std::task::{Context, Poll};
55

66
use bytes::Bytes;
77
use futures::stream::Filter;
8-
use futures::{stream::StreamExt, Stream};
8+
use futures::{Stream, stream::StreamExt};
99
use pin_project::pin_project;
1010
use reqwest::multipart::Form;
1111
use reqwest_eventsource::{Event, EventSource, RequestBuilderExt};
12-
use serde::{de::DeserializeOwned, Serialize};
12+
use serde::{Serialize, de::DeserializeOwned};
1313

14-
use crate::util::async_convert::AsyncTryFrom;
1514
use crate::{
15+
Assistants, Audio, AuditLogs, Batches, Chat, Completions, Embeddings, FineTuning, Invites,
16+
Models, Projects, Threads, Uploads, Users, VectorStores,
1617
config::{Config, OpenAIConfig},
17-
error::{map_deserialization_error, OpenAIError, WrappedError},
18+
error::{OpenAIError, WrappedError, map_deserialization_error},
1819
file::Files,
1920
image::Images,
2021
moderation::Moderations,
2122
traits::AsyncTryFrom,
22-
Assistants, Audio, AuditLogs, Batches, Chat, Completions, Embeddings, FineTuning, Invites,
23-
Models, Projects, Threads, Uploads, Users, VectorStores,
2423
};
2524

2625
#[derive(Debug, Clone)]

async-openai-wasm/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Client configurations: [OpenAIConfig] for OpenAI, [AzureConfig] for Azure OpenAI Service.
2-
use reqwest::header::{HeaderMap, AUTHORIZATION};
2+
use reqwest::header::{AUTHORIZATION, HeaderMap};
33
use secrecy::{ExposeSecret, SecretString};
44
use serde::Deserialize;
55

0 commit comments

Comments
 (0)