JuliaML/OpenAI.jl

Downloads timeouts - switch to HTTP?

aplavin opened this issue · 8 comments

Downloads.jl has an undocumented and unconfigurable timeout: when no bytes get sent for 20 seconds, the download just fails. For me, openai API does take more than 20 seconds from time to time, and Downloads just throw an exception in those cases.
See JuliaLang/Downloads.jl#168 for details.

Maybe, HTTP.jl is a better fit for OpenAI.jl?

Hacky workaround In the meantime, to disable this timeout, one needs to dig into `Downloads` and run this code:
@eval Downloads.Curl function set_defaults(easy::Easy)
    # curl options
    setopt(easy, CURLOPT_NOSIGNAL, true)
    setopt(easy, CURLOPT_FOLLOWLOCATION, true)
    setopt(easy, CURLOPT_MAXREDIRS, 50)
    setopt(easy, CURLOPT_POSTREDIR, CURL_REDIR_POST_ALL)
    setopt(easy, CURLOPT_USERAGENT, USER_AGENT)
    setopt(easy, CURLOPT_NETRC, CURL_NETRC_OPTIONAL)
    setopt(easy, CURLOPT_COOKIEFILE, "")
    setopt(easy, CURLOPT_SSL_OPTIONS, CURLSSLOPT_REVOKE_BEST_EFFORT)

    # ssh-related options
    setopt(easy, CURLOPT_SSH_PRIVATE_KEYFILE, ssh_key_path())
    setopt(easy, CURLOPT_SSH_PUBLIC_KEYFILE, ssh_pub_key_path())
    key_pass = something(ssh_key_pass(), C_NULL)
    setopt(easy, CURLOPT_KEYPASSWD, key_pass)
end

It's the same as default in Downloads, just with timeout removed.

Well we had a contributor who switched to Downloads here: #9

I didn't foresee this outcome, which is unfortunate. I think this is definitely more than enough justification to switch back. I can work on this over the weekend if nobody else implements before I do.

Moelf commented

time out is very bad indeed, esp. for gpt-4

@algunion removed Downloads.jl here: #25

aviks commented

@algunion removed Downloads.jl here: #25

Ah, I'm sad to see that, I liked having low dependencies for this package -- helps with dependency resolution in large manifests.

Anyways, the global timeout could have been configured quite easily with a custom Downloader

downloader = Downloads.Downloader()
downloader.easy_hook = (easy, info) -> Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_LOW_SPEED_TIME, 0)

@algunion removed Downloads.jl here: #25

Ah, I'm sad to see that, I liked having low dependencies for this package -- helps with dependency resolution in large manifests.

Anyways, the global timeout could have been configured quite easily with a custom Downloader

downloader = Downloads.Downloader()
downloader.easy_hook = (easy, info) -> Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_LOW_SPEED_TIME, 0)

It is trivial to be reverted if there are clear benefits.

Given the (current) stability of HTTP.jl, I don't see it as a real dependency issue - besides, people are likely using HTTP.jl anyway when working with OpenAI-related stuff.

We can definitely add an option to set or disable the timeout.

We can definitely add an option to set or disable the timeout.

In the current version, both connect_timeout and readtimeout can be passed to all models.

They will be handled by HTTP.jl as described here.

I think this issue can be closed, unless anybody feels otherwise