Skip to content

Commit 9698f1c

Browse files
committed
Fix generation
1 parent 9f39eae commit 9698f1c

7 files changed

+354
-19
lines changed

api/OpenAI.net8.0.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,19 +1542,34 @@ public class ChatCompletionDeletionResult : IJsonModel<ChatCompletionDeletionRes
15421542
[Experimental("OPENAI001")]
15431543
public class ChatCompletionMessageCollectionOptions : IJsonModel<ChatCompletionMessageCollectionOptions>, IPersistableModel<ChatCompletionMessageCollectionOptions> {
15441544
public string AfterId { get; set; }
1545-
public ChatCompletionCollectionOrder? Order { get; set; }
1545+
public ChatCompletionMessageCollectionOrder? Order { get; set; }
15461546
public int? PageSizeLimit { get; set; }
15471547
protected virtual ChatCompletionMessageCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
15481548
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
15491549
protected virtual ChatCompletionMessageCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
15501550
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
15511551
}
15521552
[Experimental("OPENAI001")]
1553+
public readonly partial struct ChatCompletionMessageCollectionOrder : IEquatable<ChatCompletionMessageCollectionOrder> {
1554+
public ChatCompletionMessageCollectionOrder(string value);
1555+
public static ChatCompletionMessageCollectionOrder Ascending { get; }
1556+
public static ChatCompletionMessageCollectionOrder Descending { get; }
1557+
public readonly bool Equals(ChatCompletionMessageCollectionOrder other);
1558+
[EditorBrowsable(EditorBrowsableState.Never)]
1559+
public override readonly bool Equals(object obj);
1560+
[EditorBrowsable(EditorBrowsableState.Never)]
1561+
public override readonly int GetHashCode();
1562+
public static bool operator ==(ChatCompletionMessageCollectionOrder left, ChatCompletionMessageCollectionOrder right);
1563+
public static implicit operator ChatCompletionMessageCollectionOrder(string value);
1564+
public static bool operator !=(ChatCompletionMessageCollectionOrder left, ChatCompletionMessageCollectionOrder right);
1565+
public override readonly string ToString();
1566+
}
1567+
[Experimental("OPENAI001")]
15531568
public class ChatCompletionMessageListDatum : IJsonModel<ChatCompletionMessageListDatum>, IPersistableModel<ChatCompletionMessageListDatum> {
1554-
public IList<ChatMessageAnnotation> Annotations { get; }
1555-
public ChatOutputAudio Audio { get; }
1569+
public IReadOnlyList<ChatMessageAnnotation> Annotations { get; }
15561570
public string Content { get; }
15571571
public string Id { get; }
1572+
public ChatOutputAudio OutputAudio { get; }
15581573
public string Refusal { get; }
15591574
public IReadOnlyList<ChatToolCall> ToolCalls { get; }
15601575
protected virtual ChatCompletionMessageListDatum JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);

api/OpenAI.netstandard2.0.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,18 +1367,32 @@ public class ChatCompletionDeletionResult : IJsonModel<ChatCompletionDeletionRes
13671367
}
13681368
public class ChatCompletionMessageCollectionOptions : IJsonModel<ChatCompletionMessageCollectionOptions>, IPersistableModel<ChatCompletionMessageCollectionOptions> {
13691369
public string AfterId { get; set; }
1370-
public ChatCompletionCollectionOrder? Order { get; set; }
1370+
public ChatCompletionMessageCollectionOrder? Order { get; set; }
13711371
public int? PageSizeLimit { get; set; }
13721372
protected virtual ChatCompletionMessageCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
13731373
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
13741374
protected virtual ChatCompletionMessageCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
13751375
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
13761376
}
1377+
public readonly partial struct ChatCompletionMessageCollectionOrder : IEquatable<ChatCompletionMessageCollectionOrder> {
1378+
public ChatCompletionMessageCollectionOrder(string value);
1379+
public static ChatCompletionMessageCollectionOrder Ascending { get; }
1380+
public static ChatCompletionMessageCollectionOrder Descending { get; }
1381+
public readonly bool Equals(ChatCompletionMessageCollectionOrder other);
1382+
[EditorBrowsable(EditorBrowsableState.Never)]
1383+
public override readonly bool Equals(object obj);
1384+
[EditorBrowsable(EditorBrowsableState.Never)]
1385+
public override readonly int GetHashCode();
1386+
public static bool operator ==(ChatCompletionMessageCollectionOrder left, ChatCompletionMessageCollectionOrder right);
1387+
public static implicit operator ChatCompletionMessageCollectionOrder(string value);
1388+
public static bool operator !=(ChatCompletionMessageCollectionOrder left, ChatCompletionMessageCollectionOrder right);
1389+
public override readonly string ToString();
1390+
}
13771391
public class ChatCompletionMessageListDatum : IJsonModel<ChatCompletionMessageListDatum>, IPersistableModel<ChatCompletionMessageListDatum> {
1378-
public IList<ChatMessageAnnotation> Annotations { get; }
1379-
public ChatOutputAudio Audio { get; }
1392+
public IReadOnlyList<ChatMessageAnnotation> Annotations { get; }
13801393
public string Content { get; }
13811394
public string Id { get; }
1395+
public ChatOutputAudio OutputAudio { get; }
13821396
public string Refusal { get; }
13831397
public IReadOnlyList<ChatToolCall> ToolCalls { get; }
13841398
protected virtual ChatCompletionMessageListDatum JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);

src/Generated/ChatClient.cs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.Threading;
1111
using System.Threading.Tasks;
1212
using OpenAI;
13-
using OpenAI.VectorStores;
1413

1514
namespace OpenAI.Chat
1615
{
@@ -149,39 +148,59 @@ public virtual async Task<ClientResult> DeleteChatCompletionAsync(string complet
149148
}
150149

151150
[Experimental("OPENAI001")]
152-
public virtual ClientResult GetChatCompletionMessages(string completionId, string after, int? limit, string order, RequestOptions options)
151+
public virtual CollectionResult GetChatCompletionMessages(string completionId, string after, int? limit, string order, RequestOptions options)
153152
{
154153
Argument.AssertNotNullOrEmpty(completionId, nameof(completionId));
155154

156-
using PipelineMessage message = CreateGetChatCompletionMessagesRequest(completionId, after, limit, order, options);
157-
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
155+
return new ChatClientGetChatCompletionMessagesCollectionResult(
156+
this,
157+
completionId,
158+
after,
159+
limit,
160+
order,
161+
options);
158162
}
159163

160164
[Experimental("OPENAI001")]
161-
public virtual async Task<ClientResult> GetChatCompletionMessagesAsync(string completionId, string after, int? limit, string order, RequestOptions options)
165+
public virtual AsyncCollectionResult GetChatCompletionMessagesAsync(string completionId, string after, int? limit, string order, RequestOptions options)
162166
{
163167
Argument.AssertNotNullOrEmpty(completionId, nameof(completionId));
164168

165-
using PipelineMessage message = CreateGetChatCompletionMessagesRequest(completionId, after, limit, order, options);
166-
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
169+
return new ChatClientGetChatCompletionMessagesAsyncCollectionResult(
170+
this,
171+
completionId,
172+
after,
173+
limit,
174+
order,
175+
options);
167176
}
168177

169178
[Experimental("OPENAI001")]
170-
public virtual ClientResult<InternalChatCompletionMessageList> GetChatCompletionMessages(string completionId, string after = default, int? limit = default, VectorStoreCollectionOrder? order = default, CancellationToken cancellationToken = default)
179+
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionCollectionOptions options = default, CancellationToken cancellationToken = default)
171180
{
172181
Argument.AssertNotNullOrEmpty(completionId, nameof(completionId));
173182

174-
ClientResult result = GetChatCompletionMessages(completionId, after, limit, order?.ToString(), cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
175-
return ClientResult.FromValue((InternalChatCompletionMessageList)result, result.GetRawResponse());
183+
return new ChatClientGetChatCompletionMessagesCollectionResultOfT(
184+
this,
185+
completionId,
186+
options?.AfterId,
187+
options?.PageSizeLimit,
188+
options?.Order?.ToString(),
189+
cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
176190
}
177191

178192
[Experimental("OPENAI001")]
179-
public virtual async Task<ClientResult<InternalChatCompletionMessageList>> GetChatCompletionMessagesAsync(string completionId, string after = default, int? limit = default, VectorStoreCollectionOrder? order = default, CancellationToken cancellationToken = default)
193+
public virtual AsyncCollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessagesAsync(string completionId, ChatCompletionMessageCollectionOptions options = default, CancellationToken cancellationToken = default)
180194
{
181195
Argument.AssertNotNullOrEmpty(completionId, nameof(completionId));
182196

183-
ClientResult result = await GetChatCompletionMessagesAsync(completionId, after, limit, order?.ToString(), cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
184-
return ClientResult.FromValue((InternalChatCompletionMessageList)result, result.GetRawResponse());
197+
return new ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT(
198+
this,
199+
completionId,
200+
options?.AfterId,
201+
options?.PageSizeLimit,
202+
options?.Order?.ToString(),
203+
cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
185204
}
186205
}
187206
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
using OpenAI;
10+
11+
namespace OpenAI.Chat
12+
{
13+
internal partial class ChatClientGetChatCompletionMessagesAsyncCollectionResult : AsyncCollectionResult
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 ChatClientGetChatCompletionMessagesAsyncCollectionResult(ChatClient client, string completionId, string after, int? limit, string order, RequestOptions options)
23+
{
24+
Argument.AssertNotNullOrEmpty(completionId, nameof(completionId));
25+
26+
_client = client;
27+
_completionId = completionId;
28+
_after = after;
29+
_limit = limit;
30+
_order = order;
31+
_options = options;
32+
}
33+
34+
public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync()
35+
{
36+
PipelineMessage message = _client.CreateGetChatCompletionMessagesRequest(_completionId, _after, _limit, _order, _options);
37+
string nextToken = null;
38+
while (true)
39+
{
40+
ClientResult result = ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
41+
yield return result;
42+
43+
// Plugin customization: add hasMore assignment
44+
bool hasMore = ((InternalChatCompletionMessageList)result).HasMore;
45+
nextToken = ((InternalChatCompletionMessageList)result).LastId;
46+
// Plugin customization: add hasMore == false check to pagination condition
47+
if (nextToken == null || !hasMore)
48+
{
49+
yield break;
50+
}
51+
message = _client.CreateGetChatCompletionMessagesRequest(_completionId, nextToken, _limit, _order, _options);
52+
}
53+
}
54+
55+
public override ContinuationToken GetContinuationToken(ClientResult page)
56+
{
57+
string nextPage = ((InternalChatCompletionMessageList)page).LastId;
58+
if (nextPage != null)
59+
{
60+
return ContinuationToken.FromBytes(BinaryData.FromString(nextPage));
61+
}
62+
else
63+
{
64+
return null;
65+
}
66+
}
67+
}
68+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
using System.Threading.Tasks;
10+
using OpenAI;
11+
12+
namespace OpenAI.Chat
13+
{
14+
internal partial class ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT : AsyncCollectionResult<ChatCompletionMessageListDatum>
15+
{
16+
private readonly ChatClient _client;
17+
private readonly string _completionId;
18+
private readonly string _after;
19+
private readonly int? _limit;
20+
private readonly string _order;
21+
private readonly RequestOptions _options;
22+
23+
public ChatClientGetChatCompletionMessagesAsyncCollectionResultOfT(ChatClient client, string completionId, string after, int? limit, string order, RequestOptions options)
24+
{
25+
Argument.AssertNotNullOrEmpty(completionId, nameof(completionId));
26+
27+
_client = client;
28+
_completionId = completionId;
29+
_after = after;
30+
_limit = limit;
31+
_order = order;
32+
_options = options;
33+
}
34+
35+
public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync()
36+
{
37+
PipelineMessage message = _client.CreateGetChatCompletionMessagesRequest(_completionId, _after, _limit, _order, _options);
38+
string nextToken = null;
39+
while (true)
40+
{
41+
ClientResult result = ClientResult.FromResponse(await _client.Pipeline.ProcessMessageAsync(message, _options).ConfigureAwait(false));
42+
yield return result;
43+
44+
// Plugin customization: add hasMore assignment
45+
bool hasMore = ((InternalChatCompletionMessageList)result).HasMore;
46+
nextToken = ((InternalChatCompletionMessageList)result).LastId;
47+
// Plugin customization: add hasMore == false check to pagination condition
48+
if (nextToken == null || !hasMore)
49+
{
50+
yield break;
51+
}
52+
message = _client.CreateGetChatCompletionMessagesRequest(_completionId, nextToken, _limit, _order, _options);
53+
}
54+
}
55+
56+
public override ContinuationToken GetContinuationToken(ClientResult page)
57+
{
58+
string nextPage = ((InternalChatCompletionMessageList)page).LastId;
59+
if (nextPage != null)
60+
{
61+
return ContinuationToken.FromBytes(BinaryData.FromString(nextPage));
62+
}
63+
else
64+
{
65+
return null;
66+
}
67+
}
68+
69+
protected override async IAsyncEnumerable<ChatCompletionMessageListDatum> GetValuesFromPageAsync(ClientResult page)
70+
{
71+
foreach (ChatCompletionMessageListDatum item in ((InternalChatCompletionMessageList)page).Data)
72+
{
73+
yield return item;
74+
await Task.Yield();
75+
}
76+
}
77+
}
78+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
using OpenAI;
10+
11+
namespace OpenAI.Chat
12+
{
13+
internal partial class ChatClientGetChatCompletionMessagesCollectionResult : CollectionResult
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 ChatClientGetChatCompletionMessagesCollectionResult(ChatClient client, string completionId, string after, int? limit, string order, RequestOptions options)
23+
{
24+
Argument.AssertNotNullOrEmpty(completionId, nameof(completionId));
25+
26+
_client = client;
27+
_completionId = completionId;
28+
_after = after;
29+
_limit = limit;
30+
_order = order;
31+
_options = options;
32+
}
33+
34+
public override IEnumerable<ClientResult> GetRawPages()
35+
{
36+
PipelineMessage message = _client.CreateGetChatCompletionMessagesRequest(_completionId, _after, _limit, _order, _options);
37+
string nextToken = null;
38+
while (true)
39+
{
40+
ClientResult result = ClientResult.FromResponse(_client.Pipeline.ProcessMessage(message, _options));
41+
yield return result;
42+
43+
// Plugin customization: add hasMore assignment
44+
bool hasMore = ((InternalChatCompletionMessageList)result).HasMore;
45+
nextToken = ((InternalChatCompletionMessageList)result).LastId;
46+
// Plugin customization: add hasMore == false check to pagination condition
47+
if (nextToken == null || !hasMore)
48+
{
49+
yield break;
50+
}
51+
message = _client.CreateGetChatCompletionMessagesRequest(_completionId, nextToken, _limit, _order, _options);
52+
}
53+
}
54+
55+
public override ContinuationToken GetContinuationToken(ClientResult page)
56+
{
57+
string nextPage = ((InternalChatCompletionMessageList)page).LastId;
58+
if (nextPage != null)
59+
{
60+
return ContinuationToken.FromBytes(BinaryData.FromString(nextPage));
61+
}
62+
else
63+
{
64+
return null;
65+
}
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)