openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
OpenAI.Responses/src/Generated/CollectionResults/ResponsesClientGetResponseInputItemsCollectionResultOfT.cs
77lines · 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 | |
| 10 | namespace OpenAI.Responses |
| 11 | { |
| 12 | internal partial class ResponsesClientGetResponseInputItemsCollectionResultOfT : CollectionResult<ResponseItem> |
| 13 | { |
| 14 | private readonly ResponsesClient _client; |
| 15 | private readonly string _responseId; |
| 16 | private readonly int? _limit; |
| 17 | private readonly string _order; |
| 18 | private readonly string _after; |
| 19 | private readonly string _before; |
| 20 | private readonly RequestOptions _options; |
| 21 | |
| 22 | public ResponsesClientGetResponseInputItemsCollectionResultOfT(ResponsesClient client, string responseId, int? limit, string order, string after, string before, RequestOptions options) |
| 23 | { |
| 24 | _client = client; |
| 25 | _responseId = responseId; |
| 26 | _limit = limit; |
| 27 | _order = order; |
| 28 | _after = after; |
| 29 | _before = before; |
| 30 | _options = options; |
| 31 | } |
| 32 | |
| 33 | public override IEnumerable<ClientResult> GetRawPages() |
| 34 | { |
| 35 | PipelineMessage message = _client.CreateGetResponseInputItemsRequest(_responseId, _limit, _order, _after, _before, _options); |
| 36 | string nextToken = null; |
| 37 | while (true) |
| 38 | { |
| 39 | ClientResult result = GetNextResponse(message); |
| 40 | yield return result; |
| 41 | |
| 42 | // Plugin customization: add hasMore assignment |
| 43 | bool hasMore = ((ResponseItemCollectionPage)result).HasMore; |
| 44 | nextToken = ((ResponseItemCollectionPage)result).LastId; |
| 45 | // Plugin customization: add hasMore == false check to pagination condition |
| 46 | if (string.IsNullOrEmpty(nextToken) || !hasMore) |
| 47 | { |
| 48 | yield break; |
| 49 | } |
| 50 | message = _client.CreateGetResponseInputItemsRequest(_responseId, _limit, _order, nextToken, _before, _options); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public override ContinuationToken GetContinuationToken(ClientResult page) |
| 55 | { |
| 56 | string nextPage = ((ResponseItemCollectionPage)page).LastId; |
| 57 | if (!string.IsNullOrEmpty(nextPage)) |
| 58 | { |
| 59 | return ContinuationToken.FromBytes(BinaryData.FromString(nextPage)); |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | return null; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | protected override IEnumerable<ResponseItem> GetValuesFromPage(ClientResult page) |
| 68 | { |
| 69 | return ((ResponseItemCollectionPage)page).Data; |
| 70 | } |
| 71 | |
| 72 | private ClientResult GetNextResponse(PipelineMessage message) |
| 73 | { |
| 74 | return ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options)); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |