Skip to content

Commit

Permalink
Merge pull request #413 from betalgo/dev
Browse files Browse the repository at this point in the history
Release 7.4.0
  • Loading branch information
kayhantolga authored Nov 10, 2023
2 parents b5f072e + 2577b39 commit ec9a425
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 13 deletions.
10 changes: 10 additions & 0 deletions OpenAI.SDK/Managers/OpenAIImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public async Task<ImageCreateResponse> CreateImageEdit(ImageEditCreateRequest im
multipartContent.Add(new StringContent(imageEditCreateRequest.N.ToString()!), "n");
}

if (imageEditCreateRequest.Model != null)
{
multipartContent.Add(new StringContent(imageEditCreateRequest.Model!), "model");
}

if (imageEditCreateRequest.Mask != null)
{
multipartContent.Add(new ByteArrayContent(imageEditCreateRequest.Mask), "mask", imageEditCreateRequest.MaskName);

Check warning on line 55 in OpenAI.SDK/Managers/OpenAIImage.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'fileName' in 'void MultipartFormDataContent.Add(HttpContent content, string name, string fileName)'.
Expand Down Expand Up @@ -84,6 +89,11 @@ public async Task<ImageCreateResponse> CreateImageVariation(ImageVariationCreate
multipartContent.Add(new StringContent(imageEditCreateRequest.N.ToString()!), "n");
}

if (imageEditCreateRequest.Model != null)
{
multipartContent.Add(new StringContent(imageEditCreateRequest.Model!), "model");
}

multipartContent.Add(new ByteArrayContent(imageEditCreateRequest.Image), "image", imageEditCreateRequest.ImageName);

return await _httpClient.PostFileAndReadAsAsync<ImageCreateResponse>(_endpointProvider.ImageVariationCreate(), multipartContent, cancellationToken);
Expand Down
50 changes: 49 additions & 1 deletion OpenAI.SDK/ObjectModels/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ public enum Model
Gpt_3_5_Turbo_16k,
Gpt_3_5_Turbo_16k_0613,
Gpt_3_5_Turbo_0613,
Gpt_3_5_Turbo_1106,
Gpt_3_5_Turbo_Instruct,

Gpt_4,
Gpt_4_0314,
Gpt_4_0613,
Gpt_4_32k,
Gpt_4_32k_0314,
Gpt_4_32k_0613,
Gpt_4_1106_preview,
Gpt_4_vision_preview,

WhisperV1
WhisperV1,

Dall_e_2,
Dall_e_3
}

public enum Subject
Expand Down Expand Up @@ -149,6 +156,21 @@ public enum Subject
/// </summary>
public static string Gpt_4_32k_0613 => "gpt-4-32k-0613";

/// <summary>
/// The latest GPT-4 model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more.
/// Returns a maximum of 4,096 output tokens. This preview model is not yet suited for production traffic.
/// 128,000 tokens Up to Apr 2023
/// </summary>
public static string Gpt_4_1106_preview => "gpt-4-1106-preview";

/// <summary>
/// Ability to understand images, in addition to all other GPT-4 Turbo capabilties.
/// Returns a maximum of 4,096 output tokens. This is a preview model version and not suited yet for production traffic.
/// 128,000 tokens Up to Apr 2023
/// </summary>
public static string Gpt_4_vision_preview => "gpt-4-vision-preview";



public static string Ada => "ada";
public static string Babbage => "babbage";
Expand Down Expand Up @@ -237,17 +259,37 @@ public enum Subject
/// 4,096 tokens Up to Sep 2021
/// </summary>
public static string Gpt_3_5_Turbo_0613 => "gpt-3.5-turbo-0613";

/// <summary>
/// The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, parallel function calling, and more.
/// 16,384 tokens Up to Sep 2021
/// </summary>
public static string Gpt_3_5_Turbo_1106 => "gpt-3.5-turbo-1106";

