client
client copied to clipboard
Add Timeout Param
The official Python library allows a timeout to be set on requests. It would be really helpful for production applications to be able to set up a timeout on requests so we don't keep our web workers hanging if there is hiccups in connections or issues on the OpenAI side.
Can you make a pull request adding that feature?
Hmmm, it doesn't even look like the PSR7 lib that is used here to make HTTP calls supports timeouts at all if I'm looking through their code correctly? Would potentially require a wrapper around the requests to handle this since it's not supported native.
Might it be possible to use one of these options?
- https://docs.guzzlephp.org/en/latest/request-options.html#connect-timeout
- https://docs.guzzlephp.org/en/latest/request-options.html#timeout
Afterall a Guzzle Client is being used by the OpenAI Class
This can now be achieved by using the newly introduced factory:
$client = OpenAI::factory()
->withHttpClient(new \GuzzleHttp\Client(['timeout' => 2.0]))
->make();