64bit / async-openai

Rust library for OpenAI
https://docs.rs/async-openai
MIT License
1.09k stars 161 forks source link

Failing to deserialize API response when translating audio with SRT output #212

Closed fversaci closed 2 months ago

fversaci commented 4 months ago

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!

64bit commented 4 months ago

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 commented 2 months ago

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

fversaci commented 2 months ago

@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()?;
64bit commented 2 months ago

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.

fversaci commented 2 months ago

Perfect, thanks!