Add retry logic for OpenAI API requests#1
Closed
lemillermicrosoft wants to merge 1 commit intomainfrom
Closed
Conversation
dluc
suggested changes
Mar 3, 2023
jansenbe
reviewed
Mar 4, 2023
e8f71ac to
99db183
Compare
4d7ee16 to
ca50027
Compare
c52796c to
807f7d4
Compare
There was a problem hiding this comment.
nit: Retries through a DelegatingHandler would be more elegant solution for the problem because would decouple the code from the retry logic which would make this class a little bit simpler.
Owner
Author
There was a problem hiding this comment.
Yeah, agreed. I think I'll go ahead and take a stab at doing it that way instead for compare/contrast purposes.
Owner
Author
There was a problem hiding this comment.
I've taken a stab at this here: #2
The DelegatingHandler cannot be shared, so this also uses a Factory interface to aid with creation of DelegatingHandler instances.
99b9f79 to
deef524
Compare
… that implement it, allowing the caller to customize the retry logic for HTTP requests to AI services. The commit also modifies the OpenAI and AzureAI clients and services to accept and use the retry policy when making requests. Additionally, the commit adds a cancellation token parameter to the CompleteAsync method of the text completion clients and services, and passes it to the retry policy. The commit also updates the KernelConfig class, the kernel syntax examples, and the samples to use the new interface and classes. Finally, the commit adds unit tests and integration tests for the new functionality, and removes some unused or deprecated code.
deef524 to
cff73ce
Compare
Owner
Author
|
Closing PR. Will be publishing #2 against the main repo. |
dehoward
pushed a commit
that referenced
this pull request
Jun 1, 2023
Add Memory to the list and update diagrams with more recent information.
lemillermicrosoft
pushed a commit
that referenced
this pull request
Nov 13, 2023
…soft#3415) ### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context and Motivation
This PR adds a retry mechanism for OpenAI API requests that encounter throttling or service errors, using the retry-after header if available. This improves the reliability and performance of the OpenAI client, especially when the request volume is high or unpredictable.
Description
The main changes in this PR are:
Contribution Checklist
dotnet format