Skip to content

Commit 6b5b399

Browse files
committed
Add pagination support to GetVideos and GetVideosAsync in the VideoClient
1 parent 62c6ddb commit 6b5b399

16 files changed

+12011
-11569
lines changed

api/OpenAI.net8.0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6933,7 +6933,7 @@ public class VideoClient {
69336933
public virtual Task<ClientResult> DownloadVideoAsync(string videoId, string variant = null, RequestOptions options = null);
69346934
public virtual ClientResult GetVideo(string videoId, RequestOptions options = null);
69356935
public virtual Task<ClientResult> GetVideoAsync(string videoId, RequestOptions options = null);
6936-
public virtual ClientResult GetVideos(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6937-
public virtual Task<ClientResult> GetVideosAsync(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6936+
public virtual CollectionResult GetVideos(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6937+
public virtual AsyncCollectionResult GetVideosAsync(long? limit = null, string order = null, string after = null, RequestOptions options = null);
69386938
}
69396939
}

api/OpenAI.netstandard2.0.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6116,7 +6116,7 @@ public class VideoClient {
61166116
public virtual Task<ClientResult> DownloadVideoAsync(string videoId, string variant = null, RequestOptions options = null);
61176117
public virtual ClientResult GetVideo(string videoId, RequestOptions options = null);
61186118
public virtual Task<ClientResult> GetVideoAsync(string videoId, RequestOptions options = null);
6119-
public virtual ClientResult GetVideos(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6120-
public virtual Task<ClientResult> GetVideosAsync(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6119+
public virtual CollectionResult GetVideos(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6120+
public virtual AsyncCollectionResult GetVideosAsync(long? limit = null, string order = null, string after = null, RequestOptions options = null);
61216121
}
61226122
}

specification/base/typespec/videos/models.tsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ model VideoListResource {
116116
object: "list" = "list";
117117

118118
/** A list of items */
119-
data: VideoResource[];
119+
@pageItems data: VideoResource[];
120120

121121
#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
122122
#suppress "@azure-tools/typespec-azure-core/casing-style" "Auto-suppressed warnings non-applicable rules during import."
123123
#suppress "@azure-tools/typespec-azure-core/no-nullable" "Auto-suppressed warnings non-applicable rules during import."
124-
first_id: string | null;
124+
first_id: string;
125125
#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
126126
#suppress "@azure-tools/typespec-azure-core/casing-style" "Auto-suppressed warnings non-applicable rules during import."
127127
#suppress "@azure-tools/typespec-azure-core/no-nullable" "Auto-suppressed warnings non-applicable rules during import."
128-
last_id: string | null;
128+
@continuationToken last_id: string;
129129

130130
/** Whether there are more items available. */
131131
#suppress "@azure-tools/typespec-azure-core/casing-style" "Auto-suppressed warnings non-applicable rules during import."

specification/base/typespec/videos/operations.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace OpenAI;
3838
}
3939
)
4040
@tag("Videos")
41+
@list
4142
op ListVideos(
4243
/** Number of items to retrieve */
4344
#suppress "@azure-tools/typespec-azure-core/no-query-explode" "Auto-suppressed warnings non-applicable rules during import."
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import "../../base/typespec/videos/main.tsp";
2+
import "./common.models.tsp";
3+
import "@azure-tools/typespec-client-generator-core";
4+
5+
using Azure.ClientGenerator.Core;
6+
using TypeSpec.Http;
7+
8+
namespace OpenAI;
9+
10+
alias VideoItemCollectionOrderQueryParameter = {
11+
/**
12+
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending order and`desc`
13+
* for descending order.
14+
*/
15+
@query order?: VideoItemCollectionOrder;
16+
};
17+
18+
union VideoItemCollectionOrder {
19+
string,
20+
Ascending: "asc",
21+
Descending: "desc",
22+
}
23+
24+
@access(Access.public)
25+
@usage(Usage.input)
26+
model VideoItemCollectionOptions {
27+
...DotNetCollectionAfterQueryParameter,
28+
...DotNetCollectionLimitQueryParameter,
29+
...VideoItemCollectionOrderQueryParameter,
30+
}

specification/main.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ import "./client/models/containers.models.tsp";
2626
import "./client/models/conversations.models.tsp";
2727
import "./client/models/responses.models.tsp";
2828
import "./client/models/vector-stores.models.tsp";
29+
import "./client/models/videos.models.tsp";
2930

3031
import "./base/entrypoints/sdk.dotnet";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace OpenAI.Videos;
2+
3+
// CUSTOM:
4+
// - Renamed.
5+
// - Made internal until we support the convenience methods.
6+
[CodeGenType("VideoItemCollectionOptions")]
7+
internal partial class InternaVideoItemCollectionOptions
8+
{
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace OpenAI.Videos;
2+
3+
// CUSTOM:
4+
// - Renamed.
5+
// - Made internal until we support the convenience methods.
6+
[CodeGenType("VideoItemCollectionOrder")]
7+
internal readonly partial struct InternalVideoItemCollectionOrder
8+
{
9+
}

src/Generated/Models/OpenAIContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using OpenAI.Realtime;
2323
using OpenAI.Responses;
2424
using OpenAI.VectorStores;
25+
using OpenAI.Videos;
2526

2627
namespace OpenAI
2728
{
@@ -621,6 +622,7 @@ namespace OpenAI
621622
[ModelReaderWriterBuildable(typeof(InternalVectorStoreSearchResultsPage))]
622623
[ModelReaderWriterBuildable(typeof(InternalWebSearchLocation))]
623624
[ModelReaderWriterBuildable(typeof(InternalWebSearchToolCallItemParam))]
625+
[ModelReaderWriterBuildable(typeof(InternaVideoItemCollectionOptions))]
624626
[ModelReaderWriterBuildable(typeof(ItemCreatedUpdate))]
625627
[ModelReaderWriterBuildable(typeof(ItemDeletedUpdate))]
626628
[ModelReaderWriterBuildable(typeof(ItemRetrievedUpdate))]
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// <auto-generated/>
2+
3+
#nullable disable
4+
5+
using System;
6+
using System.ClientModel.Primitives;
7+
using System.Collections.Generic;
8+
using System.Text.Json;
9+
using OpenAI;
10+
11+
namespace OpenAI.Videos
12+
{
13+
internal partial class InternaVideoItemCollectionOptions : IJsonModel<InternaVideoItemCollectionOptions>
14+
{
15+
void IJsonModel<InternaVideoItemCollectionOptions>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
16+
{
17+
writer.WriteStartObject();
18+
JsonModelWriteCore(writer, options);
19+
writer.WriteEndObject();
20+
}
21+
22+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
23+
{
24+
string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format;
25+
if (format != "J")
26+
{
27+
throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support writing '{format}' format.");
28+
}
29+
// Plugin customization: remove options.Format != "W" check
30+
if (_additionalBinaryDataProperties != null)
31+
{
32+
foreach (var item in _additionalBinaryDataProperties)
33+
{
34+
if (ModelSerializationExtensions.IsSentinelValue(item.Value))
35+
{
36+
continue;
37+
}
38+
writer.WritePropertyName(item.Key);
39+
#if NET6_0_OR_GREATER
40+
writer.WriteRawValue(item.Value);
41+
#else
42+
using (JsonDocument document = JsonDocument.Parse(item.Value))
43+
{
44+
JsonSerializer.Serialize(writer, document.RootElement);
45+
}
46+
#endif
47+
}
48+
}
49+
}
50+
51+
InternaVideoItemCollectionOptions IJsonModel<InternaVideoItemCollectionOptions>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
52+
53+
protected virtual InternaVideoItemCollectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
54+
{
55+
string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format;
56+
if (format != "J")
57+
{
58+
throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support reading '{format}' format.");
59+
}
60+
using JsonDocument document = JsonDocument.ParseValue(ref reader);
61+
return DeserializeInternaVideoItemCollectionOptions(document.RootElement, options);
62+
}
63+
64+
internal static InternaVideoItemCollectionOptions DeserializeInternaVideoItemCollectionOptions(JsonElement element, ModelReaderWriterOptions options)
65+
{
66+
if (element.ValueKind == JsonValueKind.Null)
67+
{
68+
return null;
69+
}
70+
string afterId = default;
71+
int? pageSizeLimit = default;
72+
InternalVideoItemCollectionOrder? order = default;
73+
IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
74+
foreach (var prop in element.EnumerateObject())
75+
{
76+
// Plugin customization: remove options.Format != "W" check
77+
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
78+
}
79+
return new InternaVideoItemCollectionOptions(afterId, pageSizeLimit, order, additionalBinaryDataProperties);
80+
}
81+
82+
BinaryData IPersistableModel<InternaVideoItemCollectionOptions>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
83+
84+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
85+
{
86+
string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format;
87+
switch (format)
88+
{
89+
case "J":
90+
return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
91+
default:
92+
throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support writing '{options.Format}' format.");
93+
}
94+
}
95+
96+
InternaVideoItemCollectionOptions IPersistableModel<InternaVideoItemCollectionOptions>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
97+
98+
protected virtual InternaVideoItemCollectionOptions PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
99+
{
100+
string format = options.Format == "W" ? ((IPersistableModel<InternaVideoItemCollectionOptions>)this).GetFormatFromOptions(options) : options.Format;
101+
switch (format)
102+
{
103+
case "J":
104+
using (JsonDocument document = JsonDocument.Parse(data))
105+
{
106+
return DeserializeInternaVideoItemCollectionOptions(document.RootElement, options);
107+
}
108+
default:
109+
throw new FormatException($"The model {nameof(InternaVideoItemCollectionOptions)} does not support reading '{options.Format}' format.");
110+
}
111+
}
112+
113+
string IPersistableModel<InternaVideoItemCollectionOptions>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
114+
}
115+
}

0 commit comments

Comments
 (0)