Skip to content

Commit b06f32a

Browse files
authored
Implement generated ListBatches operations (#606)
1 parent bef01b5 commit b06f32a

39 files changed

+4453
-2181
lines changed

api/OpenAI.net8.0.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,46 @@ public class BatchClient {
14031403
public virtual Task<CreateBatchOperation> CreateBatchAsync(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null);
14041404
public virtual ClientResult GetBatch(string batchId, RequestOptions options);
14051405
public virtual Task<ClientResult> GetBatchAsync(string batchId, RequestOptions options);
1406+
public virtual CollectionResult<BatchJob> GetBatches(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
14061407
public virtual CollectionResult GetBatches(string after, int? limit, RequestOptions options);
1408+
public virtual AsyncCollectionResult<BatchJob> GetBatchesAsync(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
14071409
public virtual AsyncCollectionResult GetBatchesAsync(string after, int? limit, RequestOptions options);
14081410
}
14091411
[Experimental("OPENAI001")]
1412+
public class BatchCollectionOptions : IJsonModel<BatchCollectionOptions>, IPersistableModel<BatchCollectionOptions> {
1413+
public string AfterId { get; set; }
1414+
public int? PageSizeLimit { get; set; }
1415+
protected virtual BatchCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1416+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1417+
protected virtual BatchCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1418+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1419+
}
1420+
[Experimental("OPENAI001")]
1421+
public class BatchJob : IJsonModel<BatchJob>, IPersistableModel<BatchJob> {
1422+
public DateTimeOffset? CancelledAt { get; }
1423+
public DateTimeOffset? CancellingAt { get; }
1424+
public DateTimeOffset? CompletedAt { get; }
1425+
public string CompletionWindow { get; }
1426+
public DateTimeOffset CreatedAt { get; }
1427+
public string Endpoint { get; }
1428+
public string ErrorFileId { get; }
1429+
public DateTimeOffset? ExpiredAt { get; }
1430+
public DateTimeOffset? ExpiresAt { get; }
1431+
public DateTimeOffset? FailedAt { get; }
1432+
public DateTimeOffset? FinalizingAt { get; }
1433+
public string Id { get; }
1434+
public DateTimeOffset? InProgressAt { get; }
1435+
public string InputFileId { get; }
1436+
public IDictionary<string, string> Metadata { get; }
1437+
public string Object { get; }
1438+
public string OutputFileId { get; }
1439+
protected virtual BatchJob JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1440+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1441+
public static explicit operator BatchJob(ClientResult result);
1442+
protected virtual BatchJob PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1443+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1444+
}
1445+
[Experimental("OPENAI001")]
14101446
public class CreateBatchOperation : OperationResult {
14111447
public string BatchId { get; }
14121448
public override ContinuationToken? RehydrationToken { get; protected set; }

api/OpenAI.netstandard2.0.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,9 +1262,43 @@ public class BatchClient {
12621262
public virtual Task<CreateBatchOperation> CreateBatchAsync(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null);
12631263
public virtual ClientResult GetBatch(string batchId, RequestOptions options);
12641264
public virtual Task<ClientResult> GetBatchAsync(string batchId, RequestOptions options);
1265+
public virtual CollectionResult<BatchJob> GetBatches(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
12651266
public virtual CollectionResult GetBatches(string after, int? limit, RequestOptions options);
1267+
public virtual AsyncCollectionResult<BatchJob> GetBatchesAsync(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
12661268
public virtual AsyncCollectionResult GetBatchesAsync(string after, int? limit, RequestOptions options);
12671269
}
1270+
public class BatchCollectionOptions : IJsonModel<BatchCollectionOptions>, IPersistableModel<BatchCollectionOptions> {
1271+
public string AfterId { get; set; }
1272+
public int? PageSizeLimit { get; set; }
1273+
protected virtual BatchCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1274+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1275+
protected virtual BatchCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1276+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1277+
}
1278+
public class BatchJob : IJsonModel<BatchJob>, IPersistableModel<BatchJob> {
1279+
public DateTimeOffset? CancelledAt { get; }
1280+
public DateTimeOffset? CancellingAt { get; }
1281+
public DateTimeOffset? CompletedAt { get; }
1282+
public string CompletionWindow { get; }
1283+
public DateTimeOffset CreatedAt { get; }
1284+
public string Endpoint { get; }
1285+
public string ErrorFileId { get; }
1286+
public DateTimeOffset? ExpiredAt { get; }
1287+
public DateTimeOffset? ExpiresAt { get; }
1288+
public DateTimeOffset? FailedAt { get; }
1289+
public DateTimeOffset? FinalizingAt { get; }
1290+
public string Id { get; }
1291+
public DateTimeOffset? InProgressAt { get; }
1292+
public string InputFileId { get; }
1293+
public IDictionary<string, string> Metadata { get; }
1294+
public string Object { get; }
1295+
public string OutputFileId { get; }
1296+
protected virtual BatchJob JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1297+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1298+
public static explicit operator BatchJob(ClientResult result);
1299+
protected virtual BatchJob PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1300+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1301+
}
12681302
public class CreateBatchOperation : OperationResult {
12691303
public string BatchId { get; }
12701304
public override ContinuationToken? RehydrationToken { get; protected set; }

codegen/generator/src/Visitors/PaginationVisitor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public class PaginationVisitor : ScmLibraryVisitor
4747
"GetChatCompletionMessagesAsync",
4848
("ChatCompletionMessageListDatum", "ChatCompletionMessageCollectionOptions", _paginationParamsToReplace)
4949
},
50+
{
51+
"GetBatches",
52+
("BatchJob", "BatchCollectionOptions", _paginationParamsToReplace)
53+
},
54+
{
55+
"GetBatchesAsync",
56+
("BatchJob", "BatchCollectionOptions", _paginationParamsToReplace)
57+
},
5058
{
5159
"GetVectorStores",
5260
("VectorStore", "VectorStoreCollectionOptions", _paginationParamsToReplace)

specification/base/typespec/batch/models.tsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ model BatchRequestOutput {
176176
}
177177

178178
model ListBatchesResponse {
179-
data: Batch[];
179+
@pageItems data: Batch[];
180180
first_id?: string;
181-
last_id?: string;
181+
@continuationToken last_id?: string;
182182
has_more: boolean;
183183
object: "list";
184184
}

specification/base/typespec/batch/operations.tsp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ interface Batches {
4747
@operationId("listBatches")
4848
@tag("Batch")
4949
@summary("List your organization's batches.")
50+
@list
5051
listBatches(
5152
@header accept: "application/json",
5253

@@ -55,7 +56,7 @@ interface Batches {
5556
* For instance, if you make a list request and receive 100 objects, ending with obj_foo, your
5657
* subsequent call can include after=obj_foo in order to fetch the next page of the list.
5758
*/
58-
@query after?: string,
59+
@continuationToken @query after?: string,
5960

6061
/**
6162
* A limit on the number of objects to be returned. Limit can range between 1 and 100, and the
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import "../../base/typespec/batch/main.tsp";
2+
import "@azure-tools/typespec-client-generator-core";
3+
4+
using Azure.ClientGenerator.Core;
5+
6+
namespace OpenAI;
7+
8+
@access(Access.public)
9+
@usage(Usage.input)
10+
model BatchCollectionOptions {
11+
...CollectionAfterQueryParameter,
12+
...CollectionLimitQueryParameter,
13+
}
14+
15+

specification/main.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import "./client/videos.client.tsp";
1818

1919
import "./client/models/assistants.models.tsp";
2020
import "./client/models/audio.models.tsp";
21+
import "./client/models/batch.models.tsp";
2122
import "./client/models/chat.models.tsp";
2223
import "./client/models/container.models.tsp";
2324
import "./client/models/common.models.tsp";

src/Custom/Batch/BatchClient.Protocol.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
namespace OpenAI.Batch;
88

9-
[CodeGenSuppress("GetBatches", typeof(string), typeof(int?), typeof(RequestOptions))]
10-
[CodeGenSuppress("GetBatchesAsync", typeof(string), typeof(int?), typeof(RequestOptions))]
119
public partial class BatchClient
1210
{
1311
/// <summary>
@@ -66,30 +64,4 @@ public virtual CreateBatchOperation CreateBatch(BinaryContent content, bool wait
6664
CreateBatchOperation operation = this.CreateCreateBatchOperation(batchId, status, response);
6765
return operation.WaitUntil(waitUntilCompleted, options);
6866
}
69-
70-
/// <summary>
71-
/// [Protocol Method] List your organization's batches.
72-
/// </summary>
73-
/// <param name="after"> A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. </param>
74-
/// <param name="limit"> A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. </param>
75-
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
76-
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
77-
/// <returns> The response returned from the service. </returns>
78-
public virtual AsyncCollectionResult GetBatchesAsync(string after, int? limit, RequestOptions options)
79-
{
80-
return new AsyncBatchCollectionResult(this, Pipeline, options, limit, after);
81-
}
82-
83-
/// <summary>
84-
/// [Protocol Method] List your organization's batches.
85-
/// </summary>
86-
/// <param name="after"> A cursor for use in pagination. `after` is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list. </param>
87-
/// <param name="limit"> A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. </param>
88-
/// <param name="options"> The request options, which can override default behaviors of the client pipeline on a per-call basis. </param>
89-
/// <exception cref="ClientResultException"> Service returned a non-success status code. </exception>
90-
/// <returns> The response returned from the service. </returns>
91-
public virtual CollectionResult GetBatches(string after, int? limit, RequestOptions options)
92-
{
93-
return new BatchCollectionResult(this, Pipeline, options, limit, after);
94-
}
9567
}

src/Custom/Batch/BatchClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ namespace OpenAI.Batch;
2424
[CodeGenSuppress("CancelBatchAsync", typeof(string), typeof(CancellationToken))]
2525
[CodeGenSuppress("CancelBatch", typeof(string), typeof(RequestOptions))]
2626
[CodeGenSuppress("CancelBatchAsync", typeof(string), typeof(RequestOptions))]
27-
[CodeGenSuppress("GetBatches", typeof(string), typeof(int?), typeof(CancellationToken))]
28-
[CodeGenSuppress("GetBatchesAsync", typeof(string), typeof(int?), typeof(CancellationToken))]
2927
public partial class BatchClient
3028
{
3129
// CUSTOM: Added as a convenience.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
namespace OpenAI.Batch;
2+
3+
// CUSTOM: Use the correct namespace.
4+
[CodeGenType("BatchCollectionOptions")] public partial class BatchCollectionOptions { }

0 commit comments

Comments
 (0)