Openai error handling for ratelimit, timeout and try again errors(fix #1255) #1361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
With these changes the agent won't stop if a ratelimit error or timeout error or try again error is hit from the openai library, it will try again.
Related Issues
#1255
Solution and Design
The agent will attempt to wait 5 times with an exponential backoff strategy and try again, it will wait for a minimum of 30 seconds and max of 300 seconds.
If after 5 attempts the api call still fails it will return the error.
Test Plan
The code is tested by mocking the api calls to openai and having it return the errors mentioned above and checking if the function has called the api specified number of times and it returns the expected error as a dictionary object.
To reduce the time taken to test, the tencity library's wait_random_exponential function is mocked to only use 0.1 seconds
Type of change
Checklist