/// <summary>
/// Snapshot of gpt-3.5-turbo from June 13th 2023 with function calling data. Unlike gpt-3.5-turbo,
/// this model will not receive updates, and will be deprecated 3 months after a new version is released.
/// 4,096 tokens Up to Sep 2021
/// </summary>
public static string Gpt_3_5_Turbo_16k_0613 => "gpt-3.5-turbo-16k-0613";
/// <summary>
/// Similar capabilities as text-davinci-003 but compatible with legacy Completions endpoint and not Chat Completions.
/// 4,096 tokens Up to Sep 2021
/// </summary>
public static string Gpt_3_5_Turbo_Instruct => "gpt-3.5-turbo-instruct";


public static string WhisperV1 => "whisper-1";

/// <summary>
/// The previous DALL·E model released in Nov 2022. The 2nd iteration of DALL·E with more realistic, accurate, and 4x greater resolution images than the original model.
/// </summary>
public static string Dall_e_2 => "dall-e-2";
/// <summary>
/// The latest DALL·E model released in Nov 2023.
/// </summary>
public static string Dall_e_3 => "dall-e-3";

/// <summary>
/// This method does not guarantee returned model exists.
/// </summary>
Expand Down Expand Up @@ -316,8 +358,10 @@ public static string EnumToString(this Model model)
Model.ChatGpt3_5Turbo0301 => ChatGpt3_5Turbo0301,
Model.Gpt_3_5_Turbo_0301 => Gpt_3_5_Turbo_0301,
Model.Gpt_3_5_Turbo_0613 => Gpt_3_5_Turbo_0613,
Model.Gpt_3_5_Turbo_1106 => Gpt_3_5_Turbo_1106,
Model.Gpt_3_5_Turbo_16k_0613 => Gpt_3_5_Turbo_16k_0613,
Model.Gpt_3_5_Turbo_16k => Gpt_3_5_Turbo_16k,
Model.Gpt_3_5_Turbo_Instruct => Gpt_3_5_Turbo_Instruct,
Model.WhisperV1 => WhisperV1,
Model.TextEmbeddingAdaV2 => TextEmbeddingAdaV2,
Model.Gpt_4 => Gpt_4,
Expand All @@ -326,6 +370,10 @@ public static string EnumToString(this Model model)
Model.Gpt_4_32k_0314 => Gpt_4_32k_0314,
Model.Gpt_4_0613 => Gpt_4_0613,
Model.Gpt_4_32k_0613 => Gpt_4_32k_0613,
Model.Dall_e_2 => Dall_e_2,
Model.Dall_e_3 => Dall_e_3,
Model.Gpt_4_1106_preview => Gpt_4_1106_preview,
Model.Gpt_4_vision_preview => Gpt_4_vision_preview,
_ => throw new ArgumentOutOfRangeException(nameof(model), model, null)
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace OpenAI.ObjectModels.RequestModels;

