openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
6b3c8b0a3d3208218dc3cbcd295502024988a956

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/Generated/CollectionResults/ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT.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.Chat
12{
13 internal partial class ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT : AsyncCollectionResult<ChatCompletionMessageListDatum>
14 {
15 private readonly ChatClient _client;
16 private readonly string _completionId;
17 private readonly string _after;
18 private readonly int? _limit;
19 private readonly string _order;
20 private readonly RequestOptions _options;
21
22 public ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT(ChatClient client, string completionId, string after, int? limit, string order, RequestOptions options)
23 {
24 _client = client;
25 _completionId = completionId;
26 _after = after;
27 _limit = limit;
28 _order = order;
29 _options = options;
30 }
31
32 public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync()
33 {
34 PipelineMessage message = _client.CreateGetChatCompletionMessagesRequest(_completionId, _after, _limit, _order, _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 = ((InternalChatCompletionMessageList)result).HasMore;
43 nextToken = ((InternalChatCompletionMessageList)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.CreateGetChatCompletionMessagesRequest(_completionId, nextToken, _limit, _order, _options);
50 }
51 }
52
53 public override ContinuationToken GetContinuationToken(ClientResult page)
54 {
55 string nextPage = ((InternalChatCompletionMessageList)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<ChatCompletionMessageListDatum> GetValuesFromPageAsync(ClientResult page)
67 {
68 foreach (ChatCompletionMessageListDatum item in ((InternalChatCompletionMessageList)page).Data)
69 {
70 yield return item;
71 await Task.Yield();
72 }
73 }
74 }
75}