Skip to content

Audio transcription API fails with non-json response_format field in request #133

Closed
@RulerOfCakes

Description

@RulerOfCakes

Describe the bug

The OpenAIClient::audio_transcription(&self, req:AudioTranscriptionRequest) method takes in a request of structure:

#[derive(Debug, Serialize, Clone)]
pub struct AudioTranscriptionRequest {
    pub file: String,
    pub model: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prompt: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub response_format: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub temperature: Option<f32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
}

where response_format seems to be directly mapped to the response_format API argument described in OpenAI's documentation. However, when it is given a non-json argument, text in my case, the method fails to parse the response while attempting to deserialize it from an assumed json format, giving an error.

To Reproduce

  1. Create an AudioTranscriptionRequest with its response_format field set to Some("text".to_string()).
  2. Use it to call OpenAIClient::audio_transcription(&self, req:AudioTranscriptionRequest).
  3. Observe that the returned result is always a parsing error.

Code snippets

let request = AudioTranscriptionRequest {
    file: tmp_path.to_string_lossy().to_string(), // arbitrary file path
    model: "whisper-1".to_string(),
    prompt: None,
    response_format: Some("text".to_string()),
    temperature: None,
    language: Some("ko".to_string()),
};
let resp = openai.audio_transcription(request).await;

OS

Windows 10(Ubuntu 22.04 WSL2), Also tested on MacOS 15.1.1

Rust version

Rust v1.83.0

Library version

openai-api-rs v5.2.3

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions