async-openai icon indicating copy to clipboard operation
async-openai copied to clipboard

Failing to deserialize API response when translating audio with SRT output

Open fversaci opened this issue 10 months ago • 1 comments

Hi, I'm attempting to translate audio directly into English (API).

When I set the response_format to Json, everything works correctly. However, when setting the response_format to Srt I encounter the following error:

Error: failed to deserialize api response: invalid type: integer `1`, expected struct CreateTranslationResponse at line 1 column 1

Am I doing something wrong?

Thanks!

fversaci avatar Apr 09 '24 10:04 fversaci

Hello,

This sounds like new changes need to be synced for translations APIs as well from the spec. Recently similar was done for transcription APIs in #202

64bit avatar Apr 10 '24 18:04 64bit

I think this may not be an issue any longer with recent release, can you verify please?

64bit avatar Jun 05 '24 00:06 64bit

@64bit I'm afraid it's not fixed yet.

When running client.audio().translate(request).await? I get this error

Error: failed to deserialize api response: invalid type: integer `1`, expected struct CreateTranslationResponseJson at line 1 column 1

whereas, when running client.audio().translate_verbose_json(request).await? I get this one

Error: failed to deserialize api response: invalid type: integer `1`, expected struct CreateTranslationResponseVerboseJson at line 1 column 1

Edit: to clarify, this is the request

let request = CreateTranslationRequestArgs::default()
      .file(pathbuf_to_some_mp3)
      .model("whisper-1")
      .response_format(AudioResponseFormat::Srt)
      .build()?;

fversaci avatar Jun 06 '24 09:06 fversaci

Thank you for checking it again.

SRT response doesn't fit into any predefined types in OpenAI spec, aparently this was solved for transcribe too, same feature is now added for translate API via Audio::translate_raw when you need SRT reponse format

Please see https://github.com/64bit/async-openai/blob/main/examples/audio-translate/src/main.rs#L7

This is included in v0.23.1, hence safe to close this issue now.

64bit avatar Jun 07 '24 23:06 64bit

Perfect, thanks!

fversaci avatar Jun 08 '24 10:06 fversaci