openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
OpenAI.Responses/src/Generated/CollectionResults/ResponsesClientGetResponseInputItemsAsyncCollectionResultOfT.cs
82lines · modecode
| 1 | // <auto-generated/> |
| 2 | |
| 3 | #nullable disable |
| 4 | |
| 5 | using System; |
| 6 | using System.ClientModel; |
| 7 | using System.ClientModel.Primitives; |
| 8 | using System.Collections.Generic; |
| 9 | using System.Threading.Tasks; |
| 10 | |
| 11 | namespace OpenAI.Responses |
| 12 | { |
| 13 | internal partial class ResponsesClientGetResponseInputItemsAsyncCollectionResultOfT : AsyncCollectionResult<ResponseItem> |
| 14 | { |
| 15 | private readonly ResponsesClient _client; |
| 16 | private readonly string _responseId; |
| 17 | private readonly int? _limit; |
| 18 | private readonly string _order; |
| 19 | private readonly string _after; |
| 20 | private readonly string _before; |
| 21 | private readonly RequestOptions _options; |
| 22 | |
| 23 | public ResponsesClientGetResponseInputItemsAsyncCollectionResultOfT(ResponsesClient client, string responseId, int? limit, string order, string after, string before, RequestOptions options) |
| 24 | { |
| 25 | _client = client; |
| 26 | _responseId = responseId; |
| 27 | _limit = limit; |
| 28 | _order = order; |
| 29 | _after = after; |
| 30 | _before = before; |
| 31 | _options = options; |
| 32 | } |
| 33 | |
| 34 | public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync() |
| 35 | { |
| 36 | PipelineMessage message = _client.CreateGetResponseInputItemsRequest(_responseId, _limit, _order, _after, _before, _options); |
| 37 | string nextToken = null; |
| 38 | while (true) |
| 39 | { |
| 40 | ClientResult result = await GetNextResponseAsync(message).ConfigureAwait(false); |
| 41 | yield return result; |
| 42 | |
| 43 | // Plugin customization: add hasMore assignment |
| 44 | bool hasMore = ((ResponseItemCollectionPage)result).HasMore; |
| 45 | nextToken = ((ResponseItemCollectionPage)result).LastId; |
| 46 | // Plugin customization: add hasMore == false check to pagination condition |
| 47 | if (string.IsNullOrEmpty(nextToken) || !hasMore) |
| 48 | { |
| 49 | yield break; |
| 50 | } |
| 51 | message = _client.CreateGetResponseInputItemsRequest(_responseId, _limit, _order, nextToken, _before, _options); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | public override ContinuationToken GetContinuationToken(ClientResult page) |
| 56 | { |
| 57 | string nextPage = ((ResponseItemCollectionPage)page).LastId; |
| 58 | if (!string.IsNullOrEmpty(nextPage)) |
| 59 | { |
| 60 | return ContinuationToken.FromBytes(BinaryData.FromString(nextPage)); |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | return null; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | protected override async IAsyncEnumerable<ResponseItem> GetValuesFromPageAsync(ClientResult page) |
| 69 | { |
| 70 | foreach (ResponseItem item in ((ResponseItemCollectionPage)page).Data) |
| 71 | { |
| 72 | yield return item; |
| 73 | await Task.Yield(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | private async ValueTask<ClientResult> GetNextResponseAsync(PipelineMessage message) |
| 78 | { |
| 79 | return ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |