Skip to content

Commit

Permalink
Merge pull request #476 from shanepowell/Add-EmbeddingsDimensions
Browse files Browse the repository at this point in the history
Add dimensions to EmbeddingCreateRequest
  • Loading branch information
kayhantolga authored Jan 30, 2024
2 parents a13ac9d + 44cb928 commit bafb57a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
34 changes: 31 additions & 3 deletions OpenAI.SDK/ObjectModels/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public enum Model
CodeEditDavinciV1,

TextEmbeddingAdaV2,
TextEmbeddingV3Small,
TextEmbeddingV3Large,

CodeSearchAdaCodeV1,
CodeSearchBabbageCodeV1,
Expand All @@ -80,6 +82,7 @@ public enum Model
Gpt_3_5_Turbo_16k_0613,
Gpt_3_5_Turbo_0613,
Gpt_3_5_Turbo_1106,
Gpt_3_5_Turbo_0125,
Gpt_3_5_Turbo_Instruct,

Gpt_4,
Expand All @@ -89,15 +92,21 @@ public enum Model
Gpt_4_32k_0314,
Gpt_4_32k_0613,
Gpt_4_1106_preview,
Gpt_4_0125_preview,
Gpt_4_vision_preview,
Gpt_4_turbo_preview,

WhisperV1,

Dall_e_2,
Dall_e_3,

Tts_1,
Tts_1_hd
Tts_1_hd,

Text_moderation_007,
Text_moderation_latest,
Text_moderation_stable,
}

public enum Subject
Expand All @@ -113,7 +122,8 @@ public enum Subject
Code,
CodeEdit,
Edit,
TextEmbedding
TextEmbedding,
TextModeration
}

/// <summary>
Expand Down Expand Up @@ -166,13 +176,16 @@ public enum Subject
/// </summary>
public static string Gpt_4_1106_preview => "gpt-4-1106-preview";

public static string Gpt_4_0125_preview => "gpt-4-0125-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 Gpt_4_turbo_preview => "gpt-4-turbo-preview";



public static string Ada => "ada";
Expand Down Expand Up @@ -219,7 +232,12 @@ public enum Subject
public static string CodeSearchBabbageTextV1 => ModelNameBuilder(BaseModel.Babbage, Subject.CodeSearchText, "001");

public static string TextEmbeddingAdaV2 => ModelNameBuilder(BaseModel.Ada, Subject.TextEmbedding, "002");
public static string TextEmbeddingV3Small => ModelNameBuilder(BaseModel.Ada, Subject.TextEmbedding, "3-small");
public static string TextEmbeddingV3Large => ModelNameBuilder(BaseModel.Ada, Subject.TextEmbedding, "3-large");

public static string TextModeration007 => ModelNameBuilder(BaseModel.Ada, Subject.TextModeration, "007");
public static string TextModerationLatest => ModelNameBuilder(BaseModel.Ada, Subject.TextModeration, "latest");
public static string TextModerationStable => ModelNameBuilder(BaseModel.Ada, Subject.TextModeration, "stable");
/// <summary>
/// Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with our
/// latest model iteration.
Expand Down Expand Up @@ -269,6 +287,7 @@ public enum Subject
/// </summary>
public static string Gpt_3_5_Turbo_1106 => "gpt-3.5-turbo-1106";

public static string Gpt_3_5_Turbo_0125 => "gpt-3.5-turbo-0125";
/// <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.
Expand Down Expand Up @@ -376,11 +395,14 @@ public static string EnumToString(this Model model)
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_0125 => Gpt_3_5_Turbo_0125,
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.TextEmbeddingV3Small => TextEmbeddingV3Small,
Model.TextEmbeddingV3Large => TextEmbeddingV3Large,
Model.Gpt_4 => Gpt_4,
Model.Gpt_4_0314 => Gpt_4_0314,
Model.Gpt_4_32k => Gpt_4_32k,
Expand All @@ -390,9 +412,14 @@ public static string EnumToString(this Model model)
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_0125_preview => Gpt_4_0125_preview,
Model.Gpt_4_vision_preview => Gpt_4_vision_preview,
Model.Gpt_4_turbo_preview => Gpt_4_turbo_preview,
Model.Tts_1 => Tts_1,
Model.Tts_1_hd => Tts_1_hd,
Model.Text_moderation_007 => TextModeration007,
Model.Text_moderation_latest => TextModerationLatest,
Model.Text_moderation_stable => TextModerationStable,
_ => throw new ArgumentOutOfRangeException(nameof(model), model, null)
};
}
Expand Down Expand Up @@ -427,6 +454,7 @@ public static string EnumToString(this Subject subject, string baseModel)
Subject.CodeEdit => "code-{0}-edit",
Subject.Edit => "text-{0}-edit",
Subject.TextEmbedding => "text-embedding-{0}",
Subject.TextModeration => "text-moderation-{0}",
_ => throw new ArgumentOutOfRangeException(nameof(subject), subject, null)
}, baseModel);
}
Expand Down
14 changes: 14 additions & 0 deletions OpenAI.SDK/ObjectModels/RequestModels/EmbeddingCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public IList<string>? InputCalculated
[JsonPropertyName("model")]
public string? Model { get; set; }

/// <summary>
/// The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.
/// </summary>
/// <see href="https://platform.openai.com/docs/api-reference/embeddings/create#embeddings-create-dimensions" />
[JsonPropertyName("dimensions")]
public int? Dimensions { get; set; }

/// <summary>
/// The format to return the embeddings in. Can be either float or base64.
/// </summary>
/// <returns></returns>
[JsonPropertyName("encoding_format")]
public string? EncodingFormat { get; set; }

public IEnumerable<ValidationResult> Validate()
{
throw new NotImplementedException();
Expand Down

0 comments on commit bafb57a

Please sign in to comment.