-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd6712c
Add Videos API
ShivangiReja 29ee685
Add an example
ShivangiReja 8f24907
Fix examples
ShivangiReja 6ef03de
Fix
ShivangiReja a5a7ad9
Fix format
ShivangiReja 2d49298
Merge branch 'main' of https://github.com/openai/openai-dotnet into s…
ShivangiReja fb1fcba
Regen
ShivangiReja 6773a3f
fb
ShivangiReja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| 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; | ||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| import "./models.tsp"; | ||
| import "./operations.tsp"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
ContainerClient:🔗 https://github.com/openai/openai-dotnet/blob/main/api/OpenAI.net8.0.cs#L2429
This is Chris's PR:
🔗 #624
We don't need to block the release on this, so we can add it in a separate PR. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created an issue for this: #776