Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include option for automatic retries #44

Open
christophscheuch opened this issue May 24, 2023 · 5 comments
Open

Include option for automatic retries #44

christophscheuch opened this issue May 24, 2023 · 5 comments

Comments

@christophscheuch
Copy link

christophscheuch commented May 24, 2023

As it turns out the OpenAI API frequently returns very unhelpful error messages like this one:

The server had an error while processing your request. Sorry about that!

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 like create_chat_completion().

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?

@olivierISCIII
Copy link

I think these connection problems can be fixed with the insistently function from the purrr package without having to modify the openai package.

@christophscheuch
Copy link
Author

Good suggestion, thanks!

Btw httr::RETRY() is a special case of insistently() for HTTP verbs :)

@irudnyts
Copy link
Owner

@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!

@olyerickson
Copy link

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...

@irudnyts
Copy link
Owner

@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?"))
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants