This project implements ChatGPT continuous dialogue based on ConversationId, which can be quickly integrated with just a few lines of code. It supports models such as gpt-4, gpt-3.5-turbo, and text-davinci-003.
ChatGPTSharp is available as NuGet package.
Use ConversationId for continuous conversations.
var client = new ChatGPTClient(File.ReadAllText("KEY.txt"), "gpt-3.5-turbo");
var msgFirst = await client.SendMessage("Hello, My name is Sin");
Console.WriteLine($"{msgLast.Response}");
var msgLast = await client.SendMessage("My name is?", msgFirst.ConversationId, msgFirst.MessageId);
Console.WriteLine($"{msgLast.Response}");
Use prompt to constrain ChatGPT behavior.
var client = new ChatGPTClient(File.ReadAllText("KEY.txt"), "gpt-3.5-turbo");
var sysMsg = "You will review group messages as a group administrator, and I will inform you in the format of {[who][said what]} to reply with a number from 0 to 10 to indicate the severity of political content in their speech, such as "0". No need to reply with any other unnecessary content, such as no political content or inability to understand the defense. Please note that group members may be cunning and use pinyin, initials, homophones, abbreviations, etc., to describe things to avoid scrutiny.";
var msg = await client.SendMessage("{[MrWang][Can Trump be president again?]}", sendSystemType: Model.SendSystemType.Custom, sendSystemMessage: sysMsg);
- Add support gpt-3.5-turbo-16k
- Removed the old token algorithm code and now supports netstandard2.0, now, the library can also be used with .NET Framework.
- Support for the GPT-4 model and correction of the maximum token count for 8k and 32k.
Changelog for earlier versions.
- The initialization method of ChatGPTClient adds a request timeout setting and changes the default timeout time from 20 seconds to 60 seconds.
- Using TiktokenSharp to calculate token count, fixing the issue of inaccurate token calculation.
- token algorithm fix
- The token algorithm has been temporarily removed, which may cause exceptions when certain strings are combined. It will be restored after subsequent testing is completed.
- Add SendMessage parameters sendSystemType and sendSystemMessage to specify the insertion of system messages into the conversation.
- Add local token algorithm of gpt3, the algorithm is from js library gpt-3-encoder
This code base references node-chatgpt-api