From c6afc0c1f49892981a551e1f4dc4ed74ad4defc1 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Sat, 13 Jul 2024 20:12:09 +0400 Subject: [PATCH] feat: Moved OpenAI.Constants inside main OpenAI package. --- OpenAI.sln | 7 - .../Chat/ChatModels.3.5.Turbo.Legacy.cs | 69 ------- .../Chat/ChatModels.3.5.Turbo.cs | 67 ------- .../OpenAI.Constants/Chat/ChatModels.4.32k.cs | 32 --- .../Chat/ChatModels.4.Omni.cs | 33 ---- .../Chat/ChatModels.4.Turbo.cs | 78 -------- .../Chat/ChatModels.4.Vision.cs | 34 ---- .../OpenAI.Constants/Chat/ChatModels.4.cs | 32 --- src/libs/OpenAI.Constants/Chat/ChatModels.cs | 122 ------------ .../Embedding/EmbeddingModels.V2.cs | 23 --- .../Embedding/EmbeddingModels.V3.cs | 45 ----- .../Embedding/EmbeddingModels.cs | 67 ------- .../OpenAI.Constants/Image/ImageModels.V2.cs | 14 -- .../OpenAI.Constants/Image/ImageModels.V3.cs | 14 -- .../OpenAI.Constants/Image/ImageModels.cs | 74 ------- .../Image/ImageQualities.Values.cs | 21 -- .../OpenAI.Constants/Image/ImageQualities.cs | 24 --- .../Image/ImageResolution.Values.cs | 48 ----- .../OpenAI.Constants/Image/ImageResolution.cs | 24 --- .../Moderation/ModerationModels.Values.cs | 23 --- .../Moderation/ModerationModels.cs | 43 ---- .../OpenAI.Constants/OpenAI.Constants.csproj | 38 ---- .../SpeechToText/SpeechToTextModels.Values.cs | 17 -- .../SpeechToText/SpeechToTextModels.cs | 55 ------ .../TextToSpeech/TextToSpeechModels.Values.cs | 27 --- .../TextToSpeech/TextToSpeechModels.cs | 56 ------ src/libs/OpenAI/OpenAI.csproj | 2 +- src/libs/OpenAI/Prices/Prices.Chat.cs | 183 ++++++++++++++++++ src/libs/OpenAI/Prices/Prices.Embedding.cs | 45 +++++ src/libs/OpenAI/Prices/Prices.Images.cs | 39 ++++ src/libs/OpenAI/Prices/Prices.STT.cs | 25 +++ src/libs/OpenAI/Prices/Prices.TTS.cs | 26 +++ .../Prices/Prices.cs} | 7 +- 33 files changed, 323 insertions(+), 1091 deletions(-) delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.Legacy.cs delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.cs delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.4.32k.cs delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.4.Omni.cs delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.4.Turbo.cs delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.4.Vision.cs delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.4.cs delete mode 100644 src/libs/OpenAI.Constants/Chat/ChatModels.cs delete mode 100644 src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V2.cs delete mode 100644 src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V3.cs delete mode 100644 src/libs/OpenAI.Constants/Embedding/EmbeddingModels.cs delete mode 100644 src/libs/OpenAI.Constants/Image/ImageModels.V2.cs delete mode 100644 src/libs/OpenAI.Constants/Image/ImageModels.V3.cs delete mode 100644 src/libs/OpenAI.Constants/Image/ImageModels.cs delete mode 100644 src/libs/OpenAI.Constants/Image/ImageQualities.Values.cs delete mode 100644 src/libs/OpenAI.Constants/Image/ImageQualities.cs delete mode 100644 src/libs/OpenAI.Constants/Image/ImageResolution.Values.cs delete mode 100644 src/libs/OpenAI.Constants/Image/ImageResolution.cs delete mode 100644 src/libs/OpenAI.Constants/Moderation/ModerationModels.Values.cs delete mode 100644 src/libs/OpenAI.Constants/Moderation/ModerationModels.cs delete mode 100644 src/libs/OpenAI.Constants/OpenAI.Constants.csproj delete mode 100644 src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.Values.cs delete mode 100644 src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.cs delete mode 100644 src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.Values.cs delete mode 100644 src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.cs create mode 100644 src/libs/OpenAI/Prices/Prices.Chat.cs create mode 100644 src/libs/OpenAI/Prices/Prices.Embedding.cs create mode 100644 src/libs/OpenAI/Prices/Prices.Images.cs create mode 100644 src/libs/OpenAI/Prices/Prices.STT.cs create mode 100644 src/libs/OpenAI/Prices/Prices.TTS.cs rename src/libs/{OpenAI.Constants/Helpers/InternalConstants.cs => OpenAI/Prices/Prices.cs} (75%) diff --git a/OpenAI.sln b/OpenAI.sln index bc5f7637..54a0a233 100755 --- a/OpenAI.sln +++ b/OpenAI.sln @@ -33,8 +33,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators.Integrati EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Generators.SnapshotTests", "src\tests\OpenAI.Generators.SnapshotTests\OpenAI.Generators.SnapshotTests.csproj", "{4F534836-40A3-4E75-8B71-C46CD4FBE137}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAI.Constants", "src\libs\OpenAI.Constants\OpenAI.Constants.csproj", "{74A51E6E-2955-4909-A075-13D8E620FBFE}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixOpenApiSpec", "src\helpers\FixOpenApiSpec\FixOpenApiSpec.csproj", "{594DCFD8-E707-4232-B878-90FA3D880474}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "helpers", "helpers", "{1A008ECD-2300-4BE4-A302-49DDF8BE0D54}" @@ -67,10 +65,6 @@ Global {4F534836-40A3-4E75-8B71-C46CD4FBE137}.Debug|Any CPU.Build.0 = Debug|Any CPU {4F534836-40A3-4E75-8B71-C46CD4FBE137}.Release|Any CPU.ActiveCfg = Release|Any CPU {4F534836-40A3-4E75-8B71-C46CD4FBE137}.Release|Any CPU.Build.0 = Release|Any CPU - {74A51E6E-2955-4909-A075-13D8E620FBFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {74A51E6E-2955-4909-A075-13D8E620FBFE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {74A51E6E-2955-4909-A075-13D8E620FBFE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {74A51E6E-2955-4909-A075-13D8E620FBFE}.Release|Any CPU.Build.0 = Release|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Debug|Any CPU.Build.0 = Debug|Any CPU {594DCFD8-E707-4232-B878-90FA3D880474}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -89,7 +83,6 @@ Global {5504353C-9B7F-402B-9268-4821AB5E73F9} = {61E7E11E-4558-434C-ACE8-06316A3097B3} {83CBA1D2-8424-4925-9F55-BEB64C7E3EE6} = {AAA11B78-2764-4520-A97E-46AA7089A588} {4F534836-40A3-4E75-8B71-C46CD4FBE137} = {AAA11B78-2764-4520-A97E-46AA7089A588} - {74A51E6E-2955-4909-A075-13D8E620FBFE} = {61E7E11E-4558-434C-ACE8-06316A3097B3} {594DCFD8-E707-4232-B878-90FA3D880474} = {1A008ECD-2300-4BE4-A302-49DDF8BE0D54} {FCBE699C-CCD3-4809-8128-78956BC3F2C3} = {61E7E11E-4558-434C-ACE8-06316A3097B3} EndGlobalSection diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.Legacy.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.Legacy.cs deleted file mode 100644 index 84bc7e50..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.Legacy.cs +++ /dev/null @@ -1,69 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -// ReSharper disable InconsistentNaming - -public readonly partial record struct ChatModels -{ - /// - /// 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.
- /// Max tokens: 4,096 tokens
- /// Training data: Up to Sep 2021
- ///
- [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - internal const string Gpt35Turbo_0613Id = "gpt-3.5-turbo-0613"; - - /// - /// Snapshot of gpt-3.5-turbo-16k from June 13th 2023.
- /// Unlike gpt-3.5-turbo-16k, this model will not receive updates, and will be deprecated 3 months after a new version is released.
- /// Max tokens: 16,384 tokens
- /// Training data: Up to Sep 2021
- ///
- [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - internal const string Gpt35Turbo_16k_0613Id = "gpt-3.5-turbo-16k-0613"; - - /// - /// Snapshot of gpt-3.5-turbo from March 1st 2023.
- /// Max tokens: 4,096 tokens
- /// Training data: Up to Sep 2021
- ///
- [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - internal const string Gpt35Turbo_0301Id = "gpt-3.5-turbo-0301"; - - /// - /// Alias - Currently points to gpt-3.5-turbo-16k-0613. - [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - internal const string Gpt35Turbo_16kId = "gpt-3.5-turbo-16k"; - - /// - [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - public static ChatModels Gpt35Turbo_0613 { get; } = new( - Id: Gpt35Turbo_0613Id, - ContextLength: 4_096, - PricePerInputTokenInUsd: 1.5 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 2.0 * UsdPerMillionTokens); - - /// - [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - public static ChatModels Gpt35Turbo_0301 { get; } = new( - Id: Gpt35Turbo_0301Id, - ContextLength: 4_096, - PricePerInputTokenInUsd: 2.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 2.0 * UsdPerMillionTokens); - - /// - [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - public static ChatModels Gpt35Turbo_16k_0613 { get; } = new( - Id: Gpt35Turbo_16k_0613Id, - ContextLength: 16_385, - PricePerInputTokenInUsd: 3.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 4.0 * UsdPerMillionTokens); - - /// - [Obsolete("Marked as Legacy. Will be deprecated on June 13, 2024.")] - public static ChatModels Gpt35Turbo_16k { get; } = Gpt35Turbo_16k_0613 with - { - Id = Gpt35Turbo_16kId, - }; -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.cs deleted file mode 100644 index bbb63f71..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.3.5.Turbo.cs +++ /dev/null @@ -1,67 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -// ReSharper disable InconsistentNaming - -public readonly partial record struct ChatModels -{ - /// - /// The latest GPT-3.5 Turbo model with improved instruction following, JSON mode, reproducible outputs, - /// parallel function calling, and more.
- /// Max input tokens: 16,385 tokens
- /// Max output tokens: 4,096 tokens
- /// Training data: Up to Sep 2021
- ///
- internal const string Gpt35Turbo_1106Id = "gpt-3.5-turbo-1106"; - - /// - /// Similar capabilities as GPT-3 era models. Compatible with legacy Completions endpoint and not Chat Completions.
- /// Max tokens: 4,096 tokens
- /// Training data: Up to Sep 2021
- ///
- internal const string Gpt35TurboInstructId = "gpt-3.5-turbo-instruct"; - - /// - /// This model will also have various improvements including higher accuracy - /// at responding in requested formats and a fix for a bug - /// which caused a text encoding issue for non-English language function calls.
- /// Max input tokens: 16,385 tokens
- /// Max output tokens: 4,096 tokens
- /// Training data: Up to Sep 2021
- ///
- internal const string Gpt35Turbo_0125Id = "gpt-3.5-turbo-0125"; - - /// - /// Alias - Currently points to gpt-3.5-turbo-0613. - internal const string Gpt35TurboId = "gpt-3.5-turbo"; - - /// - public static ChatModels Gpt35Turbo_1106 { get; } = new( - Id: Gpt35Turbo_1106Id, - ContextLength: 16_385, - PricePerInputTokenInUsd: 1.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 2.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt35Turbo_0125 { get; } = new( - Id: Gpt35Turbo_0125Id, - ContextLength: 16_385, - PricePerInputTokenInUsd: 0.5 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 1.5 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt35TurboInstruct { get; } = new( - Id: Gpt35TurboInstructId, - ContextLength: 4_096, - PricePerInputTokenInUsd: 1.5 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 2.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt35Turbo { get; } = Gpt35Turbo_0125 with - { - Id = Gpt35TurboId, - FineTuningPricePerTrainingTokenInUsd = 8.0 * UsdPerMillionTokens, - FineTuningPricePerInputTokenInUsd = 3.0 * UsdPerMillionTokens, - FineTuningPricePerOutputTokenInUsd = 6.0 * UsdPerMillionTokens, - }; -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.4.32k.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.4.32k.cs deleted file mode 100644 index 7dd1face..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.4.32k.cs +++ /dev/null @@ -1,32 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -// ReSharper disable InconsistentNaming - -public readonly partial record struct ChatModels -{ - /// - /// Snapshot of gpt-4-32k from June 13th 2023 with improved function calling support.
- /// According https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo
- /// Max tokens: 32,768 tokens
- /// Training data: Up to Sep 2021
- ///
- internal const string Gpt4_32k_0613Id = "gpt-4-32k-0613"; - - /// - /// Alias - Currently points to gpt-4-32k-0613 - internal const string Gpt4_32kId = "gpt-4-32"; - - /// - public static ChatModels Gpt4_32k_0613 { get; } = new( - Id: Gpt4_32k_0613Id, - ContextLength: 32_768, - PricePerInputTokenInUsd: 60.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 120.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt4_32k { get; } = Gpt4_32k_0613 with - { - Id = Gpt4_32k_0613Id, - }; -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.4.Omni.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.4.Omni.cs deleted file mode 100644 index c9d57a13..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.4.Omni.cs +++ /dev/null @@ -1,33 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -// ReSharper disable InconsistentNaming - -public readonly partial record struct ChatModels -{ - /// - /// Our most advanced, multimodal flagship model that’s cheaper and faster than GPT-4 Turbo.
- /// According https://platform.openai.com/docs/models/gpt-4o
- /// Max input tokens: 128,000 tokens
- /// Max output tokens: 4,096 tokens
- /// Training data: Up to Oct 2023
- ///
- internal const string Gpt4o_2024_05_13Id = "gpt-4o-2024-05-13"; - - /// - /// Alias - Currently points to gpt-4-1106-vision-preview. - internal const string Gpt4oId = "gpt-4o"; - - /// - public static ChatModels Gpt4o_2024_05_13 { get; } = new( - Gpt4o_2024_05_13Id, - ContextLength: 128_000, - PricePerInputTokenInUsd: 5.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 15.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt4o { get; } = Gpt4o_2024_05_13 with - { - Id = Gpt4oId, - }; -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.4.Turbo.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.4.Turbo.cs deleted file mode 100644 index e3d1fcf0..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.4.Turbo.cs +++ /dev/null @@ -1,78 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -// ReSharper disable InconsistentNaming - -public readonly partial record struct ChatModels -{ - /// - /// The GPT-4 model with improved instruction following, JSON mode, reproducible outputs, - /// parallel function calling, and more. - /// This preview model is not yet suited for production traffic.
- /// Max input tokens: 128,000 tokens
- /// Max output tokens: 4,096 tokens
- /// Training data: Up to Apr 2023
- ///
- internal const string Gpt4_1106_PreviewId = "gpt-4-1106-preview"; - - /// - /// Today, we are releasing an updated GPT-4 Turbo preview model, gpt-4-0125-preview. - /// This model completes tasks like code generation more thoroughly than the previous preview model - /// and is intended to reduce cases of “laziness” where the model doesn’t complete a task. - /// The new model also includes the fix for the bug impacting non-English UTF-8 generations.
- /// Max input tokens: 128,000 tokens
- /// Max output tokens: 4,096 tokens
- /// Training data: Up to Apr 2023
- ///
- internal const string Gpt4_0125_PreviewId = "gpt-4-0125-preview"; - - /// - /// GPT-4 Turbo with Vision model. - /// Vision requests can now use JSON mode and function calling.
- /// Max input tokens: 128,000 tokens
- /// Max output tokens: 4,096 tokens
- /// Training data: Up to Dec 2023
- ///
- internal const string Gpt4Turbo_2024_04_09Id = "gpt-4-turbo-2024-04-09"; - - /// - /// Alias - Currently points to gpt-4-0125-preview. - internal const string Gpt4TurboPreviewId = "gpt-4-turbo-preview"; - - /// - /// Alias - Currently points to gpt-4-turbo-2024-04-09. - internal const string Gpt4TurboId = "gpt-4-turbo"; - - /// - public static ChatModels Gpt4_1106_Preview { get; } = new( - Id: Gpt4_1106_PreviewId, - ContextLength: 128_000, - PricePerInputTokenInUsd: 10.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 30.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt4_0125_Preview { get; } = new( - Id: Gpt4_0125_PreviewId, - ContextLength: 128_000, - PricePerInputTokenInUsd: 10.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 30.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt4Turbo_2024_04_09 { get; } = new( - Id: Gpt4Turbo_2024_04_09Id, - ContextLength: 128_000, - PricePerInputTokenInUsd: 10.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 30.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt4TurboPreview { get; } = Gpt4_0125_Preview with - { - Id = Gpt4TurboPreviewId, - }; - - /// - public static ChatModels Gpt4Turbo { get; } = Gpt4Turbo_2024_04_09 with - { - Id = Gpt4TurboId, - }; -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.4.Vision.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.4.Vision.cs deleted file mode 100644 index 585b1e2b..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.4.Vision.cs +++ /dev/null @@ -1,34 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -// ReSharper disable InconsistentNaming - -public readonly partial record struct ChatModels -{ - /// - /// Ability to understand images, in addition to all other GPT-4 Turbo capabilities. - /// This is a preview model version and not suited yet for production traffic.
- /// According https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo
- /// Max input tokens: 128,000 tokens
- /// Max output tokens: 4,096 tokens
- /// Training data: Up to Apr 2023
- ///
- internal const string Gpt4_1106_VisionPreviewId = "gpt-4-1106-vision-preview"; - - /// - /// Alias - Currently points to gpt-4-1106-vision-preview. - internal const string Gpt4VisionPreviewId = "gpt-4-vision-preview"; - - /// - public static ChatModels Gpt4_1106_VisionPreview { get; } = new( - Gpt4_1106_VisionPreviewId, - ContextLength: 128_000, - PricePerInputTokenInUsd: 10.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 30.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt4VisionPreview { get; } = Gpt4_1106_VisionPreview with - { - Id = Gpt4VisionPreviewId, - }; -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.4.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.4.cs deleted file mode 100644 index 72b5510d..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.4.cs +++ /dev/null @@ -1,32 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -// ReSharper disable InconsistentNaming - -public readonly partial record struct ChatModels -{ - /// - /// Snapshot of gpt-4 from June 13th 2023 with improved function calling support.
- /// According https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo
- /// Max tokens: 8,192 tokens
- /// Training data: Up to Sep 2021
- ///
- internal const string Gpt4_0613Id = "gpt-4-0613"; - - /// - /// Alias - Currently points to gpt-4-0613. - internal const string Gpt4Id = "gpt-4"; - - /// - public static ChatModels Gpt4_0613 { get; } = new( - Id: Gpt4_0613Id, - ContextLength: 8_192, - PricePerInputTokenInUsd: 30.0 * UsdPerMillionTokens, - PricePerOutputTokenInUsd: 60.0 * UsdPerMillionTokens); - - /// - public static ChatModels Gpt4 { get; } = Gpt4_0613 with - { - Id = Gpt4Id, - }; -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Chat/ChatModels.cs b/src/libs/OpenAI.Constants/Chat/ChatModels.cs deleted file mode 100644 index bc7a3215..00000000 --- a/src/libs/OpenAI.Constants/Chat/ChatModels.cs +++ /dev/null @@ -1,122 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According: -/// - https://platform.openai.com/docs/models/ -/// - https://openai.com/blog/new-embedding-models-and-api-updates -/// - https://platform.openai.com/docs/models/gpt-4-and-gpt-4-turbo -/// -/// OpenAI models are non-deterministic, meaning that identical inputs can yield different outputs. -/// Setting temperature to 0 will make the outputs mostly deterministic, but a small amount of variability may remain. -/// -/// -/// Id of the model. -/// The maximum number of input tokens. -/// Price per input token in USD. -/// Price per output token in USD. -/// Fine tuning price per training token in USD. -/// Fine tuning price per input token in USD. -/// Fine tuning price per output token in USD. -public readonly partial record struct ChatModels( - string Id, - int ContextLength, - double PricePerInputTokenInUsd, - double PricePerOutputTokenInUsd, - double? FineTuningPricePerTrainingTokenInUsd = null, - double? FineTuningPricePerInputTokenInUsd = null, - double? FineTuningPricePerOutputTokenInUsd = null) -{ - /// - public override string ToString() - { - return Id; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(ChatModels model) - { - return model.Id; - } - - /// - /// According https://openai.com/pricing/
- ///
- /// - /// - /// - public double GetPriceInUsd( - int inputTokens, - int outputTokens) - { - return inputTokens * PricePerInputTokenInUsd + - outputTokens * PricePerOutputTokenInUsd; - } - - /// - /// According https://openai.com/pricing/
- ///
- /// - /// - /// - /// - /// - public double GetFineTunePriceInUsd( - int trainingTokens, - int inputTokens, - int outputTokens) - { - if (FineTuningPricePerTrainingTokenInUsd is null || - FineTuningPricePerInputTokenInUsd is null || - FineTuningPricePerOutputTokenInUsd is null) - { - throw new InvalidOperationException( - $"Fine tuning prices are not available for {Id}."); - } - - return trainingTokens * FineTuningPricePerTrainingTokenInUsd.Value + - inputTokens * FineTuningPricePerInputTokenInUsd.Value + - outputTokens * FineTuningPricePerOutputTokenInUsd.Value; - } - - /// - /// Returns by .
- /// Returns if is not found. - ///
- /// Id of the model. - /// - public static ChatModels? ById(string id) - { - return id switch - { - Gpt35Turbo_1106Id => Gpt35Turbo_1106, - Gpt35Turbo_0125Id => Gpt35Turbo_0125, - Gpt35TurboInstructId => Gpt35TurboInstruct, - Gpt35TurboId => Gpt35Turbo, - - Gpt35Turbo_16kId => Gpt35Turbo_16k, - Gpt35Turbo_0613Id => Gpt35Turbo_0613, - Gpt35Turbo_16k_0613Id => Gpt35Turbo_16k_0613, - Gpt35Turbo_0301Id => Gpt35Turbo_0301, - - Gpt4Id => Gpt4, - Gpt4_0613Id => Gpt4_0613, - - Gpt4_32kId => Gpt4_32k, - Gpt4_32k_0613Id => Gpt4_32k_0613, - - Gpt4_1106_PreviewId => Gpt4_1106_Preview, - Gpt4_0125_PreviewId => Gpt4_0125_Preview, - Gpt4TurboPreviewId => Gpt4TurboPreview, - - Gpt4_1106_VisionPreviewId => Gpt4_1106_VisionPreview, - Gpt4VisionPreviewId => Gpt4VisionPreview, - - _ => null, - }; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V2.cs b/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V2.cs deleted file mode 100644 index db205f42..00000000 --- a/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V2.cs +++ /dev/null @@ -1,23 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct EmbeddingModels -{ - /// - /// We are not deprecating text-embedding-ada-002, so while we recommend the newer model, - /// customers are welcome to continue using the previous generation model.
- /// Max input tokens: 8,191 tokens
- /// Tokenizer: cl100k_base
- /// Output dimensions: 1536
- /// Rough pages per dollar: 12,500
- /// MIRACL average(1536): 31.4%
- /// MTEB average(1536): 61.0%
- ///
- internal const string Ada002Id = "text-embedding-ada-002"; - - /// - public static EmbeddingModels Ada002 { get; } = new( - Id: Ada002Id, - MaxInputTokens: 8_191, - PricePerTokenInUsd: 0.10 * UsdPerMillionTokens); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V3.cs b/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V3.cs deleted file mode 100644 index 01dd971e..00000000 --- a/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.V3.cs +++ /dev/null @@ -1,45 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct EmbeddingModels -{ - /// - /// is our new highly efficient embedding model - /// and provides a significant upgrade over its predecessor, - /// the model released in December 2022.
- /// Max input tokens: 8,191 tokens
- /// Tokenizer: cl100k_base
- /// Max and default output dimensions: 1536
- /// Rough pages per dollar: 62,500
- /// MIRACL average(1536): 44.0%
- /// MTEB average(512): 61.6%
- /// MTEB average(1536): 62.3%
- ///
- internal const string Version3SmallId = "text-embedding-3-small"; - - /// - /// is our new next generation larger embedding model - /// and creates embeddings with up to 3072 dimensions.
- /// Max input tokens: 8,191 tokens
- /// Tokenizer: cl100k_base
- /// Max and default output dimensions: 3072
- /// Rough pages per dollar: 9,615
- /// MIRACL average(3072): 54.9%
- /// MTEB average(256): 62.0%
- /// MTEB average(1024): 64.1%
- /// MTEB average(3072): 64.6%
- ///
- internal const string Version3LargeId = "text-embedding-3-large"; - - /// - public static EmbeddingModels Version3Small { get; } = new( - Id: Version3SmallId, - MaxInputTokens: 8_191, - PricePerTokenInUsd: 0.02 * UsdPerMillionTokens); - - /// - public static EmbeddingModels Version3Large { get; } = new( - Id: Version3LargeId, - MaxInputTokens: 8_191, - PricePerTokenInUsd: 0.13 * UsdPerMillionTokens); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.cs b/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.cs deleted file mode 100644 index 6a20f40a..00000000 --- a/src/libs/OpenAI.Constants/Embedding/EmbeddingModels.cs +++ /dev/null @@ -1,67 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According:
-/// - https://platform.openai.com/docs/guides/embeddings/embedding-models
-/// - https://openai.com/blog/new-embedding-models-and-api-updates
-/// -/// and , our newest and -/// most performant embedding models are now available, with lower costs, -/// higher multilingual performance, and new parameters to control the overall size. -/// -///
-/// Id of the model. -/// Max input tokens. -/// Price per token in USD. -public readonly partial record struct EmbeddingModels( - string Id, - int MaxInputTokens, - double PricePerTokenInUsd) -{ - /// - public override string ToString() - { - return Id; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(EmbeddingModels model) - { - return model.Id; - } - - /// - /// According https://openai.com/pricing/
- ///
- /// - /// - public double GetPriceInUsd( - int tokens) - { - return tokens * PricePerTokenInUsd; - } - - /// - /// Returns by .
- /// Returns if is not found. - ///
- /// Id of the model. - /// - public static EmbeddingModels? ById(string id) - { - return id switch - { - Ada002Id => Ada002, - - Version3SmallId => Version3Small, - Version3LargeId => Version3Large, - - _ => null, - }; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Image/ImageModels.V2.cs b/src/libs/OpenAI.Constants/Image/ImageModels.V2.cs deleted file mode 100644 index 88dfa9a7..00000000 --- a/src/libs/OpenAI.Constants/Image/ImageModels.V2.cs +++ /dev/null @@ -1,14 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct ImageModels -{ - /// - /// The image generations endpoint allows you to create an original image given a text prompt.
- /// Images can have a size of 1024x1024, 1024x1792 or 1792x1024 pixels.
- ///
- internal const string DallE2Id = "dall-e-2"; - - /// - public static ImageModels DallE2 { get; } = new(DallE2Id); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Image/ImageModels.V3.cs b/src/libs/OpenAI.Constants/Image/ImageModels.V3.cs deleted file mode 100644 index 078a1cf7..00000000 --- a/src/libs/OpenAI.Constants/Image/ImageModels.V3.cs +++ /dev/null @@ -1,14 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct ImageModels -{ - /// - /// The image generations endpoint allows you to create an original image given a text prompt.
- /// Images can have a size of 1024x1024, 1024x1792 or 1792x1024 pixels.
- ///
- internal const string DallE3Id = "dall-e-3"; - - /// - public static ImageModels DallE3 { get; } = new(DallE3Id); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Image/ImageModels.cs b/src/libs/OpenAI.Constants/Image/ImageModels.cs deleted file mode 100644 index 123df30f..00000000 --- a/src/libs/OpenAI.Constants/Image/ImageModels.cs +++ /dev/null @@ -1,74 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According https://platform.openai.com/docs/guides/images/introduction -/// -/// Id of the model. -public readonly partial record struct ImageModels(string Id) -{ - /// - public override string ToString() - { - return Id; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(ImageModels model) - { - return model.Id; - } - - /// - /// All prices in USD.
- /// According https://openai.com/pricing/
- ///
- /// - /// - /// - /// - public double GetPriceInUsd( - ImageResolutions resolution, - ImageQualities? quality = null) - { - quality ??= ImageQualities.Standard; - - return (Id, quality.Value.Value, resolution.Value) switch - { - (DallE3Id, ImageQualities.StandardValue, ImageResolutions._1024x1024Value) => 0.040, - (DallE3Id, ImageQualities.StandardValue, ImageResolutions._1024x1792Value) => 0.080, - (DallE3Id, ImageQualities.StandardValue, ImageResolutions._1792x1024Value) => 0.080, - - (DallE3Id, ImageQualities.HdValue, ImageResolutions._1024x1024Value) => 0.080, - (DallE3Id, ImageQualities.HdValue, ImageResolutions._1024x1792Value) => 0.120, - (DallE3Id, ImageQualities.HdValue, ImageResolutions._1792x1024Value) => 0.120, - - (DallE2Id, _, ImageResolutions._1024x1024Value) => 0.020, - (DallE2Id, _, ImageResolutions._512x512Value) => 0.018, - (DallE2Id, _, ImageResolutions._256x256Value) => 0.016, - - _ => throw new NotImplementedException(), - }; - } - - /// - /// Returns by .
- /// Returns if is not found. - ///
- /// Id of the model. - /// - public static ImageModels? ById(string id) - { - return id switch - { - DallE2Id => DallE2, - DallE3Id => DallE3, - - _ => null, - }; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Image/ImageQualities.Values.cs b/src/libs/OpenAI.Constants/Image/ImageQualities.Values.cs deleted file mode 100644 index aae565ba..00000000 --- a/src/libs/OpenAI.Constants/Image/ImageQualities.Values.cs +++ /dev/null @@ -1,21 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct ImageQualities -{ - /// - /// By default, images are generated at standard quality, but when using DALL·E 3 you can set quality: "hd" for enhanced detail. Square, standard quality images are the fastest to generate.
- ///
- internal const string StandardValue = "standard"; - - /// - /// By default, images are generated at standard quality, but when using DALL·E 3 you can set quality: "hd" for enhanced detail. Square, standard quality images are the fastest to generate.
- ///
- internal const string HdValue = "hd"; - - /// - public static ImageQualities Standard { get; } = new(StandardValue); - - /// - public static ImageQualities Hd { get; } = new(HdValue); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Image/ImageQualities.cs b/src/libs/OpenAI.Constants/Image/ImageQualities.cs deleted file mode 100644 index db83ee84..00000000 --- a/src/libs/OpenAI.Constants/Image/ImageQualities.cs +++ /dev/null @@ -1,24 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According https://platform.openai.com/docs/guides/images/introduction -/// -public readonly partial record struct ImageQualities(string Value) -{ - /// - public override string ToString() - { - return Value; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(ImageQualities model) - { - return model.Value; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Image/ImageResolution.Values.cs b/src/libs/OpenAI.Constants/Image/ImageResolution.Values.cs deleted file mode 100644 index 8b6b46d8..00000000 --- a/src/libs/OpenAI.Constants/Image/ImageResolution.Values.cs +++ /dev/null @@ -1,48 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct ImageResolutions -{ - /// - /// Supported models: DALL·E 2.
- ///
- internal const string _256x256Value = "256x256"; - - /// - /// Supported models: DALL·E 2.
- ///
- internal const string _512x512Value = "512x512"; - - /// - /// Supported models: DALL·E 2, DALL·E 3.
- /// Supported qualities: Standard and HD.
- ///
- internal const string _1024x1024Value = "1024x1024"; - - /// - /// Supported models: DALL·E 3.
- /// Supported qualities: Standard and HD.
- ///
- internal const string _1024x1792Value = "1024x1792"; - - /// - /// Supported models: DALL·E 3.
- /// Supported qualities: Standard and HD.
- ///
- internal const string _1792x1024Value = "1792x1024"; - - /// - public static ImageResolutions _256x256 { get; } = new(_256x256Value); - - /// - public static ImageResolutions _512x512 { get; } = new(_512x512Value); - - /// - public static ImageResolutions _1024x1024 { get; } = new(_1024x1024Value); - - /// - public static ImageResolutions _1024x1792 { get; } = new(_1024x1792Value); - - /// - public static ImageResolutions _1792x1024 { get; } = new(_1792x1024Value); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Image/ImageResolution.cs b/src/libs/OpenAI.Constants/Image/ImageResolution.cs deleted file mode 100644 index 7892ac30..00000000 --- a/src/libs/OpenAI.Constants/Image/ImageResolution.cs +++ /dev/null @@ -1,24 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According https://platform.openai.com/docs/guides/images/introduction -/// -public readonly partial record struct ImageResolutions(string Value) -{ - /// - public override string ToString() - { - return Value; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(ImageResolutions model) - { - return model.Value; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Moderation/ModerationModels.Values.cs b/src/libs/OpenAI.Constants/Moderation/ModerationModels.Values.cs deleted file mode 100644 index 0b85504d..00000000 --- a/src/libs/OpenAI.Constants/Moderation/ModerationModels.Values.cs +++ /dev/null @@ -1,23 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct ModerationModels -{ - /// - /// If you use text-moderation-stable, we will provide advanced notice before updating the model.
- /// Accuracy of text-moderation-stable may be slightly lower than for text-moderation-latest.
- ///
- internal const string StableId = "text-moderation-stable"; - - /// - /// The default is text-moderation-latest which will be automatically upgraded over time.
- /// This ensures you are always using our most accurate model.
- ///
- internal const string LatestId = "text-moderation-latest"; - - /// - public static ModerationModels Stable { get; } = new(StableId); - - /// - public static ModerationModels Latest { get; } = new(LatestId); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Moderation/ModerationModels.cs b/src/libs/OpenAI.Constants/Moderation/ModerationModels.cs deleted file mode 100644 index f92931dc..00000000 --- a/src/libs/OpenAI.Constants/Moderation/ModerationModels.cs +++ /dev/null @@ -1,43 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According https://platform.openai.com/docs/api-reference/moderations -/// Two content moderation models are available: text-moderation-stable and text-moderation-latest. -/// -/// Id of the model. -public readonly partial record struct ModerationModels(string Id) -{ - /// - public override string ToString() - { - return Id; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(ModerationModels model) - { - return model.Id; - } - - /// - /// Returns by .
- /// Returns if is not found. - ///
- /// Id of the model. - /// - public static ModerationModels? ById(string id) - { - return id switch - { - StableId => Stable, - LatestId => Latest, - - _ => null, - }; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/OpenAI.Constants.csproj b/src/libs/OpenAI.Constants/OpenAI.Constants.csproj deleted file mode 100644 index eff9dd97..00000000 --- a/src/libs/OpenAI.Constants/OpenAI.Constants.csproj +++ /dev/null @@ -1,38 +0,0 @@ - - - - netstandard2.0;net4.6.2;net6.0;net7.0;net8.0 - $(NoWarn);CA1707;CS0618 - - - - Static classes that provide actual constants(models/context lengts/prices) for the OpenAI API. - Available types in OpenAI.Constants namespace: - - ChatModels - - EmbeddingModels - - ImageModels - - ImageQualities - - ImageResolutions - - ModerationModels - - SpeechToTextModels - - TextToSpeechModels - - openai;constants;prices;pricing;gpt-3.5;gpt-4;chatgpt;vision;audio;embedding;moderation;image;chat - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - diff --git a/src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.Values.cs b/src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.Values.cs deleted file mode 100644 index 5124ab91..00000000 --- a/src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.Values.cs +++ /dev/null @@ -1,17 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct SpeechToTextModels -{ - /// - /// Transcribe audio into whatever language the audio is in.
- /// File uploads are currently limited to 25 MB and - /// the following input file types are supported: mp3, mp4, mpeg, mpga, m4a, wav, and webm.
- ///
- internal const string Whisper1Id = "whisper-1"; - - /// - public static SpeechToTextModels Whisper1 { get; } = new( - Id: Whisper1Id, - PricePerMinuteInUsd: 0.006); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.cs b/src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.cs deleted file mode 100644 index f36f593b..00000000 --- a/src/libs/OpenAI.Constants/SpeechToText/SpeechToTextModels.cs +++ /dev/null @@ -1,55 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According https://platform.openai.com/docs/guides/speech-to-text -/// -/// Id of the model. -/// Price per minute in USD. -public readonly partial record struct SpeechToTextModels( - string Id, - double PricePerMinuteInUsd) -{ - /// - public override string ToString() - { - return Id; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(SpeechToTextModels model) - { - return model.Id; - } - - /// - /// According https://openai.com/pricing/
- ///
- /// rounded to the nearest second - /// - public double GetPriceInUsd( - int seconds) - { - return seconds * PricePerMinuteInUsd / 60.0; - } - - /// - /// Returns by .
- /// Returns if is not found. - ///
- /// Id of the model. - /// - public static SpeechToTextModels? ById(string id) - { - return id switch - { - Whisper1Id => Whisper1, - - _ => null, - }; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.Values.cs b/src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.Values.cs deleted file mode 100644 index fbeaf3df..00000000 --- a/src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.Values.cs +++ /dev/null @@ -1,27 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -public readonly partial record struct TextToSpeechModels -{ - /// - /// Transcribe audio into whatever language the audio is in.
- /// File uploads are currently limited to 25 MB and the following input file types are supported: mp3, mp4, mpeg, mpga, m4a, wav, and webm.
- ///
- internal const string Tts1Id = "tts-1"; - - /// - /// Transcribe audio into whatever language the audio is in.
- /// File uploads are currently limited to 25 MB and the following input file types are supported: mp3, mp4, mpeg, mpga, m4a, wav, and webm.
- ///
- internal const string Tts1HdId = "tts-1-hd"; - - /// - public static TextToSpeechModels Tts1 { get; } = new( - Id: Tts1Id, - PricePerCharacterInUsd: 15.0 * UsdPerMillionTokens); - - /// - public static TextToSpeechModels Tts1Hd { get; } = new( - Id: Tts1HdId, - PricePerCharacterInUsd: 30.0 * UsdPerMillionTokens); -} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.cs b/src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.cs deleted file mode 100644 index ebd60f82..00000000 --- a/src/libs/OpenAI.Constants/TextToSpeech/TextToSpeechModels.cs +++ /dev/null @@ -1,56 +0,0 @@ -// ReSharper disable once CheckNamespace -namespace OpenAI.Constants; - -/// -/// According https://platform.openai.com/docs/guides/text-to-speech -/// -/// Id of the model. -/// Price per character in USD. -public readonly partial record struct TextToSpeechModels( - string Id, - double PricePerCharacterInUsd) -{ - /// - public override string ToString() - { - return Id; - } - - /// - /// Implicitly converts to . - /// - /// - /// - public static implicit operator string(TextToSpeechModels model) - { - return model.Id; - } - - /// - /// According https://openai.com/pricing/
- ///
- /// - /// - public double GetPriceInUsd( - int characters) - { - return characters * PricePerCharacterInUsd; - } - - /// - /// Returns by .
- /// Returns if is not found. - ///
- /// Id of the model. - /// - public static TextToSpeechModels? ById(string id) - { - return id switch - { - Tts1Id => Tts1, - Tts1HdId => Tts1Hd, - - _ => null, - }; - } -} \ No newline at end of file diff --git a/src/libs/OpenAI/OpenAI.csproj b/src/libs/OpenAI/OpenAI.csproj index 95fabc40..7e6b207e 100644 --- a/src/libs/OpenAI/OpenAI.csproj +++ b/src/libs/OpenAI/OpenAI.csproj @@ -13,7 +13,7 @@ Generated C# SDK based on official OpenAI OpenAPI specification. Includes C# Source Generator which allows you to define functions natively through a C# interface, and also provides extensions that make it easier to call this interface later - api;client;sdk;dotnet;swagger;openapi;specification;openai;generated;nswag;functions;gpt-3.5;gpt-4;chatgpt;generator;source generator + api;client;sdk;dotnet;swagger;openapi;specification;openai;generated;nswag;functions;gpt-3.5;gpt-4;chatgpt;generator;source generator;constants;prices;pricing;vision;audio;embedding;moderation;image;chat diff --git a/src/libs/OpenAI/Prices/Prices.Chat.cs b/src/libs/OpenAI/Prices/Prices.Chat.cs new file mode 100644 index 00000000..2c8dd903 --- /dev/null +++ b/src/libs/OpenAI/Prices/Prices.Chat.cs @@ -0,0 +1,183 @@ +// ReSharper disable once CheckNamespace +namespace OpenAI; + +public static partial class Prices +{ + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + /// + /// + public static double? TryGetPriceInUsd( + this CreateChatCompletionRequestModel model, + int inputTokens, + int outputTokens) + { + var (pricePerInputTokenInUsd, pricePerOutputTokenInUsd) = model switch + { + CreateChatCompletionRequestModel.Gpt4o => (5.0 * UsdPerMillionTokens, 15.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt4o20240513 => (5.0 * UsdPerMillionTokens, 15.0 * UsdPerMillionTokens), + + CreateChatCompletionRequestModel.Gpt4Turbo => (10.0 * UsdPerMillionTokens, 30.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt4Turbo20240409 => (10.0 * UsdPerMillionTokens, 30.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt40125Preview => (10.0 * UsdPerMillionTokens, 30.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt4TurboPreview => (10.0 * UsdPerMillionTokens, 30.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt41106Preview => (10.0 * UsdPerMillionTokens, 30.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt4VisionPreview => (10.0 * UsdPerMillionTokens, 30.0 * UsdPerMillionTokens), + + CreateChatCompletionRequestModel.Gpt4 => (30.0 * UsdPerMillionTokens, 60.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt40314 => (30.0 * UsdPerMillionTokens, 60.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt40613 => (30.0 * UsdPerMillionTokens, 60.0 * UsdPerMillionTokens), + + CreateChatCompletionRequestModel.Gpt432k => (60.0 * UsdPerMillionTokens, 120.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt432k0314 => (60.0 * UsdPerMillionTokens, 120.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt432k0613 => (60.0 * UsdPerMillionTokens, 120.0 * UsdPerMillionTokens), + + CreateChatCompletionRequestModel.Gpt35Turbo => (0.5 * UsdPerMillionTokens, 1.5 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt35Turbo0125 => (0.5 * UsdPerMillionTokens, 1.5 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt35Turbo1106 => (1.0 * UsdPerMillionTokens, 2.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt35Turbo0613 => (1.5 * UsdPerMillionTokens, 2.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt35Turbo0301 => (2.0 * UsdPerMillionTokens, 2.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt35Turbo16k => (3.0 * UsdPerMillionTokens, 4.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt35Turbo16k0613 => (3.0 * UsdPerMillionTokens, 4.0 * UsdPerMillionTokens), + + _ => (double.NaN, double.NaN), + }; + if (double.IsNaN(pricePerInputTokenInUsd) || + double.IsNaN(pricePerOutputTokenInUsd)) + { + return null; + } + + return + inputTokens * pricePerInputTokenInUsd + + outputTokens * pricePerOutputTokenInUsd; + } + + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + /// + /// + /// + public static double GetPriceInUsd( + this CreateChatCompletionRequestModel model, + int inputTokens, + int outputTokens) + { + return model.TryGetPriceInUsd(inputTokens, outputTokens) ?? + throw new InvalidOperationException( + $"Prices are not available for {model.ToValueString()}."); + } + + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + /// + /// + /// + /// + public static double? TryGetFineTunePriceInUsd( + this CreateChatCompletionRequestModel model, + int trainingTokens, + int inputTokens, + int outputTokens) + { + var (pricePerTrainingTokenInUsd, pricePerInputTokenInUsd, pricePerOutputTokenInUsd) = model switch + { + CreateChatCompletionRequestModel.Gpt35Turbo => (8.0 * UsdPerMillionTokens, 3.0 * UsdPerMillionTokens, 6.0 * UsdPerMillionTokens), + CreateChatCompletionRequestModel.Gpt35Turbo0125 => (8.0 * UsdPerMillionTokens, 3.0 * UsdPerMillionTokens, 6.0 * UsdPerMillionTokens), + + _ => (double.NaN, double.NaN, double.NaN), + }; + if (double.IsNaN(pricePerTrainingTokenInUsd) || + double.IsNaN(pricePerInputTokenInUsd) || + double.IsNaN(pricePerOutputTokenInUsd)) + { + return null; + } + + return trainingTokens * pricePerTrainingTokenInUsd + + inputTokens * pricePerInputTokenInUsd + + outputTokens * pricePerOutputTokenInUsd; + } + + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + /// + /// + /// + /// + public static double GetFineTunePriceInUsd( + this CreateChatCompletionRequestModel model, + int trainingTokens, + int inputTokens, + int outputTokens) + { + return model.TryGetFineTunePriceInUsd(trainingTokens, inputTokens, outputTokens) ?? + throw new InvalidOperationException( + $"Fine tuning prices are not available for {model.ToValueString()}."); + } + + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + public static double? TryGetContextLength( + this CreateChatCompletionRequestModel model) + { + return model switch + { + CreateChatCompletionRequestModel.Gpt4o => 128_000, + CreateChatCompletionRequestModel.Gpt4o20240513 => 128_000, + + CreateChatCompletionRequestModel.Gpt4Turbo => 128_000, + CreateChatCompletionRequestModel.Gpt4Turbo20240409 => 128_000, + CreateChatCompletionRequestModel.Gpt40125Preview => 128_000, + CreateChatCompletionRequestModel.Gpt4TurboPreview => 128_000, + CreateChatCompletionRequestModel.Gpt41106Preview => 128_000, + CreateChatCompletionRequestModel.Gpt4VisionPreview => 128_000, + + CreateChatCompletionRequestModel.Gpt4 => 8_192, + CreateChatCompletionRequestModel.Gpt40314 => 8_192, + CreateChatCompletionRequestModel.Gpt40613 => 8_192, + + CreateChatCompletionRequestModel.Gpt432k => 32_768, + CreateChatCompletionRequestModel.Gpt432k0314 => 32_768, + CreateChatCompletionRequestModel.Gpt432k0613 => 32_768, + + CreateChatCompletionRequestModel.Gpt35Turbo => 4_096, + CreateChatCompletionRequestModel.Gpt35Turbo0301 => 4_096, + CreateChatCompletionRequestModel.Gpt35Turbo0613 => 4_096, + CreateChatCompletionRequestModel.Gpt35Turbo1106 => 16_385, + CreateChatCompletionRequestModel.Gpt35Turbo0125 => 16_385, + CreateChatCompletionRequestModel.Gpt35Turbo16k => 16_385, + CreateChatCompletionRequestModel.Gpt35Turbo16k0613 => 16_385, + + _ => null, + }; + } + + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + public static double GetContextLength( + this CreateChatCompletionRequestModel model) + { + return model.TryGetContextLength() ?? + throw new InvalidOperationException( + $"Context length is not available for {model.ToValueString()}."); + } +} \ No newline at end of file diff --git a/src/libs/OpenAI/Prices/Prices.Embedding.cs b/src/libs/OpenAI/Prices/Prices.Embedding.cs new file mode 100644 index 00000000..01568cdf --- /dev/null +++ b/src/libs/OpenAI/Prices/Prices.Embedding.cs @@ -0,0 +1,45 @@ +// ReSharper disable once CheckNamespace +namespace OpenAI; + +public static partial class Prices +{ + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + /// + public static double GetPriceInUsd( + this CreateEmbeddingRequestModel model, + int tokens) + { + var pricePerTokenInUsd = model switch + { + CreateEmbeddingRequestModel.TextEmbeddingAda002 => 0.10 * UsdPerMillionTokens, + CreateEmbeddingRequestModel.TextEmbedding3Small => 0.02 * UsdPerMillionTokens, + CreateEmbeddingRequestModel.TextEmbedding3Large => 0.13 * UsdPerMillionTokens, + + _ => throw new NotImplementedException(), + }; + + return tokens * pricePerTokenInUsd; + } + + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + public static double GetMaxInputTokens( + this CreateEmbeddingRequestModel model) + { + return model switch + { + CreateEmbeddingRequestModel.TextEmbeddingAda002 => 8_191, + CreateEmbeddingRequestModel.TextEmbedding3Small => 8_191, + CreateEmbeddingRequestModel.TextEmbedding3Large => 8_191, + + _ => throw new NotImplementedException(), + }; + } +} \ No newline at end of file diff --git a/src/libs/OpenAI/Prices/Prices.Images.cs b/src/libs/OpenAI/Prices/Prices.Images.cs new file mode 100644 index 00000000..f8bf88f2 --- /dev/null +++ b/src/libs/OpenAI/Prices/Prices.Images.cs @@ -0,0 +1,39 @@ +// ReSharper disable once CheckNamespace +namespace OpenAI; + +public static partial class Prices +{ + /// + /// All prices in USD.
+ /// According https://platform.openai.com/docs/guides/images/introduction
+ ///
+ /// + /// + /// + /// + /// + public static double GetPriceInUsd( + this CreateImageRequestModel model, + CreateImageRequestSize size, + CreateImageRequestQuality? quality = null) + { + quality ??= CreateImageRequestQuality.Standard; + + return (model, quality.Value, size) switch + { + (CreateImageRequestModel.DallE3, CreateImageRequestQuality.Standard, CreateImageRequestSize._1024x1024) => 0.040, + (CreateImageRequestModel.DallE3, CreateImageRequestQuality.Standard, CreateImageRequestSize._1024x1792) => 0.080, + (CreateImageRequestModel.DallE3, CreateImageRequestQuality.Standard, CreateImageRequestSize._1792x1024) => 0.080, + + (CreateImageRequestModel.DallE3, CreateImageRequestQuality.Hd, CreateImageRequestSize._1024x1024) => 0.080, + (CreateImageRequestModel.DallE3, CreateImageRequestQuality.Hd, CreateImageRequestSize._1024x1792) => 0.120, + (CreateImageRequestModel.DallE3, CreateImageRequestQuality.Hd, CreateImageRequestSize._1792x1024) => 0.120, + + (CreateImageRequestModel.DallE2, _, CreateImageRequestSize._1024x1024) => 0.020, + (CreateImageRequestModel.DallE2, _, CreateImageRequestSize._512x512) => 0.018, + (CreateImageRequestModel.DallE2, _, CreateImageRequestSize._256x256) => 0.016, + + _ => throw new NotImplementedException(), + }; + } +} \ No newline at end of file diff --git a/src/libs/OpenAI/Prices/Prices.STT.cs b/src/libs/OpenAI/Prices/Prices.STT.cs new file mode 100644 index 00000000..b7e975da --- /dev/null +++ b/src/libs/OpenAI/Prices/Prices.STT.cs @@ -0,0 +1,25 @@ +// ReSharper disable once CheckNamespace +namespace OpenAI; + +public static partial class Prices +{ + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// rounded to the nearest second + /// + public static double GetPriceInUsd( + this CreateTranscriptionRequestModel model, + int seconds) + { + var pricePerMinuteInUsd = model switch + { + CreateTranscriptionRequestModel.Whisper1 => 0.006, + + _ => throw new NotImplementedException(), + }; + + return seconds * pricePerMinuteInUsd / 60.0; + } +} \ No newline at end of file diff --git a/src/libs/OpenAI/Prices/Prices.TTS.cs b/src/libs/OpenAI/Prices/Prices.TTS.cs new file mode 100644 index 00000000..b97ef1fa --- /dev/null +++ b/src/libs/OpenAI/Prices/Prices.TTS.cs @@ -0,0 +1,26 @@ +// ReSharper disable once CheckNamespace +namespace OpenAI; + +public static partial class Prices +{ + /// + /// According https://openai.com/pricing/
+ ///
+ /// + /// + /// + public static double GetPriceInUsd( + this CreateSpeechRequestModel model, + int characters) + { + var pricePerCharacterInUsd = model switch + { + CreateSpeechRequestModel.Tts1 => 15.0 * UsdPerMillionTokens, + CreateSpeechRequestModel.Tts1Hd => 30.0 * UsdPerMillionTokens, + + _ => throw new NotImplementedException(), + }; + + return characters * pricePerCharacterInUsd; + } +} \ No newline at end of file diff --git a/src/libs/OpenAI.Constants/Helpers/InternalConstants.cs b/src/libs/OpenAI/Prices/Prices.cs similarity index 75% rename from src/libs/OpenAI.Constants/Helpers/InternalConstants.cs rename to src/libs/OpenAI/Prices/Prices.cs index 200d715c..5a7367d8 100644 --- a/src/libs/OpenAI.Constants/Helpers/InternalConstants.cs +++ b/src/libs/OpenAI/Prices/Prices.cs @@ -1,9 +1,10 @@ -namespace OpenAI.Constants.Helpers; +// ReSharper disable once CheckNamespace +namespace OpenAI; /// -/// Internal constants used by the OpenAI SDK. +/// According https://openai.com/pricing/ /// -public static class InternalConstants +public static partial class Prices { /// /// Just a constant for 1e-3.