Skip to content

Commit 9a979ad

Browse files
authored
Generate ListInputItems for Responses (#604)
1 parent 2237506 commit 9a979ad

25 files changed

+10942
-9918
lines changed

api/OpenAI.net8.0.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ public class ChatClient {
14631463
[Experimental("OPENAI001")]
14641464
public virtual Task<ClientResult<ChatCompletion>> GetChatCompletionAsync(string completionId, CancellationToken cancellationToken = default);
14651465
[Experimental("OPENAI001")]
1466-
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionCollectionOptions options = null, CancellationToken cancellationToken = default);
1466+
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionMessageCollectionOptions options = null, CancellationToken cancellationToken = default);
14671467
[Experimental("OPENAI001")]
14681468
public virtual CollectionResult GetChatCompletionMessages(string completionId, string after, int? limit, string order, RequestOptions options);
14691469
[Experimental("OPENAI001")]
@@ -4748,6 +4748,10 @@ public class OpenAIResponseClient {
47484748
public virtual ClientResult<ResponseDeletionResult> DeleteResponse(string responseId, CancellationToken cancellationToken = default);
47494749
public virtual Task<ClientResult> DeleteResponseAsync(string responseId, RequestOptions options);
47504750
public virtual Task<ClientResult<ResponseDeletionResult>> DeleteResponseAsync(string responseId, CancellationToken cancellationToken = default);
4751+
public virtual CollectionResult<ResponseItem> GetInputItems(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4752+
public virtual CollectionResult GetInputItems(string responseId, int? limit, string order, string after, string before, RequestOptions options);
4753+
public virtual AsyncCollectionResult<ResponseItem> GetInputItemsAsync(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4754+
public virtual AsyncCollectionResult GetInputItemsAsync(string responseId, int? limit, string order, string after, string before, RequestOptions options);
47514755
public virtual ClientResult GetResponse(string responseId, bool? stream, int? startingAfter, RequestOptions options);
47524756
public virtual ClientResult<OpenAIResponse> GetResponse(string responseId, CancellationToken cancellationToken = default);
47534757
public virtual Task<ClientResult> GetResponseAsync(string responseId, bool? stream, int? startingAfter, RequestOptions options);
@@ -4998,11 +5002,15 @@ public class ResponseItem : IJsonModel<ResponseItem>, IPersistableModel<Response
49985002
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
49995003
}
50005004
[Experimental("OPENAI001")]
5001-
public class ResponseItemCollectionOptions {
5005+
public class ResponseItemCollectionOptions : IJsonModel<ResponseItemCollectionOptions>, IPersistableModel<ResponseItemCollectionOptions> {
50025006
public string AfterId { get; set; }
50035007
public string BeforeId { get; set; }
50045008
public ResponseItemCollectionOrder? Order { get; set; }
50055009
public int? PageSizeLimit { get; set; }
5010+
protected virtual ResponseItemCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
5011+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
5012+
protected virtual ResponseItemCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
5013+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
50065014
}
50075015
[Experimental("OPENAI001")]
50085016
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
@@ -1310,7 +1310,7 @@ public class ChatClient {
13101310
public virtual ClientResult<ChatCompletion> GetChatCompletion(string completionId, CancellationToken cancellationToken = default);
13111311
public virtual Task<ClientResult> GetChatCompletionAsync(string completionId, RequestOptions options);
13121312
public virtual Task<ClientResult<ChatCompletion>> GetChatCompletionAsync(string completionId, CancellationToken cancellationToken = default);
1313-
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionCollectionOptions options = null, CancellationToken cancellationToken = default);
1313+
public virtual CollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessages(string completionId, ChatCompletionMessageCollectionOptions options = null, CancellationToken cancellationToken = default);
13141314
public virtual CollectionResult GetChatCompletionMessages(string completionId, string after, int? limit, string order, RequestOptions options);
13151315
public virtual AsyncCollectionResult<ChatCompletionMessageListDatum> GetChatCompletionMessagesAsync(string completionId, ChatCompletionMessageCollectionOptions options = null, CancellationToken cancellationToken = default);
13161316
public virtual AsyncCollectionResult GetChatCompletionMessagesAsync(string completionId, string after, int? limit, string order, RequestOptions options);
@@ -4193,6 +4193,10 @@ public class OpenAIResponseClient {
41934193
public virtual ClientResult<ResponseDeletionResult> DeleteResponse(string responseId, CancellationToken cancellationToken = default);
41944194
public virtual Task<ClientResult> DeleteResponseAsync(string responseId, RequestOptions options);
41954195
public virtual Task<ClientResult<ResponseDeletionResult>> DeleteResponseAsync(string responseId, CancellationToken cancellationToken = default);
4196+
public virtual CollectionResult<ResponseItem> GetInputItems(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4197+
public virtual CollectionResult GetInputItems(string responseId, int? limit, string order, string after, string before, RequestOptions options);
4198+
public virtual AsyncCollectionResult<ResponseItem> GetInputItemsAsync(string responseId, ResponseItemCollectionOptions options = null, CancellationToken cancellationToken = default);
4199+
public virtual AsyncCollectionResult GetInputItemsAsync(string responseId, int? limit, string order, string after, string before, RequestOptions options);
41964200
public virtual ClientResult GetResponse(string responseId, bool? stream, int? startingAfter, RequestOptions options);
41974201
public virtual ClientResult<OpenAIResponse> GetResponse(string responseId, CancellationToken cancellationToken = default);
41984202
public virtual Task<ClientResult> GetResponseAsync(string responseId, bool? stream, int? startingAfter, RequestOptions options);
@@ -4421,11 +4425,15 @@ public class ResponseItem : IJsonModel<ResponseItem>, IPersistableModel<Response
44214425
protected virtual ResponseItem PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
44224426
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
44234427
}
4424-
public class ResponseItemCollectionOptions {
4428+
public class ResponseItemCollectionOptions : IJsonModel<ResponseItemCollectionOptions>, IPersistableModel<ResponseItemCollectionOptions> {
44254429
public string AfterId { get; set; }
44264430
public string BeforeId { get; set; }
44274431
public ResponseItemCollectionOrder? Order { get; set; }
44284432
public int? PageSizeLimit { get; set; }
4433+
protected virtual ResponseItemCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4434+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4435+
protected virtual ResponseItemCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4436+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
44294437
}
44304438
public readonly partial struct ResponseItemCollectionOrder : IEquatable<ResponseItemCollectionOrder> {
44314439
public ResponseItemCollectionOrder(string value);

codegen/generator/src/Visitors/PaginationVisitor.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class PaginationVisitor : ScmLibraryVisitor
2222
private static readonly Dictionary<string, string> _paramReplacementMap = new()
2323
{
2424
{ "after", "AfterId" },
25-
{ "before", "LastId" },
25+
{ "before", "BeforeId" },
2626
{ "limit", "PageSizeLimit" },
2727
{ "order", "Order" },
2828
{ "model", "Model" },
@@ -40,11 +40,19 @@ public class PaginationVisitor : ScmLibraryVisitor
4040
},
4141
{
4242
"GetChatCompletionMessages",
43-
("ChatCompletionMessageListDatum", "ChatCompletionCollectionOptions", _chatParamsToReplace)
43+
("ChatCompletionMessageListDatum", "ChatCompletionMessageCollectionOptions", _chatParamsToReplace)
4444
},
4545
{
4646
"GetChatCompletionMessagesAsync",
4747
("ChatCompletionMessageListDatum", "ChatCompletionMessageCollectionOptions", _chatParamsToReplace)
48+
},
49+
{
50+
"GetInputItems",
51+
("ResponseItem", "ResponseItemCollectionOptions", _chatParamsToReplace)
52+
},
53+
{
54+
"GetInputItemsAsync",
55+
("ResponseItem", "ResponseItemCollectionOptions", _chatParamsToReplace)
4856
}
4957
};
5058

specification/base/typespec/responses/models.tsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ model ResponseItemList {
12721272
object: "list";
12731273

12741274
/** A list of items used to generate this response. */
1275-
data: ItemResource[];
1275+
@pageItems data: ItemResource[];
12761276

12771277
/** Whether there are more items available. */
12781278
has_more: boolean;
@@ -1281,7 +1281,7 @@ model ResponseItemList {
12811281
first_id: string;
12821282

12831283
/** The ID of the last item in the list. */
1284-
last_id: string;
1284+
@continuationToken last_id: string;
12851285
}
12861286

12871287
// Tool customization: Establish discriminated type base

specification/base/typespec/responses/operations.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ interface Responses {
8282
@operationId("listInputItems")
8383
@get
8484
@route("{response_id}/input_items")
85+
@list
8586
listInputItems(
8687
@path
8788
@example("resp_677efb5139a88190b512bc3fef8e535d")

specification/client/models/common.models.tsp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,13 @@ alias CollectionAfterQueryParameter = {
144144
* subsequent call can include after=obj_foo in order to fetch the next page of the list.
145145
*/
146146
@query @continuationToken afterId?: string;
147+
};
148+
149+
alias CollectionBeforeQueryParameter = {
150+
/**
151+
* A cursor for use in pagination. `before` is an object ID that defines your place in the list.
152+
* For instance, if you make a list request and receive 100 objects, starting with obj_foo, your
153+
* subsequent call can include before=obj_foo in order to fetch the previous page of the list.
154+
*/
155+
@query beforeId?: string;
147156
};

specification/client/models/responses.models.tsp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import "../../base/typespec/responses/main.tsp";
22
import "@azure-tools/typespec-client-generator-core";
33

44
using Azure.ClientGenerator.Core;
5+
using TypeSpec.Http;
56

67
namespace OpenAI;
78

@@ -25,3 +26,26 @@ model DotNetItemReferenceItemResource extends ItemResource {
2526
type: ItemType.item_reference;
2627
...ItemReferenceItemBase;
2728
}
29+
30+
alias ResponseItemCollectionOrderQueryParameter = {
31+
/**
32+
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
33+
* for descending order.
34+
*/
35+
@query order?: ResponseItemCollectionOrder;
36+
};
37+
38+
union ResponseItemCollectionOrder {
39+
string,
40+
Ascending: "asc",
41+
Descending: "desc",
42+
}
43+
44+
@access(Access.public)
45+
@usage(Usage.input)
46+
model ResponseItemCollectionOptions {
47+
...CollectionAfterQueryParameter,
48+
...CollectionBeforeQueryParameter,
49+
...CollectionLimitQueryParameter,
50+
...ResponseItemCollectionOrderQueryParameter,
51+
}

src/Custom/Responses/OpenAIResponseClient.Protocol.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace OpenAI.Responses;
88

99
[CodeGenSuppress("GetResponse", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
1010
[CodeGenSuppress("GetResponseAsync", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
11-
[CodeGenSuppress("GetInputItems", typeof(string), typeof(int?), typeof(string), typeof(string), typeof(string), typeof(RequestOptions))]
12-
[CodeGenSuppress("GetInputItemsAsync", typeof(string), typeof(int?), typeof(string), typeof(string), typeof(string), typeof(RequestOptions))]
1311
[CodeGenSuppress("CancelResponse", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
1412
[CodeGenSuppress("CancelResponseAsync", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]
1513
[CodeGenSuppress("GetResponse", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(RequestOptions))]

src/Custom/Responses/OpenAIResponseClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace OpenAI.Responses;
1616
[CodeGenSuppress("CreateResponse", typeof(ResponseCreationOptions), typeof(CancellationToken))]
1717
[CodeGenSuppress("GetResponse", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(CancellationToken))]
1818
[CodeGenSuppress("GetResponseAsync", typeof(string), typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(CancellationToken))]
19-
[CodeGenSuppress("GetInputItems", typeof(string), typeof(int?), typeof(OpenAI.VectorStores.VectorStoreCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
20-
[CodeGenSuppress("GetInputItemsAsync", typeof(string), typeof(int?), typeof(OpenAI.VectorStores.VectorStoreCollectionOrder?), typeof(string), typeof(string), typeof(CancellationToken))]
2119
[CodeGenSuppress("DeleteResponse", typeof(string), typeof(string), typeof(CancellationToken))]
2220
[CodeGenSuppress("DeleteResponseAsync", typeof(string), typeof(string), typeof(CancellationToken))]
2321
[CodeGenSuppress("CancelResponse", typeof(string), typeof(IEnumerable<InternalIncludable>), typeof(bool?), typeof(int?), typeof(CancellationToken))]
Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,4 @@
1-
using System.Diagnostics.CodeAnalysis;
2-
31
namespace OpenAI.Responses;
42

5-
/// <summary> The options to configure how <see cref="ResponseItem"/> objects are retrieved and paginated. </summary>
6-
[Experimental("OPENAI001")]
7-
public class ResponseItemCollectionOptions
8-
{
9-
/// <summary> Initializes a new instance of <see cref="ResponseItemCollectionOptions"/>. </summary>
10-
public ResponseItemCollectionOptions() { }
11-
12-
/// <summary>
13-
/// A limit on the number of <see cref="Response"/> objects to be returned per page.
14-
/// </summary>
15-
public int? PageSizeLimit { get; set; }
16-
17-
/// <summary>
18-
/// The order in which to retrieve <see cref="Response"/> objects when sorted by their
19-
/// <see cref="Response.CreatedAt"/> timestamp.
20-
/// </summary>
21-
public ResponseItemCollectionOrder? Order { get; set; }
22-
23-
/// <summary>
24-
/// The <see cref="Response.Id"/> used to retrieve the page of <see cref="Response"/> objects that come
25-
/// after this one.
26-
/// </summary>
27-
public string AfterId { get; set; }
28-
29-
/// <summary>
30-
/// The <see cref="Response.Id"/> used to retrieve the page of <see cref="Response"/> objects that come
31-
/// before this one.
32-
/// </summary>
33-
public string BeforeId { get; set; }
34-
}
3+
// CUSTOM: Make public and use the correct namespace.
4+
[CodeGenType("ResponseItemCollectionOptions")] public partial class ResponseItemCollectionOptions { }

0 commit comments

Comments
 (0)