forked from RageAgainstThePixel/OpenAI-DotNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OpenAI-DotNet 6.6.0 (RageAgainstThePixel#77)
- Added [`response_format`](https://platform.openai.com/docs/api-reference/images/create#images/create-response_format) to `ImageGenerationRequest` - Refactored Image Requests with AbstractBaseImageRequest --------- Co-authored-by: John Korsnes <[email protected]>
- Loading branch information
1 parent
40c3fc2
commit 841802f
Showing
9 changed files
with
307 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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 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,76 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenAI.Images | ||
{ | ||
/// <summary> | ||
/// Abstract base image class for making requests. | ||
/// </summary> | ||
public abstract class AbstractBaseImageRequest | ||
{ | ||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
/// <param name="numberOfResults"> | ||
/// The number of images to generate. Must be between 1 and 10. | ||
/// </param> | ||
/// <param name="size"> | ||
/// The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024. | ||
/// </param> | ||
/// <param name="user"> | ||
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. | ||
/// </param> | ||
/// <param name="responseFormat"> | ||
/// The format in which the generated images are returned. | ||
/// Must be one of url or b64_json. | ||
/// <para/> Defaults to <see cref="Images.ResponseFormat.Url"/> | ||
/// </param> | ||
/// <exception cref="ArgumentOutOfRangeException"></exception> | ||
protected AbstractBaseImageRequest(int numberOfResults = 1, ImageSize size = ImageSize.Large, ResponseFormat responseFormat = Images.ResponseFormat.Url, string user = null) | ||
{ | ||
Number = numberOfResults; | ||
|
||
Size = size switch | ||
{ | ||
ImageSize.Small => "256x256", | ||
ImageSize.Medium => "512x512", | ||
ImageSize.Large => "1024x1024", | ||
_ => throw new ArgumentOutOfRangeException(nameof(size), size, null) | ||
}; | ||
|
||
User = user; | ||
ResponseFormat = responseFormat switch | ||
{ | ||
Images.ResponseFormat.Url => "url", | ||
Images.ResponseFormat.B64_Json => "b64_json", | ||
_ => throw new ArgumentOutOfRangeException(nameof(responseFormat), responseFormat, null) | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// The number of images to generate. Must be between 1 and 10. | ||
/// </summary> | ||
[JsonPropertyName("n")] | ||
public int Number { get; } | ||
|
||
/// <summary> | ||
/// The format in which the generated images are returned. | ||
/// Must be one of url or b64_json. | ||
/// <para/> Defaults to <see cref="Images.ResponseFormat.Url"/> | ||
/// </summary> | ||
[JsonPropertyName("response_format")] | ||
public string ResponseFormat { get; } | ||
|
||
/// <summary> | ||
/// The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024. | ||
/// </summary> | ||
[JsonPropertyName("size")] | ||
public string Size { get; } | ||
|
||
/// <summary> | ||
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. | ||
/// </summary> | ||
[JsonPropertyName("user")] | ||
public string User { get; } | ||
} | ||
} |
This file contains 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
Oops, something went wrong.