Skip to content

Commit 3717e42

Browse files
committed
Implement generated ListBatches operations
1 parent ff21e64 commit 3717e42

26 files changed

+2625
-1866
lines changed

api/OpenAI.net8.0.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,10 +1355,45 @@ public class BatchClient {
13551355
public virtual Task<CreateBatchOperation> CreateBatchAsync(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null);
13561356
public virtual ClientResult GetBatch(string batchId, RequestOptions options);
13571357
public virtual Task<ClientResult> GetBatchAsync(string batchId, RequestOptions options);
1358+
public virtual CollectionResult<BatchJob> GetBatches(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
13581359
public virtual CollectionResult GetBatches(string after, int? limit, RequestOptions options);
1360+
public virtual AsyncCollectionResult<BatchJob> GetBatchesAsync(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
13591361
public virtual AsyncCollectionResult GetBatchesAsync(string after, int? limit, RequestOptions options);
13601362
}
13611363
[Experimental("OPENAI001")]
1364+
public class BatchCollectionOptions : IJsonModel<BatchCollectionOptions>, IPersistableModel<BatchCollectionOptions> {
1365+
public string AfterId { get; set; }
1366+
public int? PageSizeLimit { get; set; }
1367+
protected virtual BatchCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1368+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1369+
protected virtual BatchCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1370+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1371+
}
1372+
[Experimental("OPENAI001")]
1373+
public class BatchJob : IJsonModel<BatchJob>, IPersistableModel<BatchJob> {
1374+
public DateTimeOffset? CancelledAt { get; }
1375+
public DateTimeOffset? CancellingAt { get; }
1376+
public DateTimeOffset? CompletedAt { get; }
1377+
public string CompletionWindow { get; }
1378+
public DateTimeOffset CreatedAt { get; }
1379+
public string Endpoint { get; }
1380+
public string ErrorFileId { get; }
1381+
public DateTimeOffset? ExpiredAt { get; }
1382+
public DateTimeOffset? ExpiresAt { get; }
1383+
public DateTimeOffset? FailedAt { get; }
1384+
public DateTimeOffset? FinalizingAt { get; }
1385+
public string Id { get; }
1386+
public DateTimeOffset? InProgressAt { get; }
1387+
public string InputFileId { get; }
1388+
public IDictionary<string, string> Metadata { get; }
1389+
public string Object { get; }
1390+
public string OutputFileId { get; }
1391+
protected virtual BatchJob JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1392+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1393+
protected virtual BatchJob PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1394+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1395+
}
1396+
[Experimental("OPENAI001")]
13621397
public class CreateBatchOperation : OperationResult {
13631398
public string BatchId { get; }
13641399
public override ContinuationToken? RehydrationToken { get; protected set; }

api/OpenAI.netstandard2.0.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,9 +1221,42 @@ public class BatchClient {
12211221
public virtual Task<CreateBatchOperation> CreateBatchAsync(BinaryContent content, bool waitUntilCompleted, RequestOptions options = null);
12221222
public virtual ClientResult GetBatch(string batchId, RequestOptions options);
12231223
public virtual Task<ClientResult> GetBatchAsync(string batchId, RequestOptions options);
1224+
public virtual CollectionResult<BatchJob> GetBatches(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
12241225
public virtual CollectionResult GetBatches(string after, int? limit, RequestOptions options);
1226+
public virtual AsyncCollectionResult<BatchJob> GetBatchesAsync(BatchCollectionOptions options = null, CancellationToken cancellationToken = default);
12251227
public virtual AsyncCollectionResult GetBatchesAsync(string after, int? limit, RequestOptions options);
12261228
}
1229+
public class BatchCollectionOptions : IJsonModel<BatchCollectionOptions>, IPersistableModel<BatchCollectionOptions> {
1230+
public string AfterId { get; set; }
1231+
public int? PageSizeLimit { get; set; }
1232+
protected virtual BatchCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1233+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1234+
protected virtual BatchCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1235+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1236+
}
1237+
public class BatchJob : IJsonModel<BatchJob>, IPersistableModel<BatchJob> {
1238+
public DateTimeOffset? CancelledAt { get; }
1239+
public DateTimeOffset? CancellingAt { get; }
1240+
public DateTimeOffset? CompletedAt { get; }
1241+
public string CompletionWindow { get; }
1242+
public DateTimeOffset CreatedAt { get; }
1243+
public string Endpoint { get; }
1244+
public string ErrorFileId { get; }
1245+
public DateTimeOffset? ExpiredAt { get; }
1246+
public DateTimeOffset? ExpiresAt { get; }
1247+
public DateTimeOffset? FailedAt { get; }
1248+
public DateTimeOffset? FinalizingAt { get; }
1249+
public string Id { get; }
1250+
public DateTimeOffset? InProgressAt { get; }
1251+
public string InputFileId { get; }
1252+
public IDictionary<string, string> Metadata { get; }
1253+
public string Object { get; }
1254+
public string OutputFileId { get; }
1255+
protected virtual BatchJob JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
1256+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
1257+
protected virtual BatchJob PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
1258+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
1259+
}
12271260
public class CreateBatchOperation : OperationResult {
12281261
public string BatchId { get; }
12291262
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
@@ -45,6 +45,14 @@ public class PaginationVisitor : ScmLibraryVisitor
4545
{
4646
"GetChatCompletionMessagesAsync",
4747
("ChatCompletionMessageListDatum", "ChatCompletionMessageCollectionOptions", _chatParamsToReplace)
48+
},
49+
{
50+
"GetBatches",
51+
("BatchJob", "BatchCollectionOptions", _chatParamsToReplace)
52+
},
53+
{
54+
"GetBatchesAsync",
55+
("BatchJob", "BatchCollectionOptions", _chatParamsToReplace)
4856
}
4957
};
5058

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
@@ -15,6 +15,7 @@ import "./client/threads.client.tsp";
1515
import "./client/vector-stores.client.tsp";
1616

1717
import "./client/models/audio.models.tsp";
18+
import "./client/models/batch.models.tsp";
1819
import "./client/models/chat.models.tsp";
1920
import "./client/models/common.models.tsp";
2021
import "./client/models/responses.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)