dvcrn / ex_openai

Auto-generated Elixir SDK for OpenAI APIs with full typespecs, docs and streaming support
MIT License
71 stars 27 forks source link

ExOpenAI.Audio.create_speech tries to parse response as JSON when it is the raw MP3 string #19

Closed hawkyre closed 3 months ago

hawkyre commented 5 months ago

I'm getting this error because the library is trying to parse the response as a JSON when it's just the raw binary in string format.

Here's the error:

no case clause matching: {:ok, %HTTPoison.Response{status_code: 200, body: {:error, %Jason.DecodeError{position: 0, token: nil, data: <<255, 243, 228, 196, 0, 91, 100, 57, 232, 21, 90, 192, 0, 105, 255, 83, 205, 128, 236, 76, 55, 204, 13, 17, 96, 49, 6, 244, 26, 36, 206, 179, 57, 51, 79, 183, 35, 229, 184, 243, 94, ...>>}}, headers: [{"Date", "Sat, 10 Feb 2024 16:37:49 GMT"}, {"Content-Type", "audio/mpeg"}, {"Transfer-Encoding", "chunked"}, {"Connection", "keep-alive"}, {"openai-organization", "user-wrp869fi21tfiba2c6pbgtzk"}, {"openai-processing-ms", "360"}, {"openai-version", "2020-10-01"}, {"strict-transport-security", "max-age=15724800; includeSubDomains"}, {"x-ratelimit-limit-requests", "100"}, {"x-ratelimit-remaining-requests", "99"}, {"x-ratelimit-reset-requests", "600ms"}, {"x-request-id", "req_2bea2f766ab224baaabfd670b08a848b"}, {"CF-Cache-Status", "DYNAMIC"}, {"Set-Cookie", "__cf_bm=c8hZghGTexxu3aBBeC3VLcn.WvGjFtOuXf6vVL41cxk-1707583069-1-AZXuK2wvaT6R5ez3gM6UNEZSOsLc0eET5P7hCfrwGz7y0mzBishNY9UV9vRFJSQUDfd4HEG+MzeEszFDo28H9k0=; path=/; expires=Sat, 10-Feb-24 17:07:49 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None"}, {"Set-Cookie", "_cfuvid=DVhy6UAnPoUha56tErBCRatIWg8.QnVt37EerIA6yh8-1707583069884-0-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None"}, {"Server", "cloudflare"}, {"CF-RAY", "8535c7652fa38680-MAD"}, {"alt-svc", "h3=\":443\"; ma=86400"}], request_url: "https://api.openai.com/v1/audio/speech?", request: %HTTPoison.Request{method: :post, url: "https://api.openai.com/v1/audio/speech?", headers: [{"Authorization", "Bearer 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"}, {"Content-type", "application/json"}], body: "{\"input\":\"weekend\",\"voice\":\"alloy\",\"model\":\"tts-1\"}", params: %{}, options: [recv_timeout: 50000, stream_to: nil]}}}
    (ex_openai 1.5.0) lib/ex_openai/client.ex:11: ExOpenAI.Client.handle_response/1
    (ex_openai 1.5.0) lib/ex_openai/client.ex:126: ExOpenAI.Client.api_post/4
dvcrn commented 5 months ago

There’s a open PR for this, but couldn’t merge it yet because CI breaks - https://github.com/dvcrn/ex_openai/pull/18 Let me see if I can get it done this weekend!

dvcrn commented 5 months ago

Could you give this branch a go? https://github.com/dvcrn/ex_openai/pull/20

dvcrn commented 3 months ago

Released in https://github.com/dvcrn/ex_openai/releases/tag/1.5.1