-
Notifications
You must be signed in to change notification settings - Fork 342
Add protocol method support for Video APIs #772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
bd6712c
29ee685
8f24907
6ef03de
a5a7ad9
2d49298
fb1fcba
6773a3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,8 @@ public class OpenAIClient { | |
| public virtual RealtimeClient GetRealtimeClient(); | ||
| [Experimental("OPENAI001")] | ||
| public virtual VectorStoreClient GetVectorStoreClient(); | ||
| [Experimental("OPENAI001")] | ||
| public virtual Videos.VideoClient GetVideoClient(); | ||
| } | ||
| public class OpenAIClientOptions : ClientPipelineOptions { | ||
| public Uri Endpoint { get; set; } | ||
|
|
@@ -6815,4 +6817,31 @@ public enum VectorStoreStatus { | |
| Completed = 2, | ||
| Expired = 3 | ||
| } | ||
| } | ||
| namespace OpenAI.Videos { | ||
| [Experimental("OPENAI001")] | ||
| public class VideoClient { | ||
| protected VideoClient(); | ||
| public VideoClient(ApiKeyCredential credential, OpenAIClientOptions options); | ||
| public VideoClient(ApiKeyCredential credential); | ||
| public VideoClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options); | ||
| public VideoClient(AuthenticationPolicy authenticationPolicy); | ||
| protected internal VideoClient(ClientPipeline pipeline, OpenAIClientOptions options); | ||
| public VideoClient(string apiKey); | ||
| [Experimental("OPENAI001")] | ||
| public Uri Endpoint { get; } | ||
| public ClientPipeline Pipeline { get; } | ||
| public virtual ClientResult CreateVideo(BinaryContent content, string contentType, RequestOptions options = null); | ||
| public virtual Task<ClientResult> CreateVideoAsync(BinaryContent content, string contentType, RequestOptions options = null); | ||
| public virtual ClientResult CreateVideoRemix(string videoId, BinaryContent content, string contentType, RequestOptions options = null); | ||
| public virtual Task<ClientResult> CreateVideoRemixAsync(string videoId, BinaryContent content, string contentType, RequestOptions options = null); | ||
| public virtual ClientResult DeleteVideo(string videoId, RequestOptions options = null); | ||
| public virtual Task<ClientResult> DeleteVideoAsync(string videoId, RequestOptions options = null); | ||
| public virtual ClientResult GetVideo(string videoId, RequestOptions options = null); | ||
| public virtual Task<ClientResult> GetVideoAsync(string videoId, RequestOptions options = null); | ||
| public virtual ClientResult GetVideos(long? limit = null, string order = null, string after = null, RequestOptions options = null); | ||
| public virtual Task<ClientResult> GetVideosAsync(long? limit = null, string order = null, string after = null, RequestOptions options = null); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "GetVideos" and "GetVideosAsync" should implement the pagination pattern. As an example, you can take a look at the This is Chris's PR: We don't need to block the release on this, so we can add it in a separate PR. 🙂
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have created an issue for this: #776 |
||
| public virtual ClientResult RetrieveVideoContent(string videoId, string variant = null, RequestOptions options = null); | ||
| public virtual Task<ClientResult> RetrieveVideoContentAsync(string videoId, string variant = null, RequestOptions options = null); | ||
ShivangiReja marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Internal; | ||
| using OpenAI.Videos; | ||
| using System; | ||
| using System.ClientModel; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.Contracts; | ||
| using System.IO; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace OpenAI.Examples; | ||
|
|
||
| // This example uses experimental APIs which are subject to change. To use experimental APIs, | ||
| // please acknowledge their experimental status by suppressing the corresponding warning. | ||
| #pragma warning disable OPENAI001 | ||
|
|
||
| public partial class VideoExamples | ||
| { | ||
| [Test] | ||
| public void Example01_VideoCreation() | ||
| { | ||
| // 1) Create the client | ||
| VideoClient client = new(new ApiKeyCredential(Environment.GetEnvironmentVariable("OPENAI_API_KEY"))); | ||
|
|
||
| // 2) Build the multipart/form-data payload with an explicit boundary | ||
| var boundary = Guid.NewGuid().ToString(); | ||
| var contentType = $"multipart/form-data; boundary=\"{boundary}\""; | ||
| using var multipart = new MultipartFormDataContent(boundary); | ||
|
|
||
| multipart.Add(new StringContent("sora-2", Encoding.UTF8, "text/plain"), "model"); | ||
| multipart.Add(new StringContent("A calico cat playing a piano on stage", Encoding.UTF8, "text/plain"), "prompt"); | ||
|
|
||
| // 3) Get a stream for the multipart body | ||
| using var bodyStream = multipart.ReadAsStream(); | ||
|
|
||
| // 4) Send the request | ||
| var createResult = client.CreateVideo(BinaryContent.Create(bodyStream), contentType); | ||
| var createRaw = createResult.GetRawResponse().Content; | ||
|
|
||
| // 5) Parse the JSON response | ||
| using var createdDoc = JsonDocument.Parse(createRaw); | ||
| var id = createdDoc.RootElement.GetProperty("id").GetString(); | ||
| var status = createdDoc.RootElement.GetProperty("status").GetString(); | ||
|
|
||
| Console.WriteLine($"CreateVideo => id: {id}, status: {status}"); | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
|
|
||
| #pragma warning restore OPENAI001 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using NUnit.Framework; | ||
| using NUnit.Framework.Internal; | ||
| using OpenAI.Videos; | ||
| using System; | ||
| using System.ClientModel; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace OpenAI.Examples; | ||
|
|
||
| // This example uses experimental APIs which are subject to change. To use experimental APIs, | ||
| // please acknowledge their experimental status by suppressing the corresponding warning. | ||
| #pragma warning disable OPENAI001 | ||
|
|
||
| public partial class VideoExamples | ||
| { | ||
| [Test] | ||
| public async Task Example01_VideoCreationAsync() | ||
| { | ||
| // 1) Create the client | ||
| VideoClient client = new(new ApiKeyCredential(Environment.GetEnvironmentVariable("OPENAI_API_KEY"))); | ||
|
|
||
| // 2) Build the multipart/form-data payload with an explicit boundary | ||
| var boundary = Guid.NewGuid().ToString(); | ||
| var contentType = $"multipart/form-data; boundary=\"{boundary}\""; | ||
| using var multipart = new MultipartFormDataContent(boundary); | ||
|
|
||
| multipart.Add(new StringContent("sora-2", Encoding.UTF8, "text/plain"), "model"); | ||
| multipart.Add(new StringContent("A calico cat playing a piano on stage", Encoding.UTF8, "text/plain"), "prompt"); | ||
|
|
||
| // 3) Get a stream for the multipart body | ||
| using var bodyStream = await multipart.ReadAsStreamAsync(); | ||
|
|
||
| // 4) Send the request | ||
| var createResult = await client.CreateVideoAsync(BinaryContent.Create(bodyStream), contentType); | ||
| var createRaw = createResult.GetRawResponse().Content; | ||
|
|
||
| // 5) Parse the JSON response | ||
| using var createdDoc = JsonDocument.Parse(createRaw); | ||
| var id = createdDoc.RootElement.GetProperty("id").GetString(); | ||
| var status = createdDoc.RootElement.GetProperty("status").GetString(); | ||
|
|
||
| Console.WriteLine($"CreateVideo => id: {id}, status: {status}"); | ||
| } | ||
| } | ||
|
|
||
| #pragma warning restore OPENAI001 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import "./models.tsp"; | ||
| import "./operations.tsp"; |
Uh oh!
There was an error while loading. Please reload this page.