openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/move-addresponsesclient-methods

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

OpenAI/src/Generated/CollectionResults/AssistantClientGetAssistantsAsyncCollectionResultOfT.cs

75lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.ClientModel;
7using System.ClientModel.Primitives;
8using System.Collections.Generic;
9using System.Threading.Tasks;
10
11namespace OpenAI.Assistants
12{
13 internal partial class AssistantClientGetAssistantsAsyncCollectionResultOfT : AsyncCollectionResult<Assistant>
14 {
15 private readonly AssistantClient _client;
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 AssistantClientGetAssistantsAsyncCollectionResultOfT(AssistantClient client, int? limit, string order, string after, string before, RequestOptions options)
23 {
24 _client = client;
25 _limit = limit;
26 _order = order;
27 _after = after;
28 _before = before;
29 _options = options;
30 }
31
32 public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync()
33 {
34 PipelineMessage message = _client.CreateGetAssistantsRequest(_limit, _order, _after, _before, _options);
35 string nextToken = null;
36 while (true)
37 {
38 ClientResult result = ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
39 yield return result;
40
41 // Plugin customization: add hasMore assignment
42 bool hasMore = ((InternalListAssistantsResponse)result).HasMore;
43 nextToken = ((InternalListAssistantsResponse)result).LastId;
44 // Plugin customization: add hasMore == false check to pagination condition
45 if (string.IsNullOrEmpty(nextToken) || !hasMore)
46 {
47 yield break;
48 }
49 message = _client.CreateGetAssistantsRequest(_limit, _order, nextToken, _before, _options);
50 }
51 }
52
53 public override ContinuationToken GetContinuationToken(ClientResult page)
54 {
55 string nextPage = ((InternalListAssistantsResponse)page).LastId;
56 if (!string.IsNullOrEmpty(nextPage))
57 {
58 return ContinuationToken.FromBytes(BinaryData.FromString(nextPage));
59 }
60 else
61 {
62 return null;
63 }
64 }
65
66 protected override async IAsyncEnumerable<Assistant> GetValuesFromPageAsync(ClientResult page)
67 {
68 foreach (Assistant item in ((InternalListAssistantsResponse)page).Data)
69 {
70 yield return item;
71 await Task.Yield();
72 }
73 }
74 }
75}
76