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

added retry when sending httpx request to LLM provider apis #20

Merged
merged 11 commits into from
Aug 30, 2024

Conversation

lifeizhou-ap
Copy link
Collaborator

@lifeizhou-ap lifeizhou-ap commented Aug 30, 2024

Why
Implement retry when request to LLM provider API returns certain response code. Currently it is implemented in the anthropic provider. we would like to enable retry for other providers

What

  • Created retry_with_backoff decorator. This is a generic decorator
  • Created retry_httpx_request decorator which is specific for sending httpx request to the LLM provider api. It can specify the response status codes which requires retry. The retry logic is built based on anthropic provider
  • Applied the retry_httpx_request to all the providers with default behaviours

Note/Todo

  • I was not involved in the initial discussion. So I created two decorators that people can choose. Personally I think retry_httpx_request is sufficient for our use cases. If retry_with_backoff is not required, please delete it

  • I've applied the retry_httpx_request to all the providers in this project with default values. You may add the customised parameter value on the decorator if the default value does not suit for some providers.

@lifeizhou-ap lifeizhou-ap marked this pull request as ready for review August 30, 2024 07:35
@lifeizhou-ap lifeizhou-ap changed the title added retry_with_backoff decorator added retry when sending httpx request to LLM provider apis Aug 30, 2024
Copy link
Collaborator

@michaelneale michaelneale left a comment

Choose a reason for hiding this comment

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

I like this a lot - would like some other eyes on this very sensitive part of the code.

Copy link
Collaborator

@lukealvoeiro lukealvoeiro left a comment

Choose a reason for hiding this comment

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

LGTM, pending one nit.

src/exchange/providers/anthropic.py Show resolved Hide resolved
src/exchange/providers/retry_with_back_off_decorator.py Outdated Show resolved Hide resolved
src/exchange/providers/retry_with_back_off_decorator.py Outdated Show resolved Hide resolved
@andrewblane andrewblane merged commit ed3a6ab into main Aug 30, 2024
3 checks passed
lukealvoeiro added a commit that referenced this pull request Sep 2, 2024
lukealvoeiro added a commit that referenced this pull request Sep 2, 2024
* main:
  fix typos found by PyCharm (#21)
  added retry when sending httpx request to LLM provider apis (#20)
  chore: version bump to `0.8.2` (#19)
  fix: don't always use ollama provider (#18)
  fix: export `metadata.plugins` export should have a valid value (#17)
  Create an entry-point for `ai-exchange` (#16)
  chore: Run tests for python  >=3.10 (#14)
  Update pypi_release.yaml (#13)
  ollama provider (#7)
  chore: gitignore generated lockfile (#8)
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

Successfully merging this pull request may close these issues.

6 participants