Skip to content

Commit 29ee685

Browse files
committed
Add an example
1 parent bd6712c commit 29ee685

File tree

10 files changed

+144
-44
lines changed

10 files changed

+144
-44
lines changed

api/OpenAI.net8.0.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class OpenAIClient {
3838
[Experimental("OPENAI001")]
3939
public virtual VectorStoreClient GetVectorStoreClient();
4040
[Experimental("OPENAI001")]
41-
public virtual Videos.VideosClient GetVideosClient();
41+
public virtual Videos.VideoClient GetVideoClient();
4242
}
4343
public class OpenAIClientOptions : ClientPipelineOptions {
4444
public Uri Endpoint { get; set; }
@@ -6820,14 +6820,14 @@ public enum VectorStoreStatus {
68206820
}
68216821
namespace OpenAI.Videos {
68226822
[Experimental("OPENAI001")]
6823-
public class VideosClient {
6824-
protected VideosClient();
6825-
public VideosClient(ApiKeyCredential credential, OpenAIClientOptions options);
6826-
public VideosClient(ApiKeyCredential credential);
6827-
public VideosClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options);
6828-
public VideosClient(AuthenticationPolicy authenticationPolicy);
6829-
protected internal VideosClient(ClientPipeline pipeline, OpenAIClientOptions options);
6830-
public VideosClient(string apiKey);
6823+
public class VideoClient {
6824+
protected VideoClient();
6825+
public VideoClient(ApiKeyCredential credential, OpenAIClientOptions options);
6826+
public VideoClient(ApiKeyCredential credential);
6827+
public VideoClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options);
6828+
public VideoClient(AuthenticationPolicy authenticationPolicy);
6829+
protected internal VideoClient(ClientPipeline pipeline, OpenAIClientOptions options);
6830+
public VideoClient(string apiKey);
68316831
[Experimental("OPENAI001")]
68326832
public Uri Endpoint { get; }
68336833
public ClientPipeline Pipeline { get; }

api/OpenAI.netstandard2.0.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class OpenAIClient {
2525
public virtual OpenAIResponseClient GetOpenAIResponseClient(string model);
2626
public virtual RealtimeClient GetRealtimeClient();
2727
public virtual VectorStoreClient GetVectorStoreClient();
28-
public virtual Videos.VideosClient GetVideosClient();
28+
public virtual Videos.VideoClient GetVideoClient();
2929
}
3030
public class OpenAIClientOptions : ClientPipelineOptions {
3131
public Uri Endpoint { get; set; }
@@ -6010,14 +6010,14 @@ public enum VectorStoreStatus {
60106010
}
60116011
}
60126012
namespace OpenAI.Videos {
6013-
public class VideosClient {
6014-
protected VideosClient();
6015-
public VideosClient(ApiKeyCredential credential, OpenAIClientOptions options);
6016-
public VideosClient(ApiKeyCredential credential);
6017-
public VideosClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options);
6018-
public VideosClient(AuthenticationPolicy authenticationPolicy);
6019-
protected internal VideosClient(ClientPipeline pipeline, OpenAIClientOptions options);
6020-
public VideosClient(string apiKey);
6013+
public class VideoClient {
6014+
protected VideoClient();
6015+
public VideoClient(ApiKeyCredential credential, OpenAIClientOptions options);
6016+
public VideoClient(ApiKeyCredential credential);
6017+
public VideoClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options);
6018+
public VideoClient(AuthenticationPolicy authenticationPolicy);
6019+
protected internal VideoClient(ClientPipeline pipeline, OpenAIClientOptions options);
6020+
public VideoClient(string apiKey);
60216021
public Uri Endpoint { get; }
60226022
public ClientPipeline Pipeline { get; }
60236023
public virtual ClientResult CreateVideo(BinaryContent content, string contentType, RequestOptions options = null);

examples/OpenAI.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net9.0</TargetFramework>
44

examples/VectorStore/Example01_VectorStoreCreationAsync.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System;
66
using System.ClientModel;
77
using System.Collections.Generic;
8-
using System.Threading;
98
using System.Threading.Tasks;
109

1110
namespace OpenAI.Examples;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using NUnit.Framework;
2+
using NUnit.Framework.Internal;
3+
using OpenAI.Videos;
4+
using System;
5+
using System.ClientModel;
6+
using System.Collections.Generic;
7+
using System.Diagnostics.Contracts;
8+
using System.IO;
9+
using System.Net.Http;
10+
using System.Text;
11+
using System.Text.Json;
12+
using System.Threading.Tasks;
13+
14+
namespace OpenAI.Examples;
15+
16+
// This example uses experimental APIs which are subject to change. To use experimental APIs,
17+
// please acknowledge their experimental status by suppressing the corresponding warning.
18+
#pragma warning disable OPENAI001
19+
20+
public partial class VectorStoreExamples
21+
{
22+
[Test]
23+
public void Example01_SimpleVideoCreation()
24+
{
25+
// 1) Create the client
26+
VideoClient client = new(new ApiKeyCredential(Environment.GetEnvironmentVariable("OPENAI_API_KEY")));
27+
28+
// 2) Build the multipart/form-data payload with an explicit boundary
29+
var boundary = Guid.NewGuid().ToString();
30+
var contentType = $"multipart/form-data; boundary=\"{boundary}\"";
31+
using var multipart = new MultipartFormDataContent(boundary);
32+
33+
multipart.Add(new StringContent("sora-2", Encoding.UTF8, "text/plain"), "model");
34+
multipart.Add(new StringContent("A calico cat playing a piano on stage", Encoding.UTF8, "text/plain"), "prompt");
35+
36+
// 3) Get a stream for the multipart body
37+
using var bodyStream = multipart.ReadAsStream();
38+
39+
// 4) Send the request
40+
var createResult = client.CreateVideo(BinaryContent.Create(bodyStream), contentType);
41+
var createRaw = createResult.GetRawResponse().Content;
42+
43+
// 5) Parse the JSON response
44+
using var createdDoc = JsonDocument.Parse(createRaw);
45+
var id = createdDoc.RootElement.GetProperty("id").GetString();
46+
var status = createdDoc.RootElement.GetProperty("status").GetString();
47+
48+
Console.WriteLine($"CreateVideo => id: {id}, status: {status}");
49+
}
50+
}
51+
52+
#pragma warning restore OPENAI001
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using NUnit.Framework;
2+
using NUnit.Framework.Internal;
3+
using OpenAI.Videos;
4+
using System;
5+
using System.ClientModel;
6+
using System.Net.Http;
7+
using System.Text;
8+
using System.Text.Json;
9+
using System.Threading.Tasks;
10+
11+
namespace OpenAI.Examples;
12+
13+
// This example uses experimental APIs which are subject to change. To use experimental APIs,
14+
// please acknowledge their experimental status by suppressing the corresponding warning.
15+
#pragma warning disable OPENAI001
16+
17+
public partial class VectorStoreExamples
18+
{
19+
[Test]
20+
public async Task Example01_SimpleVideoCreationAsync()
21+
{
22+
// 1) Create the client
23+
VideoClient client = new(new ApiKeyCredential(Environment.GetEnvironmentVariable("OPENAI_API_KEY")));
24+
25+
// 2) Build the multipart/form-data payload with an explicit boundary
26+
var boundary = Guid.NewGuid().ToString();
27+
var contentType = $"multipart/form-data; boundary=\"{boundary}\"";
28+
using var multipart = new MultipartFormDataContent(boundary);
29+
30+
multipart.Add(new StringContent("sora-2", Encoding.UTF8, "text/plain"), "model");
31+
multipart.Add(new StringContent("A calico cat playing a piano on stage", Encoding.UTF8, "text/plain"), "prompt");
32+
33+
// 3) Get a stream for the multipart body
34+
using var bodyStream = await multipart.ReadAsStreamAsync();
35+
36+
// 4) Send the request
37+
var createResult = await client.CreateVideoAsync(BinaryContent.Create(bodyStream), contentType);
38+
var createRaw = createResult.GetRawResponse().Content;
39+
40+
// 5) Parse the JSON response
41+
using var createdDoc = JsonDocument.Parse(createRaw);
42+
var id = createdDoc.RootElement.GetProperty("id").GetString();
43+
var status = createdDoc.RootElement.GetProperty("status").GetString();
44+
45+
Console.WriteLine($"CreateVideo => id: {id}, status: {status}");
46+
}
47+
}
48+
49+
#pragma warning restore OPENAI001

src/Custom/OpenAIClient.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace OpenAI;
5050
[CodeGenSuppress("_cachedRealtimeClient")]
5151
[CodeGenSuppress("_cachedOpenAIResponseClient")]
5252
[CodeGenSuppress("_cachedVectorStoreClient")]
53-
[CodeGenSuppress("_cachedVideosClient")]
53+
[CodeGenSuppress("_cachedVideoClient")]
5454
[CodeGenSuppress("_cachedInternalAssistantMessageClient")]
5555
[CodeGenSuppress("_cachedInternalAssistantRunClient")]
5656
[CodeGenSuppress("_cachedInternalAssistantThreadClient")]
@@ -72,7 +72,7 @@ namespace OpenAI;
7272
[CodeGenSuppress("GetRealtimeClient")]
7373
[CodeGenSuppress("GetOpenAIResponseClient")]
7474
[CodeGenSuppress("GetVectorStoreClient")]
75-
[CodeGenSuppress("GetVideosClient")]
75+
[CodeGenSuppress("GetVideoClient")]
7676
[CodeGenSuppress("GetInternalAssistantMessageClient")]
7777
[CodeGenSuppress("GetInternalAssistantRunClient")]
7878
[CodeGenSuppress("GetInternalAssistantThreadClient")]
@@ -344,19 +344,19 @@ protected internal OpenAIClient(ClientPipeline pipeline, OpenAIClientOptions opt
344344
[Experimental("OPENAI001")]
345345
public virtual ContainerClient GetContainerClient() => new(Pipeline, _options);
346346

347-
internal static AuthenticationPolicy CreateApiKeyAuthenticationPolicy(ApiKeyCredential credential)
348-
{
349-
Argument.AssertNotNull(credential, nameof(credential));
350-
return ApiKeyAuthenticationPolicy.CreateHeaderApiKeyPolicy(credential, AuthorizationHeader, AuthorizationApiKeyPrefix);
351-
}
352-
353347
/// <summary>
354-
/// Gets a new instance of <see cref="VideosClient"/> that reuses the client configuration details provided to
348+
/// Gets a new instance of <see cref="VideoClient"/> that reuses the client configuration details provided to
355349
/// the <see cref="OpenAIClient"/> instance.
356350
/// </summary>
357351
/// <returns></returns>
358352
[Experimental("OPENAI001")]
359-
public virtual VideosClient GetVideosClient() => new(Pipeline, _options);
353+
public virtual VideoClient GetVideoClient() => new(Pipeline, _options);
354+
355+
internal static AuthenticationPolicy CreateApiKeyAuthenticationPolicy(ApiKeyCredential credential)
356+
{
357+
Argument.AssertNotNull(credential, nameof(credential));
358+
return ApiKeyAuthenticationPolicy.CreateHeaderApiKeyPolicy(credential, AuthorizationHeader, AuthorizationApiKeyPrefix);
359+
}
360360

361361
internal static ClientPipeline CreatePipeline(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options)
362362
{

src/Custom/Videos/VideosClient.cs renamed to src/Custom/Videos/VideoClient.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,43 @@ namespace OpenAI.Videos;
1111
// - Suppressed methods that only take the options parameter.
1212
/// <summary> The service client for OpenAI video operations. </summary>
1313
[CodeGenType("Videos")]
14-
[CodeGenSuppress("VideosClient", typeof(ClientPipeline), typeof(Uri))]
15-
public partial class VideosClient
14+
[CodeGenSuppress("VideoClient", typeof(ClientPipeline), typeof(Uri))]
15+
public partial class VideoClient
1616
{
1717
// CUSTOM: Added as a convenience.
18-
/// <summary> Initializes a new instance of <see cref="VideosClient"/>. </summary>
18+
/// <summary> Initializes a new instance of <see cref="VideoClient"/>. </summary>
1919
/// <param name="apiKey"> The API key to authenticate with the service. </param>
2020
/// <exception cref="ArgumentNullException"> <paramref name="apiKey"/> is null. </exception>
21-
public VideosClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions())
21+
public VideoClient(string apiKey) : this(new ApiKeyCredential(apiKey), new OpenAIClientOptions())
2222
{
2323
}
2424

2525
// CUSTOM:
2626
// - Used a custom pipeline.
2727
// - Demoted the endpoint parameter to be a property in the options class.
28-
/// <summary> Initializes a new instance of <see cref="VideosClient"/>. </summary>
28+
/// <summary> Initializes a new instance of <see cref="VideoClient"/>. </summary>
2929
/// <param name="credential"> The <see cref="ApiKeyCredential"/> to authenticate with the service. </param>
3030
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
31-
public VideosClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions())
31+
public VideoClient(ApiKeyCredential credential) : this(credential, new OpenAIClientOptions())
3232
{
3333
}
3434

3535
// CUSTOM:
3636
// - Used a custom pipeline.
3737
// - Demoted the endpoint parameter to be a property in the options class.
38-
/// <summary> Initializes a new instance of <see cref="VideosClient"/>. </summary>
38+
/// <summary> Initializes a new instance of <see cref="VideoClient"/>. </summary>
3939
/// <param name="credential"> The <see cref="ApiKeyCredential"/> to authenticate with the service. </param>
4040
/// <param name="options"> The options to configure the client. </param>
4141
/// <exception cref="ArgumentNullException"> <paramref name="credential"/> is null. </exception>
42-
public VideosClient(ApiKeyCredential credential, OpenAIClientOptions options) : this(OpenAIClient.CreateApiKeyAuthenticationPolicy(credential), options)
42+
public VideoClient(ApiKeyCredential credential, OpenAIClientOptions options) : this(OpenAIClient.CreateApiKeyAuthenticationPolicy(credential), options)
4343
{
4444
}
4545

4646
// CUSTOM: Added as a convenience.
4747
/// <summary> Initializes a new instance of <see cref="GraderClient"/>. </summary>
4848
/// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param>
4949
/// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception>
50-
public VideosClient(AuthenticationPolicy authenticationPolicy) : this(authenticationPolicy, new OpenAIClientOptions())
50+
public VideoClient(AuthenticationPolicy authenticationPolicy) : this(authenticationPolicy, new OpenAIClientOptions())
5151
{
5252
}
5353

@@ -56,7 +56,7 @@ public VideosClient(ApiKeyCredential credential, OpenAIClientOptions options) :
5656
/// <param name="authenticationPolicy"> The authentication policy used to authenticate with the service. </param>
5757
/// <param name="options"> The options to configure the client. </param>
5858
/// <exception cref="ArgumentNullException"> <paramref name="authenticationPolicy"/> is null. </exception>
59-
public VideosClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options)
59+
public VideoClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options)
6060
{
6161
Argument.AssertNotNull(authenticationPolicy, nameof(authenticationPolicy));
6262
options ??= new OpenAIClientOptions();
@@ -73,7 +73,7 @@ public VideosClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptio
7373
/// <param name="pipeline"> The HTTP pipeline to send and receive REST requests and responses. </param>
7474
/// <param name="options"> The options to configure the client. </param>
7575
/// <exception cref="ArgumentNullException"> <paramref name="pipeline"/> is null. </exception>
76-
protected internal VideosClient(ClientPipeline pipeline, OpenAIClientOptions options)
76+
protected internal VideoClient(ClientPipeline pipeline, OpenAIClientOptions options)
7777
{
7878
Argument.AssertNotNull(pipeline, nameof(pipeline));
7979
options ??= new OpenAIClientOptions();

src/Generated/VideosClient.RestClient.cs renamed to src/Generated/VideoClient.RestClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace OpenAI.Videos
1010
{
11-
public partial class VideosClient
11+
public partial class VideoClient
1212
{
1313
private static PipelineMessageClassifier _pipelineMessageClassifier200;
1414

src/Generated/VideosClient.cs renamed to src/Generated/VideoClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
namespace OpenAI.Videos
1313
{
1414
[Experimental("OPENAI001")]
15-
public partial class VideosClient
15+
public partial class VideoClient
1616
{
1717
private readonly Uri _endpoint;
1818

19-
protected VideosClient()
19+
protected VideoClient()
2020
{
2121
}
2222

0 commit comments

Comments
 (0)