Update GPT ChatterBot

* Updates endpoint from v1/completions to v1/chat/completions
* Add SharpTokens as a library to calculate input token usage
* Subtract input tokens from max_tokens to ensure the API tokens don't exceed the max specified
* Add Chat history support since this API supports it
* Add a personality prompt to tweak the way the bot behaves
* Add a min_tokens config to increase the quality of chat messages when history is enabled
* Adjust the response function to throw an exception so that a null message isn't added to the list.
This commit is contained in:
Alexandra
2024-01-16 09:12:14 +00:00
committed by Kwoth
parent ef4d38bc87
commit afba004d85
9 changed files with 140 additions and 47 deletions

View File

@@ -11,7 +11,13 @@ public class Gpt3Response
public class Choice
{
public string Text { get; set; }
[JsonPropertyName("message")]
public Message Message { get; init; }
}
public class Message {
[JsonPropertyName("content")]
public string Content { get; init; }
}
public class Gpt3ApiRequest
@@ -19,12 +25,22 @@ public class Gpt3ApiRequest
[JsonPropertyName("model")]
public string Model { get; init; }
[JsonPropertyName("prompt")]
public string Prompt { get; init; }
[JsonPropertyName("messages")]
public List<GPTMessage> Messages { get; init; }
[JsonPropertyName("temperature")]
public int Temperature { get; init; }
[JsonPropertyName("max_tokens")]
public int MaxTokens { get; init; }
}
public class GPTMessage
{
[JsonPropertyName("role")]
public string Role {get; init;}
[JsonPropertyName("content")]
public string Content {get; init;}
[JsonPropertyName("name")]
public string Name {get; init;}
}