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/BatchClientGetBatchesCollectionResultOfT.cs

66lines · modecode

1// <auto-generated/>
2
3#nullable disable
4
5using System;
6using System.ClientModel;
7using System.ClientModel.Primitives;
8using System.Collections.Generic;
9
10namespace OpenAI.Batch
11{
12 internal partial class BatchClientGetBatchesCollectionResultOfT : CollectionResult<BatchJob>
13 {
14 private readonly BatchClient _client;
15 private readonly string _after;
16 private readonly int? _limit;
17 private readonly RequestOptions _options;
18
19 public BatchClientGetBatchesCollectionResultOfT(BatchClient client, string after, int? limit, RequestOptions options)
20 {
21 _client = client;
22 _after = after;
23 _limit = limit;
24 _options = options;
25 }
26
27 public override IEnumerable<ClientResult> GetRawPages()
28 {
29 PipelineMessage message = _client.CreateGetBatchesRequest(_after, _limit, _options);
30 string nextToken = null;
31 while (true)
32 {
33 ClientResult result = ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
34 yield return result;
35
36 // Plugin customization: add hasMore assignment
37 bool hasMore = ((InternalListBatchesResponse)result).HasMore;
38 nextToken = ((InternalListBatchesResponse)result).LastId;
39 // Plugin customization: add hasMore == false check to pagination condition
40 if (string.IsNullOrEmpty(nextToken) || !hasMore)
41 {
42 yield break;
43 }
44 message = _client.CreateGetBatchesRequest(nextToken, _limit, _options);
45 }
46 }
47
48 public override ContinuationToken GetContinuationToken(ClientResult page)
49 {
50 string nextPage = ((InternalListBatchesResponse)page).LastId;
51 if (!string.IsNullOrEmpty(nextPage))
52 {
53 return ContinuationToken.FromBytes(BinaryData.FromString(nextPage));
54 }
55 else
56 {
57 return null;
58 }
59 }
60
61 protected override IEnumerable<BatchJob> GetValuesFromPage(ClientResult page)
62 {
63 return ((InternalListBatchesResponse)page).Data;
64 }
65 }
66}
67