Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rodion-m committed Nov 11, 2023
1 parent 9cda9fa commit 32130f2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<City>(message);
City almaty = await _client.GetStructuredResponse<City>(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).
Expand Down Expand Up @@ -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).
Expand Down
26 changes: 15 additions & 11 deletions src/OpenAI.ChatGpt/Models/ChatCompletion/ChatCompletionModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@ public static class ChatCompletionModels
public const string Default = Gpt3_5_Turbo;

/// <summary>
/// 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.
/// </summary>
public const string Gpt4Turbo = "gpt-4-1106-preview";

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// See: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4
/// </remarks>
public const string Gpt4 = "gpt-4";

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// See: https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4
/// </remarks>
public const string Gpt4_0613 = "gpt-4-0613";


Expand All @@ -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.
/// </summary>
[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";

/// <summary>
Expand All @@ -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.
/// </summary>
[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";

/// <summary>
Expand Down Expand Up @@ -146,7 +150,7 @@ public static class ChatCompletionModels
{ Gpt3_5_Turbo_0301, 4096 },
};

private static volatile bool _validateModelName = true;
private static int _validateModelName = 1;


/// <summary>
Expand Down Expand Up @@ -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));
}
Expand All @@ -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)
Expand Down

0 comments on commit 32130f2

Please sign in to comment.