@@ -211,6 +211,13 @@ impl OpenAIClient {
211
211
self . handle_response ( response) . await
212
212
}
213
213
214
+ async fn post_form_raw ( & self , path : & str , form : Form ) -> Result < Bytes , APIError > {
215
+ let request = self . build_request ( Method :: POST , path) . await ;
216
+ let request = request. multipart ( form) ;
217
+ let response = request. send ( ) . await ?;
218
+ Ok ( response. bytes ( ) . await ?)
219
+ }
220
+
214
221
async fn handle_response < T : serde:: de:: DeserializeOwned > (
215
222
& self ,
216
223
response : Response ,
@@ -303,10 +310,34 @@ impl OpenAIClient {
303
310
& self ,
304
311
req : AudioTranscriptionRequest ,
305
312
) -> Result < AudioTranscriptionResponse , APIError > {
313
+ // https://platform.openai.com/docs/api-reference/audio/createTranslation#audio-createtranslation-response_format
314
+ if let Some ( response_format) = & req. response_format {
315
+ if response_format != "json" && response_format != "verbose_json" {
316
+ return Err ( APIError :: CustomError {
317
+ message : "response_format must be either 'json' or 'verbose_json' please use audio_transcription_raw" . to_string ( ) ,
318
+ } ) ;
319
+ }
320
+ }
306
321
let form = Self :: create_form ( & req, "file" ) ?;
307
322
self . post_form ( "audio/transcriptions" , form) . await
308
323
}
309
324
325
+ pub async fn audio_transcription_raw (
326
+ & self ,
327
+ req : AudioTranscriptionRequest ,
328
+ ) -> Result < Bytes , APIError > {
329
+ // https://platform.openai.com/docs/api-reference/audio/createTranslation#audio-createtranslation-response_format
330
+ if let Some ( response_format) = & req. response_format {
331
+ if response_format != "text" && response_format != "srt" && response_format != "vtt" {
332
+ return Err ( APIError :: CustomError {
333
+ message : "response_format must be either 'text', 'srt' or 'vtt', please use audio_transcription" . to_string ( ) ,
334
+ } ) ;
335
+ }
336
+ }
337
+ let form = Self :: create_form ( & req, "file" ) ?;
338
+ self . post_form_raw ( "audio/transcriptions" , form) . await
339
+ }
340
+
310
341
pub async fn audio_translation (
311
342
& self ,
312
343
req : AudioTranslationRequest ,
0 commit comments