-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Azure OpenAI updates #46103
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
Merged
Merged
Azure OpenAI updates #46103
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
be65064
Update OpenAI.TestFramework for Sytem.ClientModel version 1.1.0
e57c141
Update OpenAI.TestFramework code
dbb3312
Update all code use to GA System.ClientModel 1.1.0 (#266)
ralph-msft 008b7e6
Update Azure OpenAI code
2444e25
Update Azure OpenAI test code
28f26b2
Revert change
841249b
Merge remote-tracking branch 'origin/main' into ralphe/scm_1_1_0_update
6a36d61
Fix anaylyze build failures
8170ca3
Try to work around build failure
2e57463
Remove files accidentally added to wrong folder
5cedc45
Address PR feedback
d3e27a6
Address spell checker issues + update for newer System.Text.Json version
0738882
More spell checker fixes
f722a01
Update tests since typo was corrected.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
|
|
||
| namespace Azure.AI.OpenAI.Utility; | ||
|
|
||
| /// <summary> | ||
| /// Represents a collection of values returned from an asynchronous Azure cloud service operation. | ||
| /// </summary> | ||
| /// <typeparam name="TItem">The type of items in the collection.</typeparam> | ||
| /// <typeparam name="TContinuation">Type of the continuation token.</typeparam> | ||
| internal class AzureAsyncCollectionResult<TItem, TContinuation> : AsyncCollectionResult<TItem> where TContinuation : ContinuationToken | ||
| { | ||
| private readonly ClientPipeline _pipeline; | ||
| private readonly RequestOptions _options; | ||
| private readonly Func<TContinuation?, PipelineMessage> _createRequest; | ||
| private readonly Func<ClientResult, TContinuation?> _getContinuationToken; | ||
| private readonly Func<ClientResult, IEnumerable<TItem>> _getValues; | ||
| private readonly CancellationToken _cancellation; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance. | ||
| /// </summary> | ||
| /// <param name="pipeline">The client pipeline to use to send requests.</param> | ||
| /// <param name="options">The request options to use.</param> | ||
| /// <param name="createRequest">The function used to create the request to get a page of results. The continuation token | ||
| /// may be set to null to get the first page. After that it will be set to a value used to get the next page of results.</param> | ||
| /// <param name="getContinuationToken">The function used to create a continuation token from a page of results.</param> | ||
| /// <param name="getValues">The function used to extract results from a page.</param> | ||
| /// <param name="cancellation">The cancellation token to use.</param> | ||
| /// <exception cref="ArgumentNullException">If any of the required arguments are null.</exception> | ||
| public AzureAsyncCollectionResult( | ||
| ClientPipeline pipeline, | ||
| RequestOptions options, | ||
| Func<TContinuation?, PipelineMessage> createRequest, | ||
| Func<ClientResult, TContinuation?> getContinuationToken, | ||
| Func<ClientResult, IEnumerable<TItem>> getValues, | ||
| CancellationToken cancellation) | ||
| { | ||
| _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); | ||
| _options = options ?? new(); | ||
| _getContinuationToken = getContinuationToken ?? throw new ArgumentNullException(nameof(_getContinuationToken)); | ||
| _createRequest = createRequest ?? throw new ArgumentNullException(nameof(_createRequest)); | ||
| _getValues = getValues ?? throw new ArgumentNullException(nameof(_getContinuationToken)); | ||
| _cancellation = cancellation; | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override ContinuationToken? GetContinuationToken(ClientResult page) => _getContinuationToken(page); | ||
|
|
||
| /// <inheritdoc /> | ||
| public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync() | ||
| { | ||
| TContinuation? continuation = null; | ||
| do | ||
| { | ||
| ClientResult page = await SendRequestAsync(continuation).ConfigureAwait(false); | ||
| continuation = _getContinuationToken(page); | ||
|
|
||
| yield return page; | ||
| } while (continuation != null); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override IAsyncEnumerable<TItem> GetValuesFromPageAsync(ClientResult page) | ||
| => _getValues(page).ToAsyncEnumerable(_cancellation); | ||
|
|
||
| /// <summary> | ||
| /// Sends a request to get the first page of results (<paramref name="continuationToken"/> is null), | ||
| /// or the next page of results (<paramref name="continuationToken"/> has a non-null value). | ||
| /// </summary> | ||
| /// <param name="continuationToken">The continuation token to use. Will be null when retrieving the first page of results.</param> | ||
| /// <returns>The result containing the page of results.</returns> | ||
| protected virtual async Task<ClientResult> SendRequestAsync(TContinuation? continuationToken) | ||
| { | ||
| using PipelineMessage message = _createRequest(continuationToken); | ||
| PipelineResponse response = await _pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false); | ||
| return ClientResult.FromResponse(response); | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #nullable enable | ||
|
|
||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
|
|
||
| namespace Azure.AI.OpenAI.Utility; | ||
|
|
||
| /// <summary> | ||
| /// Represents a collection of values returned from an Azure cloud service operation. | ||
| /// </summary> | ||
| /// <typeparam name="TItem">The type of items in the collection.</typeparam> | ||
| /// <typeparam name="TContinuation">Type of the continuation token.</typeparam> | ||
| internal class AzureCollectionResult<TItem, TContinuation> : CollectionResult<TItem> where TContinuation : ContinuationToken | ||
| { | ||
| private readonly ClientPipeline _pipeline; | ||
| private readonly RequestOptions _options; | ||
| private readonly Func<TContinuation?, PipelineMessage> _createRequest; | ||
| private readonly Func<ClientResult, TContinuation?> _getContinuationToken; | ||
| private readonly Func<ClientResult, IEnumerable<TItem>> _getValues; | ||
|
|
||
| /// <summary> | ||
| /// Creates a new instance. | ||
| /// </summary> | ||
| /// <param name="pipeline">The client pipeline to use to send requests.</param> | ||
| /// <param name="options">The request options to use.</param> | ||
| /// <param name="createRequest">The function used to create the request to get a page of results. The continuation token | ||
| /// may be set to null to get the first page. After that it will be set to a value used to get the next page of results.</param> | ||
| /// <param name="getContinuationToken">The function used to create a continuation token from a page of results.</param> | ||
| /// <param name="getValues">The function used to extract results from a page.</param> | ||
| /// <exception cref="ArgumentNullException">If any of the required arguments are null.</exception> | ||
| public AzureCollectionResult( | ||
| ClientPipeline pipeline, | ||
| RequestOptions options, | ||
| Func<TContinuation?, PipelineMessage> createRequest, | ||
| Func<ClientResult, TContinuation?> getContinuationToken, | ||
| Func<ClientResult, IEnumerable<TItem>> getValues) | ||
| { | ||
| _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); | ||
| _options = options ?? new(); | ||
| _createRequest = createRequest ?? throw new ArgumentNullException(nameof(_createRequest)); | ||
| _getContinuationToken = getContinuationToken ?? throw new ArgumentNullException(nameof(_getContinuationToken)); | ||
| _getValues = getValues ?? throw new ArgumentNullException(nameof(_getContinuationToken)); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public override ContinuationToken? GetContinuationToken(ClientResult page) => _getContinuationToken(page); | ||
|
|
||
| /// <inheritdoc /> | ||
| public override IEnumerable<ClientResult> GetRawPages() | ||
| { | ||
| TContinuation? continuation = null; | ||
|
|
||
| do | ||
| { | ||
| ClientResult page = SendRequest(continuation); | ||
| continuation = _getContinuationToken(page); | ||
|
|
||
| yield return page; | ||
| } | ||
| while (continuation != null); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override IEnumerable<TItem> GetValuesFromPage(ClientResult page) => _getValues(page); | ||
|
|
||
| /// <summary> | ||
| /// Sends a request to get the first page of results (<paramref name="continuationToken"/> is null), | ||
| /// or the next page of results (<paramref name="continuationToken"/> has a non-null value). | ||
| /// </summary> | ||
| /// <param name="continuationToken">The continuation token to use. Will be null when retrieving the first page of results.</param> | ||
| /// <returns>The result containing the page of results.</returns> | ||
| protected virtual ClientResult SendRequest(TContinuation? continuationToken) | ||
| { | ||
| using PipelineMessage message = _createRequest(continuationToken); | ||
| return ClientResult.FromResponse(_pipeline.ProcessMessage(message, _options)); | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.