public class ChatCompletionCreateRequest : IModelValidate, IOpenAiModels.ITemperature, IOpenAiModels.IModel, IOpenAiModels.IUser
{
public enum ResponseFormats
{
Text,
Json
}

/// <summary>
/// The messages to generate chat completions for, in the chat format.
/// The main input is the messages parameter. Messages must be an array of message objects, where each object has a
Expand Down Expand Up @@ -86,7 +92,7 @@ public IList<string>? StopCalculated

if (Stop != null)
{
return new List<string> {Stop};
return new List<string> { Stop };
}

return StopAsList;
Expand Down Expand Up @@ -146,6 +152,68 @@ public IList<string>? StopCalculated
[JsonPropertyName("function_call")]
public object? FunctionCall { get; set; }

/// <summary>
/// The format that the model must output. Used to enable JSON mode.
/// Must be one of "text" or "json_object".<br />
/// <see cref="StaticValues.CompletionStatics.ResponseFormat" /><br />
/// <example>
/// Sample Usage:<br />
/// new ResponseFormat { Type = StaticValues.CompletionStatics.ResponseFormat.Json }
/// </example>
/// </summary>
[JsonPropertyName("response_format")]
public ResponseFormat? ResponseFormat { get; set; }

/// <summary>
/// The format that the model must output. Used to enable JSON mode.
/// Must be one of "text" or "json_object".
/// </summary>
/// <example>
/// This example shows how to set the ChatResponseFormat to JSON:
/// <code>
/// var chatResponse = new ChatResponse
/// {
/// ChatResponseFormat = ChatResponseFormats.Json
/// };
/// </code>
/// </example>
/// <exception cref="ArgumentOutOfRangeException">
/// Thrown when an unsupported <see cref="ResponseFormats" /> value is provided.
/// </exception>
/// <exception cref="ValidationException">
/// Thrown when <see cref="ResponseFormat" /> is already set.
/// </exception>
[JsonIgnore]
public ResponseFormats? ChatResponseFormat
{
set
{
if (value == null) return;
if (ResponseFormat?.Type != null)
{
throw new ValidationException("ResponseFormat and ChatResponseFormat can not be assigned at the same time. One of them is should be null.");
}

ResponseFormat = new ResponseFormat
{
Type = value switch
{
ResponseFormats.Json => StaticValues.CompletionStatics.ResponseFormat.Json,
ResponseFormats.Text => StaticValues.CompletionStatics.ResponseFormat.Text,
_ => throw new ArgumentOutOfRangeException(nameof(value), value, null)
}
};
}
}

/// <summary>
/// This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that
/// repeated requests with the same seed and parameters should return the same result. Determinism is not guaranteed,
/// and you should refer to the system_fingerprint response parameter to monitor changes in the backend.
/// </summary>
[JsonPropertyName("seed")]
public int? Seed { get; set; }

/// <summary>
/// ID of the model to use. For models supported see <see cref="OpenAI.ObjectModels.Models" /> start with <c>Gpt_</c>
/// </summary>
Expand Down
20 changes: 19 additions & 1 deletion OpenAI.SDK/ObjectModels/RequestModels/ImageCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,26 @@ public ImageCreateRequest(string prompt)
}

/// <summary>
/// A text description of the desired image(s). The maximum length is 1000 characters.
/// A text description of the desired image(s). The maximum length is 1000 characters for dall-e-2 and 4000 characters for dall-e-3
/// </summary>
[JsonPropertyName("prompt")]
public string Prompt { get; set; }

/// <summary>
/// The quality of the image that will be generated. Must be hd.
/// Hd creates images with finer details and greater consistency across the image.
/// This param is only supported for dall-e-3 model.
/// <br /><br />Check <see cref="StaticValues.ImageStatics.Size"/> for possible values
/// </summary>
[JsonPropertyName("quality")]
public string? Quality { get; set; }

/// <summary>
/// The style of the generated images. Must be one of vivid or natural.
/// Vivid causes the model to lean towards generating hyper-real and dramatic images.
/// Natural causes the model to produce more natural, less hyper-real looking images. This param is only supported for dall-e-3.
/// <br /><br />Check <see cref="StaticValues.ImageStatics.Style"/> for possible values
/// </summary>
[JsonPropertyName("style")]
public string? Style { get; set; }
}
13 changes: 11 additions & 2 deletions OpenAI.SDK/ObjectModels/RequestModels/ImageEditCreateRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
namespace OpenAI.ObjectModels.RequestModels;
using System.Text.Json.Serialization;
using OpenAI.ObjectModels.SharedModels;

public record ImageEditCreateRequest : ImageCreateRequest
namespace OpenAI.ObjectModels.RequestModels;

