Open christophscheuch opened 1 year ago
I think these connection problems can be fixed with the insistently
function from the purrr
package without having to modify the openai
package.
Good suggestion, thanks!
Btw httr::RETRY()
is a special case of insistently()
for HTTP verbs :)
@christophscheuch
I think some parameter like max_retries could be really useful to handle such transient errors that arise while applying functions like create_chat_completion().
I am trying to be as close as possible to the original Python package and not introduce new parameters :) But maybe I will change my mind at some point.
The httr2 package provides the very useful req_retry() function that allows to define the maximum number of retries, which errors are transient, and how long to wait between retries. Is there any specific reason that you sticked httr for the openai package?
No good reason at all. It just seemed a natural candidate, and tbh, I did not even know that httr2 exist.
@olivierISCIII Thanks for the suggestion!
I've very interested in this as well, as we (and everyone else) are seeing the openai.error.RateLimitError
much more frequently over the past week or so...
@christophscheuch @olyerickson @olivierISCIII Hadley rolled out stable version 1.0.0 of {httr2}
, and from now on, I think it finally makes sense to use it.
Here is the new argument for max_retries
, as in the official OpenAI's Python package:
remotes::install_github("irudnyts/openai", ref = "r6")
library(openai)
client <- OpenAI(max_retries = 3) # XXX: here we go!
completion <- client$chat$completions$create(
model = "gpt-3.5-turbo",
messages = list(list("role" = "user", "content" = "What's up?"))
)
As it turns out the OpenAI API frequently returns very unhelpful error messages like this one:
There are also several threads on this issue, for instance in the OpenAI Develper forum.
I think some parameter like
max_retries
could be really useful to handle such transient errors that arise while applying functions likecreate_chat_completion()
.The
httr2
package provides the very usefulreq_retry()
function that allows to define the maximum number of retries, which errors are transient, and how long to wait between retries. Is there any specific reason that you stickedhttr
for theopenai
package?