From 32130f24c42beab0e7904862ba0888cea090d3dd Mon Sep 17 00:00:00 2001 From: Rodion Mostovoi Date: Sat, 11 Nov 2023 14:40:56 +0800 Subject: [PATCH] Update docs --- README.md | 28 ++++++++++++------- .../ChatCompletion/ChatCompletionModels.cs | 26 +++++++++-------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 50db8b4..f202fe0 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ record City(string Name, int YearOfFoundation, string Country); var message = Dialog .StartAsSystem("Return requested data.") .ThenUser("I need info about Almaty city"); -City almaty = await _client.GetStructuredResponse(message); +City almaty = await _client.GetStructuredResponse(message, model: ChatCompletionModels.Gpt4Turbo); Console.WriteLine(almaty); // Name: "Almaty", Country: "Kazakhstan", YearOfFoundation: 1854 ``` Under the hood, it uses the new [json mode](https://platform.openai.com/docs/guides/text-generation/json-mode) of the API for GPT4Turbo and for the `gpt-3.5-turbo-1106`. Regular GPT4 and GPT3.5Turbo models are also supported, but GPT3.5 responses may be unstable (for GPT3.5 it's strictly recommended to provide `examples` parameter). @@ -167,15 +167,23 @@ Some of them are taken from this article: https://towardsdatascience.com/gpt-3-p Below listed parameters for ChatCompletions API. ### Model -The prediction-generating AI model is specified by the engine parameter. The available models are: -* `ChatCompletionModels.Gpt3_5_Turbo` (Default): Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with OpenAI's latest model iteration. -* `ChatCompletionModels.Gpt3_5_Turbo_0301`: Snapshot of gpt-3.5-turbo from March 1st 2023. Unlike gpt-3.5-turbo, this model will not receive updates, and will only be supported for a three month period ending on June 1st 2023. -* `ChatCompletionModels.Gpt4`: More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with OpenAI's latest model iteration. \* -* `ChatCompletionModels.Gpt4_0314`: Snapshot of gpt-4 from March 14th 2023. Unlike gpt-4, this model will not receive updates, and will only be supported for a three month period ending on June 14th 2023. \* -* `ChatCompletionModels.Gpt4_32k`: Same capabilities as the base gpt-4 mode but with 4x the context length. Will be updated with OpenAI's latest model iteration. \* -* `ChatCompletionModels.Gpt4_32k_0314`: Snapshot of gpt-4-32 from March 14th 2023. Unlike gpt-4-32k, this model will not receive updates, and will only be supported for a three month period ending on June 14th 2023. \* \ - Note that training data for all models is up to Sep 2021. \ - \* These models are currently in beta and are not yet available to all users. Here is the link for joining waitlist: https://openai.com/waitlist/gpt-4-api +The prediction-generating AI model is specified by the engine parameter. The available models are described below: https://platform.openai.com/docs/models + +| C# Model | API Model | +|--------------------------------------------|------------------------| +| ChatCompletionModels.Gpt4Turbo | gpt-4-1106-preview | +| ChatCompletionModels.Gpt4 | gpt-4 | +| ChatCompletionModels.Gpt4_0613 | gpt-4-0613 | +| ChatCompletionModels.Gpt4_32k | gpt-4-32k | +| ChatCompletionModels.Gpt4_32k_0613 | gpt-4-32k-0613 | +| ChatCompletionModels.Gpt3_5_Turbo | gpt-3.5-turbo | +| ChatCompletionModels.Gpt3_5_Turbo_1106 | gpt-3.5-turbo-1106 | +| ChatCompletionModels.Gpt3_5_Turbo_16k | gpt-3.5-turbo-16k | +| ChatCompletionModels.Gpt3_5_Turbo_0613 | gpt-3.5-turbo-0613 | +| ChatCompletionModels.Gpt3_5_Turbo_16k_0613 | gpt-3.5-turbo-16k-0613 | +| ChatCompletionModels.Gpt4_0314 | gpt-4-0314 | +| ChatCompletionModels.Gpt4_32k_0314 | gpt-4-32k-0314 | +| ChatCompletionModels.Gpt3_5_Turbo_0301 | gpt-3.5-turbo-0301 | ### MaxTokens The maximum number of tokens allowed for the generated answer. Defaults to `ChatCompletionRequest.MaxTokensDefault` (64). diff --git a/src/OpenAI.ChatGpt/Models/ChatCompletion/ChatCompletionModels.cs b/src/OpenAI.ChatGpt/Models/ChatCompletion/ChatCompletionModels.cs index d587079..a3e564a 100644 --- a/src/OpenAI.ChatGpt/Models/ChatCompletion/ChatCompletionModels.cs +++ b/src/OpenAI.ChatGpt/Models/ChatCompletion/ChatCompletionModels.cs @@ -19,26 +19,32 @@ public static class ChatCompletionModels public const string Default = Gpt3_5_Turbo; /// - /// Preview of the newest GPT-4 Turbo model. + /// 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. + /// The model was trained with data up to April 2023. /// public const string Gpt4Turbo = "gpt-4-1106-preview"; /// - /// IMPORTANT: This model is available only by special coditions. https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4 /// More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. /// Will be updated with OpenAI's latest model iteration 2 weeks after it is released. /// This model has a maximum token limit of 8,192. /// The model was trained with data up to September 2021. /// + /// + /// See: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4 + /// public const string Gpt4 = "gpt-4"; /// - /// IMPORTANT: This model is available only by request. Link for joining waitlist: https://openai.com/waitlist/gpt-4-api /// Snapshot of gpt-4 from June 13th 2023 with function calling data. /// Unlike gpt-4, this model will not receive updates, and will be deprecated 3 months after a new version is released. /// This model has a maximum token limit of 8,192. /// The model was trained with data up to September 2021. /// + /// + /// See: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4 + /// public const string Gpt4_0613 = "gpt-4-0613"; @@ -48,8 +54,7 @@ public static class ChatCompletionModels /// This model has a maximum token limit of 32,768. /// The model was trained with data up to September 2021. /// - [Obsolete("This model is available only by request. " + - "Link for joining waitlist: https://openai.com/waitlist/gpt-4-api")] + [Obsolete("This model is not available for all.")] public const string Gpt4_32k = "gpt-4-32k"; /// @@ -58,8 +63,7 @@ public static class ChatCompletionModels /// This model has a maximum token limit of 32,768. /// The model was trained with data up to September 2021. /// - [Obsolete("This model is available only by request. " + - "Link for joining waitlist: https://openai.com/waitlist/gpt-4-api")] + [Obsolete("This model is not available for all.")] public const string Gpt4_32k_0613 = "gpt-4-32k-0613"; /// @@ -146,7 +150,7 @@ public static class ChatCompletionModels { Gpt3_5_Turbo_0301, 4096 }, }; - private static volatile bool _validateModelName = true; + private static int _validateModelName = 1; /// @@ -184,7 +188,7 @@ public static string FromString(string model) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(model)); } - if (_validateModelName && !MaxTokensLimits.ContainsKey(model)) + if (_validateModelName == 1 && !MaxTokensLimits.ContainsKey(model)) { throw new ArgumentException($"Invalid model: {model}", nameof(model)); } @@ -193,12 +197,12 @@ public static string FromString(string model) public static void DisableModelNameValidation() { - _validateModelName = false; + Interlocked.CompareExchange(ref _validateModelName, 0, 1); } public static void EnableModelNameValidation() { - _validateModelName = true; + Interlocked.CompareExchange(ref _validateModelName, 1, 0); } public static void EnsureMaxTokensIsSupported(string model, int maxTokens)