@@ -132,15 +132,17 @@ impl Default for InputSource {
132
132
macro_rules! impl_input {
133
133
( $for_typ: ty) => {
134
134
impl $for_typ {
135
- pub fn from_bytes( filename: String , bytes: Bytes ) -> Self {
135
+ pub fn from_bytes( filename: String , bytes: Bytes , mime_type : String ) -> Self {
136
136
Self {
137
137
source: InputSource :: Bytes { filename, bytes } ,
138
+ mime_type,
138
139
}
139
140
}
140
141
141
- pub fn from_vec_u8( filename: String , vec: Vec <u8 >) -> Self {
142
+ pub fn from_vec_u8( filename: String , vec: Vec <u8 >, mime_type : String ) -> Self {
142
143
Self {
143
144
source: InputSource :: VecU8 { filename, vec } ,
145
+ mime_type,
144
146
}
145
147
}
146
148
}
@@ -150,6 +152,7 @@ macro_rules! impl_input {
150
152
let path_buf = path. as_ref( ) . to_path_buf( ) ;
151
153
Self {
152
154
source: InputSource :: Path { path: path_buf } ,
155
+ mime_type: "application/octet-stream" . to_string( ) ,
153
156
}
154
157
}
155
158
}
@@ -832,7 +835,7 @@ impl AsyncTryFrom<CreateTranscriptionRequest> for reqwest::multipart::Form {
832
835
type Error = OpenAIError ;
833
836
834
837
async fn try_from ( request : CreateTranscriptionRequest ) -> Result < Self , Self :: Error > {
835
- let audio_part = create_file_part ( request. file . source ) . await ?;
838
+ let audio_part = create_file_part ( request. file . source , request . file . mime_type ) . await ?;
836
839
837
840
let mut form = reqwest:: multipart:: Form :: new ( )
838
841
. part ( "file" , audio_part)
@@ -868,7 +871,7 @@ impl AsyncTryFrom<CreateTranslationRequest> for reqwest::multipart::Form {
868
871
type Error = OpenAIError ;
869
872
870
873
async fn try_from ( request : CreateTranslationRequest ) -> Result < Self , Self :: Error > {
871
- let audio_part = create_file_part ( request. file . source ) . await ?;
874
+ let audio_part = create_file_part ( request. file . source , request . file . mime_type ) . await ?;
872
875
873
876
let mut form = reqwest:: multipart:: Form :: new ( )
874
877
. part ( "file" , audio_part)
@@ -897,12 +900,12 @@ impl AsyncTryFrom<CreateImageEditRequest> for reqwest::multipart::Form {
897
900
. text ( "prompt" , request. prompt ) ;
898
901
899
902
for image in request. image {
900
- let image_part = create_file_part ( image. source ) . await ?;
903
+ let image_part = create_file_part ( image. source , image . mime_type ) . await ?;
901
904
form = form. part ( "image[]" , image_part) ;
902
905
}
903
906
904
907
if let Some ( mask) = request. mask {
905
- let mask_part = create_file_part ( mask. source ) . await ?;
908
+ let mask_part = create_file_part ( mask. source , mask . mime_type ) . await ?;
906
909
form = form. part ( "mask" , mask_part) ;
907
910
}
908
911
@@ -936,7 +939,7 @@ impl AsyncTryFrom<CreateImageVariationRequest> for reqwest::multipart::Form {
936
939
type Error = OpenAIError ;
937
940
938
941
async fn try_from ( request : CreateImageVariationRequest ) -> Result < Self , Self :: Error > {
939
- let image_part = create_file_part ( request. image . source ) . await ?;
942
+ let image_part = create_file_part ( request. image . source , request . image . mime_type ) . await ?;
940
943
941
944
let mut form = reqwest:: multipart:: Form :: new ( ) . part ( "image" , image_part) ;
942
945
@@ -970,7 +973,7 @@ impl AsyncTryFrom<CreateFileRequest> for reqwest::multipart::Form {
970
973
type Error = OpenAIError ;
971
974
972
975
async fn try_from ( request : CreateFileRequest ) -> Result < Self , Self :: Error > {
973
- let file_part = create_file_part ( request. file . source ) . await ?;
976
+ let file_part = create_file_part ( request. file . source , request . file . mime_type ) . await ?;
974
977
let form = reqwest:: multipart:: Form :: new ( )
975
978
. part ( "file" , file_part)
976
979
. text ( "purpose" , request. purpose . to_string ( ) ) ;
@@ -982,7 +985,7 @@ impl AsyncTryFrom<AddUploadPartRequest> for reqwest::multipart::Form {
982
985
type Error = OpenAIError ;
983
986
984
987
async fn try_from ( request : AddUploadPartRequest ) -> Result < Self , Self :: Error > {
985
- let file_part = create_file_part ( request. data ) . await ?;
988
+ let file_part = create_file_part ( request. data , request . mime_type ) . await ?;
986
989
let form = reqwest:: multipart:: Form :: new ( ) . part ( "data" , file_part) ;
987
990
Ok ( form)
988
991
}
0 commit comments