Skip to content

Commit 080fc5b

Browse files
committed
wip
1 parent 9f3a94b commit 080fc5b

27 files changed

+11917
-10589
lines changed

specification/base/typespec/containers/models.tsp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ model ContainerFileListResource {
1313
object: "list";
1414

1515
/** A list of container files. */
16-
data: ContainerFileResource[];
16+
@pageItems data: ContainerFileResource[];
1717

1818
/** The ID of the first file in the list. */
1919
first_id: string;
2020

2121
/** The ID of the last file in the list. */
22-
last_id: string;
22+
@continuationToken last_id: string;
2323

2424
/** Whether there are more files available. */
2525
has_more: boolean;
@@ -59,13 +59,13 @@ model ContainerListResource {
5959
object: "list";
6060

6161
/** A list of containers. */
62-
data: ContainerResource[];
62+
@pageItems data: ContainerResource[];
6363

6464
/** The ID of the first container in the list. */
6565
first_id: string;
6666

6767
/** The ID of the last container in the list. */
68-
last_id: string;
68+
@continuationToken last_id: string;
6969

7070
/** Whether there are more containers available. */
7171
has_more: boolean;

specification/base/typespec/containers/operations.tsp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace OpenAI;
1414
interface Containers {
1515
@get
1616
@operationId("ListContainers")
17+
@list
1718
listContainers(
1819
...PageLimitQueryParameter,
1920
...PageOrderQueryParameter,
@@ -64,6 +65,7 @@ interface Containers {
6465
@get
6566
@route("{container_id}/files")
6667
@operationId("ListContainerFiles")
68+
@list
6769
listContainerFiles(
6870
@path
6971
container_id: string,

specification/client/containers.client.tsp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import "@azure-tools/typespec-client-generator-core";
44
using OpenAI;
55
using Azure.ClientGenerator.Core;
66

7-
@@convenientAPI(Containers.listContainers, false);
87
@@convenientAPI(Containers.createContainer, false);
98
@@convenientAPI(Containers.retrieveContainer, false);
109
@@convenientAPI(Containers.deleteContainer, false);
1110
@@convenientAPI(Containers.createContainerFile, false);
12-
@@convenientAPI(Containers.listContainerFiles, false);
1311
@@convenientAPI(Containers.retrieveContainerFile, false);
1412
@@convenientAPI(Containers.deleteContainerFile, false);
1513
@@convenientAPI(Containers.retrieveContainerFileContent, false);

specification/client/models/chat.models.tsp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,47 @@ model ChatCompletionCollectionOptions {
3131
@query `model`?: string,
3232
}
3333

34-
alias ChatCompletionMessageCollectionOrderQueryParameter = {
34+
alias ContainerCollectionOrderQueryParameter = {
3535
/**
3636
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
3737
* for descending order.
3838
*/
39-
@query order?: ChatCompletionMessageCollectionOrder;
39+
@query order?: ContainerCollectionOrder;
4040
};
4141

42-
union ChatCompletionMessageCollectionOrder {
42+
union ContainerCollectionOrder {
4343
string,
4444
Ascending: "asc",
4545
Descending: "desc",
4646
}
4747

4848
@access(Access.public)
4949
@usage(Usage.input)
50-
model ChatCompletionMessageCollectionOptions {
50+
model ContainerCollectionOptions {
5151
...CollectionAfterQueryParameter,
5252
...CollectionLimitQueryParameter,
53-
...ChatCompletionMessageCollectionOrderQueryParameter,
53+
...ContainerCollectionOrderQueryParameter,
5454
}
5555

56+
alias ContainerFileCollectionOrderQueryParameter = {
57+
/**
58+
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
59+
* for descending order.
60+
*/
61+
@query order?: ContainerCollectionOrder;
62+
};
63+
64+
union ContainerFileCollectionOrder {
65+
string,
66+
Ascending: "asc",
67+
Descending: "desc",
68+
}
69+
70+
@access(Access.public)
71+
@usage(Usage.input)
72+
model ContainerFileCollectionOptions {
73+
...CollectionAfterQueryParameter,
74+
...CollectionLimitQueryParameter,
75+
...ContainerFileCollectionOrderQueryParameter,
76+
}
5677

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import "../../base/typespec/containers/main.tsp";
2+
import "@azure-tools/typespec-client-generator-core";
3+
4+
using Azure.ClientGenerator.Core;
5+
using TypeSpec.Http;
6+
7+
namespace OpenAI;
8+
9+
alias ChatCompletionMessageCollectionOrderQueryParameter = {
10+
/**
11+
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
12+
* for descending order.
13+
*/
14+
@query order?: ChatCompletionMessageCollectionOrder;
15+
};
16+
17+
union ChatCompletionMessageCollectionOrder {
18+
string,
19+
Ascending: "asc",
20+
Descending: "desc",
21+
}
22+
23+
@access(Access.public)
24+
@usage(Usage.input)
25+
model ChatCompletionMessageCollectionOptions {
26+
...CollectionAfterQueryParameter,
27+
...CollectionLimitQueryParameter,
28+
...ChatCompletionMessageCollectionOrderQueryParameter,
29+
}

specification/main.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import "./client/vector-stores.client.tsp";
1616

1717
import "./client/models/audio.models.tsp";
1818
import "./client/models/chat.models.tsp";
19+
import "./client/models/container.models.tsp";
1920
import "./client/models/common.models.tsp";
2021
import "./client/models/responses.models.tsp";
2122
import "./client/models/vector-stores.models.tsp";
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace OpenAI.Containers;
22

3-
[CodeGenType("ContainerListResource")] public partial class ContainerListResource { }
3+
// [CodeGenType("ContainerListResource")] public partial class ContainerListResource { }
44
[CodeGenType("ContainerResource")] public partial class ContainerResource { }
55
[CodeGenType("ContainerResourceExpiresAfter")] public partial class ContainerResourceExpiresAfter { }
66
[CodeGenType("CreateContainerBody")] public partial class CreateContainerBody { }
77
[CodeGenType("CreateContainerBodyExpiresAfter")] public partial class CreateContainerBodyExpiresAfter { }
88
[CodeGenType("DeleteContainerResponse")] public partial class DeleteContainerResponse { }
99
[CodeGenType("CreateContainerFileBody")] public partial class CreateContainerFileBody { }
1010
[CodeGenType("ContainerFileResource")] public partial class ContainerFileResource { }
11-
[CodeGenType("ContainerFileListResource")] public partial class ContainerFileListResource { }
11+
// [CodeGenType("ContainerFileListResource")] public partial class ContainerFileListResource { }
1212
[CodeGenType("DeleteContainerFileResponse")] public partial class DeleteContainerFileResponse { }

src/Generated/ContainerClient.cs

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
using System.ClientModel;
77
using System.ClientModel.Primitives;
88
using System.Diagnostics.CodeAnalysis;
9+
using System.Threading;
910
using System.Threading.Tasks;
1011
using OpenAI;
12+
using OpenAI.VectorStores;
1113

1214
namespace OpenAI.Containers
1315
{
@@ -22,16 +24,24 @@ protected ContainerClient()
2224

2325
public ClientPipeline Pipeline { get; }
2426

25-
public virtual ClientResult GetContainers(int? limit = default, string order = default, string after = default, RequestOptions options = null)
27+
public virtual CollectionResult GetContainers(int? limit, string order, string after, RequestOptions options)
2628
{
27-
using PipelineMessage message = CreateGetContainersRequest(limit, order, after, options);
28-
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
29+
return new ContainerClientGetContainersCollectionResult(this, limit, order, after, options);
2930
}
3031

31-
public virtual async Task<ClientResult> GetContainersAsync(int? limit = default, string order = default, string after = default, RequestOptions options = null)
32+
public virtual AsyncCollectionResult GetContainersAsync(int? limit, string order, string after, RequestOptions options)
3233
{
33-
using PipelineMessage message = CreateGetContainersRequest(limit, order, after, options);
34-
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
34+
return new ContainerClientGetContainersAsyncCollectionResult(this, limit, order, after, options);
35+
}
36+
37+
public virtual CollectionResult<ContainerResource> GetContainers(int? limit = default, VectorStoreCollectionOrder? order = default, string after = default, CancellationToken cancellationToken = default)
38+
{
39+
return new ContainerClientGetContainersCollectionResultOfT(this, limit, order?.ToString(), after, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
40+
}
41+
42+
public virtual AsyncCollectionResult<ContainerResource> GetContainersAsync(int? limit = default, VectorStoreCollectionOrder? order = default, string after = default, CancellationToken cancellationToken = default)
43+
{
44+
return new ContainerClientGetContainersAsyncCollectionResultOfT(this, limit, order?.ToString(), after, cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
3545
}
3646

3747
public virtual ClientResult CreateContainer(BinaryContent content, RequestOptions options = null)
@@ -100,20 +110,56 @@ public virtual async Task<ClientResult> CreateContainerFileAsync(string containe
100110
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
101111
}
102112

103-
public virtual ClientResult GetContainerFiles(string containerId, int? limit = default, string order = default, string after = default, RequestOptions options = null)
113+
public virtual CollectionResult GetContainerFiles(string containerId, int? limit, string order, string after, RequestOptions options)
104114
{
105115
Argument.AssertNotNullOrEmpty(containerId, nameof(containerId));
106116

107-
using PipelineMessage message = CreateGetContainerFilesRequest(containerId, limit, order, after, options);
108-
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
117+
return new ContainerClientGetContainerFilesCollectionResult(
118+
this,
119+
containerId,
120+
limit,
121+
order,
122+
after,
123+
options);
109124
}
110125

111-
public virtual async Task<ClientResult> GetContainerFilesAsync(string containerId, int? limit = default, string order = default, string after = default, RequestOptions options = null)
126+
public virtual AsyncCollectionResult GetContainerFilesAsync(string containerId, int? limit, string order, string after, RequestOptions options)
112127
{
113128
Argument.AssertNotNullOrEmpty(containerId, nameof(containerId));
114129

115-
using PipelineMessage message = CreateGetContainerFilesRequest(containerId, limit, order, after, options);
116-
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
130+
return new ContainerClientGetContainerFilesAsyncCollectionResult(
131+
this,
132+
containerId,
133+
limit,
134+
order,
135+
after,
136+
options);
137+
}
138+
139+
public virtual CollectionResult<ContainerFileResource> GetContainerFiles(string containerId, int? limit = default, VectorStoreCollectionOrder? order = default, string after = default, CancellationToken cancellationToken = default)
140+
{
141+
Argument.AssertNotNullOrEmpty(containerId, nameof(containerId));
142+
143+
return new ContainerClientGetContainerFilesCollectionResultOfT(
144+
this,
145+
containerId,
146+
limit,
147+
order?.ToString(),
148+
after,
149+
cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
150+
}
151+
152+
public virtual AsyncCollectionResult<ContainerFileResource> GetContainerFilesAsync(string containerId, int? limit = default, VectorStoreCollectionOrder? order = default, string after = default, CancellationToken cancellationToken = default)
153+
{
154+
Argument.AssertNotNullOrEmpty(containerId, nameof(containerId));
155+
156+
return new ContainerClientGetContainerFilesAsyncCollectionResultOfT(
157+
this,
158+
containerId,
159+
limit,
160+
order?.ToString(),
161+
after,
162+
cancellationToken.CanBeCanceled ? new RequestOptions { CancellationToken = cancellationToken } : null);
117163
}
118164

119165
public virtual ClientResult GetContainerFile(string containerId, string fileId, RequestOptions options = null)
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.Containers
12+
{
13+
internal partial class ContainerClientGetContainerFilesAsyncCollectionResult : AsyncCollectionResult
14+
{
15+
private readonly ContainerClient _client;
16+
private readonly string _containerId;
17+
private readonly int? _limit;
18+
private readonly string _order;
19+
private readonly string _after;
20+
private readonly RequestOptions _options;
21+
22+
public ContainerClientGetContainerFilesAsyncCollectionResult(ContainerClient client, string containerId, int? limit, string order, string after, RequestOptions options)
23+
{
24+
Argument.AssertNotNullOrEmpty(containerId, nameof(containerId));
25+
26+
_client = client;
27+
_containerId = containerId;
28+
_limit = limit;
29+
_order = order;
30+
_after = after;
31+
_options = options;
32+
}
33+
34+
public override async IAsyncEnumerable<ClientResult> GetRawPagesAsync()
35+
{
36+
PipelineMessage message = _client.CreateGetContainerFilesRequest(_containerId, _limit, _order, _after, _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 = ((ContainerFileListResource)result).HasMore;
45+
nextToken = ((ContainerFileListResource)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.CreateGetContainerFilesRequest(_containerId, _limit, _order, nextToken, _options);
52+
}
53+
}
54+
55+
public override ContinuationToken GetContinuationToken(ClientResult page)
56+
{
57+
string nextPage = ((ContainerFileListResource)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)