Skip to content

Commit 42dda26

Browse files
authored
remove async-convert and bump rust-version (#317)
1 parent f6792f3 commit 42dda26

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

async-openai/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ categories = ["api-bindings", "web-programming", "asynchronous"]
66
keywords = ["openai", "async", "openapi", "ai"]
77
description = "Rust library for OpenAI"
88
edition = "2021"
9-
rust-version = "1.65"
9+
rust-version = "1.75"
1010
license = "MIT"
1111
readme = "README.md"
1212
homepage = "https://github.com/64bit/async-openai"
@@ -43,7 +43,6 @@ tokio-stream = "0.1.17"
4343
tokio-util = { version = "0.7.13", features = ["codec", "io-util"] }
4444
tracing = "0.1.41"
4545
derive_builder = "0.20.2"
46-
async-convert = "1.0.0"
4746
secrecy = { version = "0.10.3", features = ["serde"] }
4847
bytes = "1.9.0"
4948
eventsource-stream = "0.2.3"

async-openai/src/client.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::pin::Pin;
22

33
use bytes::Bytes;
44
use futures::{stream::StreamExt, Stream};
5+
use reqwest::multipart::Form;
56
use reqwest_eventsource::{Event, EventSource, RequestBuilderExt};
67
use serde::{de::DeserializeOwned, Serialize};
78

@@ -11,6 +12,7 @@ use crate::{
1112
file::Files,
1213
image::Images,
1314
moderation::Moderations,
15+
util::AsyncTryFrom,
1416
Assistants, Audio, AuditLogs, Batches, Chat, Completions, Embeddings, FineTuning, Invites,
1517
Models, Projects, Threads, Users, VectorStores,
1618
};
@@ -266,7 +268,7 @@ impl<C: Config> Client<C> {
266268
/// POST a form at {path} and return the response body
267269
pub(crate) async fn post_form_raw<F>(&self, path: &str, form: F) -> Result<Bytes, OpenAIError>
268270
where
269-
reqwest::multipart::Form: async_convert::TryFrom<F, Error = OpenAIError>,
271+
Form: AsyncTryFrom<F, Error = OpenAIError>,
270272
F: Clone,
271273
{
272274
let request_maker = || async {
@@ -275,7 +277,7 @@ impl<C: Config> Client<C> {
275277
.post(self.config.url(path))
276278
.query(&self.config.query())
277279
.headers(self.config.headers())
278-
.multipart(async_convert::TryFrom::try_from(form.clone()).await?)
280+
.multipart(<Form as AsyncTryFrom<F>>::try_from(form.clone()).await?)
279281
.build()?)
280282
};
281283

@@ -286,7 +288,7 @@ impl<C: Config> Client<C> {
286288
pub(crate) async fn post_form<O, F>(&self, path: &str, form: F) -> Result<O, OpenAIError>
287289
where
288290
O: DeserializeOwned,
289-
reqwest::multipart::Form: async_convert::TryFrom<F, Error = OpenAIError>,
291+
Form: AsyncTryFrom<F, Error = OpenAIError>,
290292
F: Clone,
291293
{
292294
let request_maker = || async {
@@ -295,7 +297,7 @@ impl<C: Config> Client<C> {
295297
.post(self.config.url(path))
296298
.query(&self.config.query())
297299
.headers(self.config.headers())
298-
.multipart(async_convert::TryFrom::try_from(form.clone()).await?)
300+
.multipart(<Form as AsyncTryFrom<F>>::try_from(form.clone()).await?)
299301
.build()?)
300302
};
301303

async-openai/src/types/impls.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
download::{download_url, save_b64},
88
error::OpenAIError,
99
types::InputSource,
10-
util::{create_all_dir, create_file_part},
10+
util::{create_all_dir, create_file_part, AsyncTryFrom},
1111
};
1212

1313
use bytes::Bytes;
@@ -821,8 +821,7 @@ impl Default for ChatCompletionRequestToolMessageContent {
821821

822822
// start: types to multipart from
823823

824-
#[async_convert::async_trait]
825-
impl async_convert::TryFrom<CreateTranscriptionRequest> for reqwest::multipart::Form {
824+
impl AsyncTryFrom<CreateTranscriptionRequest> for reqwest::multipart::Form {
826825
type Error = OpenAIError;
827826

828827
async fn try_from(request: CreateTranscriptionRequest) -> Result<Self, Self::Error> {
@@ -858,8 +857,7 @@ impl async_convert::TryFrom<CreateTranscriptionRequest> for reqwest::multipart::
858857
}
859858
}
860859

861-
#[async_convert::async_trait]
862-
impl async_convert::TryFrom<CreateTranslationRequest> for reqwest::multipart::Form {
860+
impl AsyncTryFrom<CreateTranslationRequest> for reqwest::multipart::Form {
863861
type Error = OpenAIError;
864862

865863
async fn try_from(request: CreateTranslationRequest) -> Result<Self, Self::Error> {
@@ -884,8 +882,7 @@ impl async_convert::TryFrom<CreateTranslationRequest> for reqwest::multipart::Fo
884882
}
885883
}
886884

887-
#[async_convert::async_trait]
888-
impl async_convert::TryFrom<CreateImageEditRequest> for reqwest::multipart::Form {
885+
impl AsyncTryFrom<CreateImageEditRequest> for reqwest::multipart::Form {
889886
type Error = OpenAIError;
890887

891888
async fn try_from(request: CreateImageEditRequest) -> Result<Self, Self::Error> {
@@ -926,8 +923,7 @@ impl async_convert::TryFrom<CreateImageEditRequest> for reqwest::multipart::Form
926923
}
927924
}
928925

929-
#[async_convert::async_trait]
930-
impl async_convert::TryFrom<CreateImageVariationRequest> for reqwest::multipart::Form {
926+
impl AsyncTryFrom<CreateImageVariationRequest> for reqwest::multipart::Form {
931927
type Error = OpenAIError;
932928

933929
async fn try_from(request: CreateImageVariationRequest) -> Result<Self, Self::Error> {
@@ -961,8 +957,7 @@ impl async_convert::TryFrom<CreateImageVariationRequest> for reqwest::multipart:
961957
}
962958
}
963959

964-
#[async_convert::async_trait]
965-
impl async_convert::TryFrom<CreateFileRequest> for reqwest::multipart::Form {
960+
impl AsyncTryFrom<CreateFileRequest> for reqwest::multipart::Form {
966961
type Error = OpenAIError;
967962

968963
async fn try_from(request: CreateFileRequest) -> Result<Self, Self::Error> {
@@ -974,8 +969,7 @@ impl async_convert::TryFrom<CreateFileRequest> for reqwest::multipart::Form {
974969
}
975970
}
976971

977-
#[async_convert::async_trait]
978-
impl async_convert::TryFrom<AddUploadPartRequest> for reqwest::multipart::Form {
972+
impl AsyncTryFrom<AddUploadPartRequest> for reqwest::multipart::Form {
979973
type Error = OpenAIError;
980974

981975
async fn try_from(request: AddUploadPartRequest) -> Result<Self, Self::Error> {

async-openai/src/util.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ use tokio_util::codec::{BytesCodec, FramedRead};
77
use crate::error::OpenAIError;
88
use crate::types::InputSource;
99

10+
pub(crate) trait AsyncTryFrom<T>: Sized {
11+
/// The type returned in the event of a conversion error.
12+
type Error;
13+
14+
/// Performs the conversion.
15+
async fn try_from(value: T) -> Result<Self, Self::Error>;
16+
}
17+
1018
pub(crate) async fn file_stream_body(source: InputSource) -> Result<Body, OpenAIError> {
1119
let body = match source {
1220
InputSource::Path { path } => {

0 commit comments

Comments
 (0)