public record ImageEditCreateRequest : SharedImageRequestBaseModel
{
/// <summary>
/// The image to edit. Must be a valid PNG file, less than 4MB, and square.
Expand All @@ -22,4 +25,10 @@ public record ImageEditCreateRequest : ImageCreateRequest
/// Mask file name
/// </summary>
public string? MaskName { get; set; }

/// <summary>
/// A text description of the desired image(s). The maximum length is 1000 characters.
/// </summary>
[JsonPropertyName("prompt")]
public string Prompt { get; set; }
}
20 changes: 20 additions & 0 deletions OpenAI.SDK/ObjectModels/RequestModels/ResponseFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text.Json.Serialization;

namespace OpenAI.ObjectModels.RequestModels;

/// <summary>
/// An object specifying the format that the model must output.
/// Used to enable JSON mode.
/// </summary>
public class ResponseFormat
{
/// <summary>
/// Setting to json_object enables JSON mode.
/// This guarantees that the message the model generates is valid JSON.
/// Note that the message content may be partial if finish_reason="length",
/// which indicates the generation exceeded max_tokens or the conversation exceeded the max context length.
/// </summary>

[JsonPropertyName("type")]
public string? Type { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ public record SharedImageRequestBaseModel
{
/// <summary>
/// The number of images to generate. Must be between 1 and 10.
/// For dall-e-3 model, only n=1 is supported.
/// </summary>
[JsonPropertyName("n")]
public int? N { get; set; }

/// <summary>
/// The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024.
/// The size of the generated images.
/// Must be one of 256x256, 512x512, or 1024x1024 for dall-e-2.
/// Must be one of 1024x1024, 1792x1024, or 1024x1792 for dall-e-3 models.
/// </summary>
[JsonPropertyName("size")]
public string? Size { get; set; }
Expand All @@ -28,4 +31,11 @@ public record SharedImageRequestBaseModel
/// </summary>
[JsonPropertyName("user")]
public string? User { get; set; }
}

/// <summary>
/// The model to use for image generation. Must be one of dall-e-2 or dall-e-3
/// For ImageEditCreateRequest and for ImageVariationCreateRequest only dall-e-2 modell is supported at this time.
/// </summary>
[JsonPropertyName("model")]
public string? Model { get; set; }
}
24 changes: 24 additions & 0 deletions OpenAI.SDK/ObjectModels/StaticValueHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,44 @@

public class StaticValues
{
public static class CompletionStatics
{
public static class ResponseFormat
{
public static string Json => "json_object";
public static string Text => "text";
}
}
public static class ImageStatics
{
public static class Size
{
public static string Size256 => "256x256";
public static string Size512 => "512x512";
public static string Size1024 => "1024x1024";
/// <summary>
/// Only dall-e-3 model
/// </summary>
// ReSharper disable once InconsistentNaming
public static string Size1792x1024 => "1792x1024";
/// <summary>
/// Only dall-e-3 model
/// </summary>
// ReSharper disable once InconsistentNaming
public static string Size1024x1792 => "1024x1792";
}

public static class ResponseFormat
{
public static string Url => "url";
public static string Base64 => "b64_json";
}

public static class Style
{
public static string Vivid => "Vivid";
public static string Natural => "Natural";
}
}

public static class AudioStatics
Expand Down
2 changes: 1 addition & 1 deletion OpenAI.SDK/OpenAI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageIcon>OpenAI-Betalgo.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>OpenAI SDK by Betalgo</Title>
<Version>7.3.1</Version>
<Version>7.4.0</Version>
<Authors>Tolga Kayhan, Betalgo</Authors>
<Company>Betalgo Up Ltd.</Company>
<Product>OpenAI ChatGPT, Whisper, GPT-4 and DALL·E dotnet SDK</Product>
Expand Down
1 change: 1 addition & 0 deletions OpenAI.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CREOL/@EntryIndexedValue">CREOL</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=argmax/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cushman/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dall/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Davinci/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=endoftext/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hyperparameters/@EntryIndexedValue">True</s:Boolean>
Expand Down
Loading

0 comments on commit ec9a425

Please sign in to comment.