Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
RulerOfCakes opened this issue Dec 14, 2024 · 1 comment · Fixed by #134
Closed

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

RulerOfCakes opened this issue Dec 14, 2024 · 1 comment · Fixed by #134
Assignees
Labels
bug Something isn't working

Comments

@RulerOfCakes
Copy link

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

@RulerOfCakes RulerOfCakes added the bug Something isn't working label Dec 14, 2024
@dongri
Copy link
Owner

dongri commented Dec 15, 2024

@RulerOfCakes Thank you for report bug
Fixed PR: #134
Please use v5.2.4

sample code
https://github.com/dongri/openai-api-rs/blob/main/examples/audio_transcriptions.rs#L20-L23

let result = client.audio_transcription_raw(req_raw).await?;

@dongri dongri self-assigned this Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants