Skip to content

Commit 95d87e5

Browse files
committed
with tests
1 parent 9222e88 commit 95d87e5

File tree

10 files changed

+78
-63
lines changed

10 files changed

+78
-63
lines changed

api/OpenAI.net8.0.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ public class ChatClient {
14511451
[Experimental("OPENAI001")]
14521452
public virtual Task<ClientResult<ChatCompletion>> GetChatCompletionAsync(string completionId, CancellationToken cancellationToken = default);
14531453
[Experimental("OPENAI001")]
1454-
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionCollectionOptions options = null, CancellationToken cancellationToken = default);
1454+
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionMessageCollectionOptions options = null, CancellationToken cancellationToken = default);
14551455
[Experimental("OPENAI001")]
14561456
public virtual CollectionResult GetChatCompletionMessages(string completionId, string after, int? limit, string order, RequestOptions options);
14571457
[Experimental("OPENAI001")]
@@ -4704,6 +4704,10 @@ public class OpenAIResponseClient {
47044704
public virtual ClientResult<ResponseDeletionResult> DeleteResponse(string responseId, CancellationToken cancellationToken = default);
47054705
public virtual Task<ClientResult> DeleteResponseAsync(string responseId, RequestOptions options);
47064706
public virtual Task<ClientResult<ResponseDeletionResult>> DeleteResponseAsync(string responseId, CancellationToken cancellationToken = default);
4707+
public virtual CollectionResult<ResponseItem> GetInputItems(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4708+
public virtual CollectionResult GetInputItems(string responseId, int? limit, string order, string after, string before, RequestOptions options);
4709+
public virtual AsyncCollectionResult<ResponseItem> GetInputItemsAsync(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4710+
public virtual AsyncCollectionResult GetInputItemsAsync(string responseId, int? limit, string order, string after, string before, RequestOptions options);
47074711
public virtual ClientResult GetResponse(string responseId, bool? stream, int? startingAfter, RequestOptions options);
47084712
public virtual ClientResult<OpenAIResponse> GetResponse(string responseId, CancellationToken cancellationToken = default);
47094713
public virtual Task<ClientResult> GetResponseAsync(string responseId, bool? stream, int? startingAfter, RequestOptions options);
@@ -4951,11 +4955,15 @@ public class ResponseItem : IJsonModel<ResponseItem>, IPersistableModel<Response
49514955
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
49524956
}
49534957
[Experimental("OPENAI001")]
4954-
public class ResponseItemCollectionOptions {
4958+
public class ResponseItemCollectionOptions : IJsonModel<ResponseItemCollectionOptions>, IPersistableModel<ResponseItemCollectionOptions> {
49554959
public string AfterId { get; set; }
49564960
public string BeforeId { get; set; }
49574961
public ResponseItemCollectionOrder? Order { get; set; }
49584962
public int? PageSizeLimit { get; set; }
4963+
protected virtual ResponseItemCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4964+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4965+
protected virtual ResponseItemCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4966+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
49594967
}
49604968
[Experimental("OPENAI001")]
49614969
public readonly partial struct ResponseItemCollectionOrder : IEquatable<ResponseItemCollectionOrder> {

api/OpenAI.netstandard2.0.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ public class ChatClient {
12971297
public virtual ClientResult<ChatCompletion> GetChatCompletion(string completionId, CancellationToken cancellationToken = default);
12981298
public virtual Task<ClientResult> GetChatCompletionAsync(string completionId, RequestOptions options);
12991299
public virtual Task<ClientResult<ChatCompletion>> GetChatCompletionAsync(string completionId, CancellationToken cancellationToken = default);
1300-
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionCollectionOptions options = null, CancellationToken cancellationToken = default);
1300+
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionMessageCollectionOptions options = null, CancellationToken cancellationToken = default);
13011301
public virtual CollectionResult GetChatCompletionMessages(string completionId, string after, int? limit, string order, RequestOptions options);
13021302
public virtual AsyncCollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessagesAsync(string completionId, ChatCompletionMessageCollectionOptions options = null, CancellationToken cancellationToken = default);
13031303
public virtual AsyncCollectionResult GetChatCompletionMessagesAsync(string completionId, string after, int? limit, string order, RequestOptions options);
@@ -4148,6 +4148,10 @@ public class OpenAIResponseClient {
41484148
public virtual ClientResult<ResponseDeletionResult> DeleteResponse(string responseId, CancellationToken cancellationToken = default);
41494149
public virtual Task<ClientResult> DeleteResponseAsync(string responseId, RequestOptions options);
41504150
public virtual Task<ClientResult<ResponseDeletionResult>> DeleteResponseAsync(string responseId, CancellationToken cancellationToken = default);
4151+
public virtual CollectionResult<ResponseItem> GetInputItems(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4152+
public virtual CollectionResult GetInputItems(string responseId, int? limit, string order, string after, string before, RequestOptions options);
4153+
public virtual AsyncCollectionResult<ResponseItem> GetInputItemsAsync(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4154+
public virtual AsyncCollectionResult GetInputItemsAsync(string responseId, int? limit, string order, string after, string before, RequestOptions options);
41514155
public virtual ClientResult GetResponse(string responseId, bool? stream, int? startingAfter, RequestOptions options);
41524156
public virtual ClientResult<OpenAIResponse> GetResponse(string responseId, CancellationToken cancellationToken = default);
41534157
public virtual Task<ClientResult> GetResponseAsync(string responseId, bool? stream, int? startingAfter, RequestOptions options);
@@ -4373,11 +4377,15 @@ public class ResponseItem : IJsonModel<ResponseItem>, IPersistableModel<Response
43734377
protected virtual ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
43744378
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
43754379
}
4376-
public class ResponseItemCollectionOptions {
4380+
public class ResponseItemCollectionOptions : IJsonModel<ResponseItemCollectionOptions>, IPersistableModel<ResponseItemCollectionOptions> {
43774381
public string AfterId { get; set; }
43784382
public string BeforeId { get; set; }
43794383
public ResponseItemCollectionOrder? Order { get; set; }
43804384
public int? PageSizeLimit { get; set; }
4385+
protected virtual ResponseItemCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4386+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4387+
protected virtual ResponseItemCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4388+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
43814389
}
43824390
public readonly partial struct ResponseItemCollectionOrder : IEquatable<ResponseItemCollectionOrder> {
43834391
public ResponseItemCollectionOrder(string value);

src/Custom/Responses/Items/Internal/ResponsesUserMessage.cs renamed to src/Custom/Responses/Items/Internal/InternalResponsesUserMessage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
namespace OpenAI.Responses;
44

55
[CodeGenType("ResponsesUserMessageItemResource")]
6-
public partial class ResponsesUserMessage
6+
internal partial class InternalResponsesUserMessage
77
{
88
// CUSTOM: Use generalized content type.
99
[CodeGenMember("Content")]
10-
public IList<ResponseContentPart> Content { get; }
10+
public IList<ResponseContentPart> InternalContent { get; }
1111

1212
// CUSTOM: For reuse as an input model
13-
internal ResponsesUserMessage(IEnumerable<ResponseContentPart> internalContent)
13+
internal InternalResponsesUserMessage(IEnumerable<ResponseContentPart> internalContent)
1414
: this(id: null, status: null, internalContent)
1515
{ }
1616
}

src/Custom/Responses/Items/MessageResponseItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public MessageRole Role
2424

2525
// CUSTOM: Recombined content from derived types.
2626
public IList<ResponseContentPart> Content
27-
=> (this as ResponsesUserMessage)?.Content
27+
=> (this as InternalResponsesUserMessage)?.Content
2828
?? (this as InternalResponsesDeveloperMessage)?.InternalContent
2929
?? (this as InternalResponsesSystemMessage)?.InternalContent
3030
?? (this as InternalResponsesAssistantMessage)?.InternalContent

src/Custom/Responses/Items/ResponseItem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ public partial class ResponseItem
1717
public static MessageResponseItem CreateUserMessageItem(IEnumerable<ResponseContentPart> contentParts)
1818
{
1919
Argument.AssertNotNullOrEmpty(contentParts, nameof(contentParts));
20-
return new ResponsesUserMessage(contentParts);
20+
return new InternalResponsesUserMessage(contentParts);
2121
}
2222

2323
public static MessageResponseItem CreateUserMessageItem(string inputTextContent)
2424
{
2525
Argument.AssertNotNull(inputTextContent, nameof(inputTextContent));
26-
return new ResponsesUserMessage(
26+
return new InternalResponsesUserMessage(
2727
internalContent: [ResponseContentPart.CreateInputTextPart(inputTextContent)]);
2828
}
2929

src/Generated/Models/Responses/ResponsesUserMessage.Serialization.cs renamed to src/Generated/Models/Responses/InternalResponsesUserMessage.Serialization.cs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
namespace OpenAI.Responses
1212
{
13-
public partial class ResponsesUserMessage : IJsonModel<ResponsesUserMessage>
13+
internal partial class InternalResponsesUserMessage : IJsonModel<InternalResponsesUserMessage>
1414
{
15-
internal ResponsesUserMessage() : this(default, null, null, default, default, null)
15+
internal InternalResponsesUserMessage() : this(default, null, null, default, default, null)
1616
{
1717
}
1818

19-
void IJsonModel<ResponsesUserMessage>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
19+
void IJsonModel<InternalResponsesUserMessage>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
2020
{
2121
writer.WriteStartObject();
2222
JsonModelWriteCore(writer, options);
@@ -25,38 +25,38 @@ void IJsonModel<ResponsesUserMessage>.Write(Utf8JsonWriter writer, ModelReaderWr
2525

2626
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
2727
{
28-
string format = options.Format == "W" ? ((IPersistableModel<ResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
28+
string format = options.Format == "W" ? ((IPersistableModel<InternalResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
2929
if (format != "J")
3030
{
31-
throw new FormatException($"The model {nameof(ResponsesUserMessage)} does not support writing '{format}' format.");
31+
throw new FormatException($"The model {nameof(InternalResponsesUserMessage)} does not support writing '{format}' format.");
3232
}
3333
base.JsonModelWriteCore(writer, options);
3434
if (_additionalBinaryDataProperties?.ContainsKey("content") != true)
3535
{
3636
writer.WritePropertyName("content"u8);
3737
writer.WriteStartArray();
38-
foreach (ResponseContentPart item in Content)
38+
foreach (ResponseContentPart item in InternalContent)
3939
{
4040
writer.WriteObjectValue(item, options);
4141
}
4242
writer.WriteEndArray();
4343
}
4444
}
4545

46-
ResponsesUserMessage IJsonModel<ResponsesUserMessage>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (ResponsesUserMessage)JsonModelCreateCore(ref reader, options);
46+
InternalResponsesUserMessage IJsonModel<InternalResponsesUserMessage>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (InternalResponsesUserMessage)JsonModelCreateCore(ref reader, options);
4747

4848
protected override ResponseItem JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
4949
{
50-
string format = options.Format == "W" ? ((IPersistableModel<ResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
50+
string format = options.Format == "W" ? ((IPersistableModel<InternalResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
5151
if (format != "J")
5252
{
53-
throw new FormatException($"The model {nameof(ResponsesUserMessage)} does not support reading '{format}' format.");
53+
throw new FormatException($"The model {nameof(InternalResponsesUserMessage)} does not support reading '{format}' format.");
5454
}
5555
using JsonDocument document = JsonDocument.ParseValue(ref reader);
56-
return DeserializeResponsesUserMessage(document.RootElement, options);
56+
return DeserializeInternalResponsesUserMessage(document.RootElement, options);
5757
}
5858

59-
internal static ResponsesUserMessage DeserializeResponsesUserMessage(JsonElement element, ModelReaderWriterOptions options)
59+
internal static InternalResponsesUserMessage DeserializeInternalResponsesUserMessage(JsonElement element, ModelReaderWriterOptions options)
6060
{
6161
if (element.ValueKind == JsonValueKind.Null)
6262
{
@@ -67,7 +67,7 @@ internal static ResponsesUserMessage DeserializeResponsesUserMessage(JsonElement
6767
IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
6868
InternalResponsesMessageRole internalRole = default;
6969
MessageStatus? status = default;
70-
IList<ResponseContentPart> content = default;
70+
IList<ResponseContentPart> internalContent = default;
7171
foreach (var prop in element.EnumerateObject())
7272
{
7373
if (prop.NameEquals("type"u8))
@@ -97,52 +97,52 @@ internal static ResponsesUserMessage DeserializeResponsesUserMessage(JsonElement
9797
{
9898
array.Add(ResponseContentPart.DeserializeResponseContentPart(item, options));
9999
}
100-
content = array;
100+
internalContent = array;
101101
continue;
102102
}
103103
// Plugin customization: remove options.Format != "W" check
104104
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
105105
}
106-
return new ResponsesUserMessage(
106+
return new InternalResponsesUserMessage(
107107
kind,
108108
id,
109109
additionalBinaryDataProperties,
110110
internalRole,
111111
status,
112-
content);
112+
internalContent);
113113
}
114114

115-
BinaryData IPersistableModel<ResponsesUserMessage>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
115+
BinaryData IPersistableModel<InternalResponsesUserMessage>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
116116

117117
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
118118
{
119-
string format = options.Format == "W" ? ((IPersistableModel<ResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
119+
string format = options.Format == "W" ? ((IPersistableModel<InternalResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
120120
switch (format)
121121
{
122122
case "J":
123123
return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
124124
default:
125-
throw new FormatException($"The model {nameof(ResponsesUserMessage)} does not support writing '{options.Format}' format.");
125+
throw new FormatException($"The model {nameof(InternalResponsesUserMessage)} does not support writing '{options.Format}' format.");
126126
}
127127
}
128128

129-
ResponsesUserMessage IPersistableModel<ResponsesUserMessage>.Create(BinaryData data, ModelReaderWriterOptions options) => (ResponsesUserMessage)PersistableModelCreateCore(data, options);
129+
InternalResponsesUserMessage IPersistableModel<InternalResponsesUserMessage>.Create(BinaryData data, ModelReaderWriterOptions options) => (InternalResponsesUserMessage)PersistableModelCreateCore(data, options);
130130

131131
protected override ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
132132
{
133-
string format = options.Format == "W" ? ((IPersistableModel<ResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
133+
string format = options.Format == "W" ? ((IPersistableModel<InternalResponsesUserMessage>)this).GetFormatFromOptions(options) : options.Format;
134134
switch (format)
135135
{
136136
case "J":
137137
using (JsonDocument document = JsonDocument.Parse(data))
138138
{
139-
return DeserializeResponsesUserMessage(document.RootElement, options);
139+
return DeserializeInternalResponsesUserMessage(document.RootElement, options);
140140
}
141141
default:
142-
throw new FormatException($"The model {nameof(ResponsesUserMessage)} does not support reading '{options.Format}' format.");
142+
throw new FormatException($"The model {nameof(InternalResponsesUserMessage)} does not support reading '{options.Format}' format.");
143143
}
144144
}
145145

146-
string IPersistableModel<ResponsesUserMessage>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
146+
string IPersistableModel<InternalResponsesUserMessage>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
147147
}
148148
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// <auto-generated/>
2+
3+
#nullable disable
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using OpenAI;
9+
10+
namespace OpenAI.Responses
11+
{
12+
internal partial class InternalResponsesUserMessage : MessageResponseItem
13+
{
14+
internal InternalResponsesUserMessage(string id, MessageStatus? status, IEnumerable<ResponseContentPart> internalContent) : base(id, InternalResponsesMessageRole.User, status)
15+
{
16+
InternalContent = internalContent.ToList();
17+
}
18+
19+
internal InternalResponsesUserMessage(InternalItemType kind, string id, IDictionary<string, BinaryData> additionalBinaryDataProperties, InternalResponsesMessageRole internalRole, MessageStatus? status, IList<ResponseContentPart> internalContent) : base(kind, id, additionalBinaryDataProperties, internalRole, status)
20+
{
21+
// Plugin customization: ensure initialization of collections
22+
InternalContent = internalContent ?? new ChangeTrackingList<ResponseContentPart>();
23+
}
24+
}
25+
}

src/Generated/Models/Responses/MessageResponseItem.Serialization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal static MessageResponseItem DeserializeMessageResponseItem(JsonElement e
6767
switch (discriminator.GetString())
6868
{
6969
case "user":
70-
return ResponsesUserMessage.DeserializeResponsesUserMessage(element, options);
70+
return InternalResponsesUserMessage.DeserializeInternalResponsesUserMessage(element, options);
7171
case "system":
7272
return InternalResponsesSystemMessage.DeserializeInternalResponsesSystemMessage(element, options);
7373
case "developer":

0 commit comments

Comments
 (0)