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

Add retry mechanism for openai API calls #129

Merged
merged 4 commits into from
Jun 22, 2023

Conversation

harshkumarchourasia
Copy link

@harshkumarchourasia harshkumarchourasia commented Jun 4, 2023

Add retrying mechanism for openai api calls.

Sample use cases

  1. complete = models.text_completion.openai("text-davinci-003", **{"wait_exponential_multiplier":1000, "wait_exponential_max":10000, "stop_max_attempt_number":5})
  2. complete = models.text_completion.openai("text-davinci-003", **{"wait_random_min":1000, "wait_random_max":10000, "stop_max_attempt_number":5})

Closes #115

Copy link
Contributor

@brandonwillard brandonwillard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to set up pre-commit locally. Also, retrying needs to be added to the dependencies in pyproject.toml.

@brandonwillard brandonwillard linked an issue Jun 4, 2023 that may be closed by this pull request
@arunpatro
Copy link
Contributor

arunpatro commented Jun 5, 2023

I would advise using https://pypi.org/project/backoff/ instead of retying. Backoff seems to have more stars, and I have seen multiple people using it like the official tree-of-thoughts too

See: https://github.com/ysymyth/tree-of-thought-llm/blob/9f0f986dc30604b83f8d07203cf09b745ada36aa/models.py#L18

@brandonwillard
Copy link
Contributor

I would advise using https://pypi.org/project/backoff/ instead of retying. Backoff seems to have more stars, and I have seen multiple people using it like the official tree-of-thoughts too

See: https://github.com/ysymyth/tree-of-thought-llm/blob/9f0f986dc30604b83f8d07203cf09b745ada36aa/models.py#L18

Is there a technical/functional/support reason one of these libraries should be used over the other?

@arunpatro
Copy link
Contributor

Nothing too technical as of my current knowledge. Just some thoughts based on seeing various implementations of retrying. I found another simple and intuitive library - https://github.com/invl/retry (600 stars). One reason to prefer this one or backoff (2000 stars) is that retrying has only 29 stars.

I feel using backoff or retry can create a more intuitive api extension, I can also try creating a PR to compare.

@brandonwillard
Copy link
Contributor

Nothing too technical as of my current knowledge. Just some thoughts based on seeing various implementations of retrying. I found another simple and intuitive library - https://github.com/invl/retry (600 stars). One reason to prefer this one or backoff (2000 stars) is that retrying has only 29 stars.

I feel using backoff or retry can create a more intuitive api extension, I can also try creating a PR to compare.

Assuming stars as a proxy for something like quality or maturity of the libraries, and that the changes are trivial, they might as well be made here.

@rlouf
Copy link
Member

rlouf commented Jun 5, 2023

I've always thought tenacity (a fork of retrying) was the de facto standard for this, and it seems to be very similar to backoff. If there is a technical reason to prefer backoff, let's use that. Otherwise we can stick with tenacity.

@rlouf rlouf changed the title Retrying mechanism added for openai api calls Add retrying mechanism for openai API calls Jun 6, 2023
@rlouf rlouf changed the title Add retrying mechanism for openai API calls Add retry mechanism for openai API calls Jun 6, 2023
@rlouf rlouf added text Linked to text generation enhancement openai labels Jun 6, 2023
@rlouf
Copy link
Member

rlouf commented Jun 7, 2023

I rebased the changes, modified the code to use tenacity and fixed a few bugs I noticed while making the changes. This is ready for review.

I used the parameters found in this file in the openai-python repo.

@rlouf rlouf requested a review from brandonwillard June 7, 2023 09:07
@rlouf rlouf merged commit 7901224 into outlines-dev:main Jun 22, 2023
3 checks passed
@harshkumarchourasia harshkumarchourasia deleted the add-retry-mechanism branch June 22, 2023 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement text Linked to text generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add retry mechanism for OpenAI API calls
5 participants