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