-
Notifications
You must be signed in to change notification settings - Fork 342
Generate GetChatCompletionMessages with pagination #569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
christothes
merged 8 commits into
openai:main
from
christothes:chriss/GetChatCompletionMessages_pagination
Jul 31, 2025
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f9d062b
Generate GetChatCompletionMessages with pagination
christothes 60f4c79
fixup
christothes 065684d
fb
christothes 55a8bf3
fb
christothes ad88b78
fb
christothes 12b930e
export
christothes 346ae44
merge
christothes 76999c3
fb
christothes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
|
|
||
| namespace OpenAI.Chat; | ||
|
|
||
| // CUSTOM: Use the correct namespace. | ||
| [CodeGenType("ChatCompletionMessageCollectionOptions")] | ||
| public partial class ChatCompletionMessageCollectionOptions {} |
2 changes: 1 addition & 1 deletion
2
...InternalChatCompletionMessageListDatum.cs → ...om/Chat/ChatCompletionMessageListDatum.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/Generated/ChatClientGetChatCompletionMessagesAsyncCollectionResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
| using System.Collections.Generic; | ||
| using OpenAI; | ||
|
|
||
| namespace OpenAI.Chat | ||
| { | ||
| internal partial class ChatClientGetChatCompletionMessagesAsyncCollectionResult : AsyncCollectionResult | ||
| { | ||
| private readonly ChatClient _client; | ||
| private readonly string _completionId; | ||
| private readonly string _after; | ||
| private readonly int? _limit; | ||
| private readonly string _order; | ||
| private readonly RequestOptions _options; | ||
|
|
||
| public ChatClientGetChatCompletionMessagesAsyncCollectionResult(ChatClient client, string completionId, string after, int? limit, string order, RequestOptions options) | ||
| { | ||
| Argument.AssertNotNullOrEmpty(completionId, nameof(completionId)); | ||
|
|
||
| _client = client; | ||
| _completionId = completionId; | ||
| _after = after; | ||
| _limit = limit; | ||
| _order = order; | ||
| _options = options; | ||
| } | ||
|
|
||
| public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync() | ||
| { | ||
| PipelineMessage message = _client.CreateGetChatCompletionMessagesRequest(_completionId, _after, _limit, _order, _options); | ||
| string nextToken = null; | ||
| while (true) | ||
| { | ||
| ClientResult result = ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); | ||
| yield return result; | ||
|
|
||
| // Plugin customization: add hasMore assignment | ||
| bool hasMore = ((InternalChatCompletionMessageList)result).HasMore; | ||
| nextToken = ((InternalChatCompletionMessageList)result).LastId; | ||
| // Plugin customization: add hasMore == false check to pagination condition | ||
| if (nextToken == null || hasMore == false) | ||
christothes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| yield break; | ||
| } | ||
| message = _client.CreateGetChatCompletionMessagesRequest(_completionId, nextToken, _limit, _order, _options); | ||
| } | ||
| } | ||
|
|
||
| public override ContinuationToken GetContinuationToken(ClientResult page) | ||
| { | ||
| string nextPage = ((InternalChatCompletionMessageList)page).LastId; | ||
| if (nextPage != null) | ||
| { | ||
| return ContinuationToken.FromBytes(BinaryData.FromString(nextPage)); | ||
| } | ||
| else | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| } | ||
78 changes: 78 additions & 0 deletions
78
src/Generated/ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using OpenAI; | ||
|
|
||
| namespace OpenAI.Chat | ||
| { | ||
| internal partial class ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT : AsyncCollectionResult<ChatCompletionMessageListDatum> | ||
| { | ||
| private readonly ChatClient _client; | ||
| private readonly string _completionId; | ||
| private readonly string _after; | ||
| private readonly int? _limit; | ||
| private readonly string _order; | ||
| private readonly RequestOptions _options; | ||
|
|
||
| public ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT(ChatClient client, string completionId, string after, int? limit, string order, RequestOptions options) | ||
| { | ||
| Argument.AssertNotNullOrEmpty(completionId, nameof(completionId)); | ||
|
|
||
| _client = client; | ||
| _completionId = completionId; | ||
| _after = after; | ||
| _limit = limit; | ||
| _order = order; | ||
| _options = options; | ||
| } | ||
|
|
||
| public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync() | ||
| { | ||
| PipelineMessage message = _client.CreateGetChatCompletionMessagesRequest(_completionId, _after, _limit, _order, _options); | ||
| string nextToken = null; | ||
| while (true) | ||
| { | ||
| ClientResult result = ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false)); | ||
| yield return result; | ||
|
|
||
| // Plugin customization: add hasMore assignment | ||
| bool hasMore = ((InternalChatCompletionMessageList)result).HasMore; | ||
| nextToken = ((InternalChatCompletionMessageList)result).LastId; | ||
| // Plugin customization: add hasMore == false check to pagination condition | ||
| if (nextToken == null || hasMore == false) | ||
| { | ||
| yield break; | ||
| } | ||
| message = _client.CreateGetChatCompletionMessagesRequest(_completionId, nextToken, _limit, _order, _options); | ||
| } | ||
| } | ||
|
|
||
| public override ContinuationToken GetContinuationToken(ClientResult page) | ||
| { | ||
| string nextPage = ((InternalChatCompletionMessageList)page).LastId; | ||
| if (nextPage != null) | ||
| { | ||
| return ContinuationToken.FromBytes(BinaryData.FromString(nextPage)); | ||
| } | ||
| else | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| protected override async IAsyncEnumerable<ChatCompletionMessageListDatum> GetValuesFromPageAsync(ClientResult page) | ||
| { | ||
| foreach (ChatCompletionMessageListDatum item in ((InternalChatCompletionMessageList)page).Data) | ||
| { | ||
| yield return item; | ||
| await Task.Yield(); | ||
| } | ||
| } | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/Generated/ChatClientGetChatCompletionMessagesCollectionResult.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // <auto-generated/> | ||
|
|
||
| #nullable disable | ||
|
|
||
| using System; | ||
| using System.ClientModel; | ||
| using System.ClientModel.Primitives; | ||
| using System.Collections.Generic; | ||
| using OpenAI; | ||
|
|
||
| namespace OpenAI.Chat | ||
| { | ||
| internal partial class ChatClientGetChatCompletionMessagesCollectionResult : CollectionResult | ||
| { | ||
| private readonly ChatClient _client; | ||
| private readonly string _completionId; | ||
| private readonly string _after; | ||
| private readonly int? _limit; | ||
| private readonly string _order; | ||
| private readonly RequestOptions _options; | ||
|
|
||
| public ChatClientGetChatCompletionMessagesCollectionResult(ChatClient client, string completionId, string after, int? limit, string order, RequestOptions options) | ||
| { | ||
| Argument.AssertNotNullOrEmpty(completionId, nameof(completionId)); | ||
|
|
||
| _client = client; | ||
| _completionId = completionId; | ||
| _after = after; | ||
| _limit = limit; | ||
| _order = order; | ||
| _options = options; | ||
| } | ||
|
|
||
| public override IEnumerable<ClientResult> GetRawPages() | ||
| { | ||
| PipelineMessage message = _client.CreateGetChatCompletionMessagesRequest(_completionId, _after, _limit, _order, _options); | ||
| string nextToken = null; | ||
| while (true) | ||
| { | ||
| ClientResult result = ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options)); | ||
| yield return result; | ||
|
|
||
| // Plugin customization: add hasMore assignment | ||
| bool hasMore = ((InternalChatCompletionMessageList)result).HasMore; | ||
| nextToken = ((InternalChatCompletionMessageList)result).LastId; | ||
| // Plugin customization: add hasMore == false check to pagination condition | ||
| if (nextToken == null || hasMore == false) | ||
| { | ||
| yield break; | ||
| } | ||
| message = _client.CreateGetChatCompletionMessagesRequest(_completionId, nextToken, _limit, _order, _options); | ||
| } | ||
| } | ||
|
|
||
| public override ContinuationToken GetContinuationToken(ClientResult page) | ||
| { | ||
| string nextPage = ((InternalChatCompletionMessageList)page).LastId; | ||
| if (nextPage != null) | ||
| { | ||
| return ContinuationToken.FromBytes(BinaryData.FromString(nextPage)); | ||
| } | ||
| else | ||
| { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.