async-openai
async-openai copied to clipboard
Failing to deserialize API response when translating audio with SRT output
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!
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
I think this may not be an issue any longer with recent release, can you verify please?
@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()?;
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.
Perfect, thanks!