ChatGPT.Net icon indicating copy to clipboard operation
ChatGPT.Net copied to clipboard

How to specify system message separately from user for the request?

Open lofti198 opened this issue 11 months ago • 1 comments

I am using code as below:

 ChatGptOptions options = new ChatGptOptions()
 {
     BaseUrl = "https://api.openai.com", // The base URL for the OpenAI API
     Model = "gpt-3.5-turbo",           // The specific model to use
     Temperature = 0.7,                   // Controls randomness in the response (0-1)
     TopP = 0.9,                         // Controls diversity in the response (0-1)
     MaxTokens = 3500,                   // The maximum number of tokens in the response
     Stop = null,       // Sequence of tokens that will stop generation
     PresencePenalty = 0.0,              // Penalizes new tokens based on their existing presence in the context
     FrequencyPenalty = 0.0              // Penalizes new tokens based on their frequency in the context
 };

 var openai = new ChatGpt(openAiKey, options);
 var fixedSentence = await openai.Ask($"{instruction}: {data}");
 return fixedSentence;

However cant get how to speficy system message separately. For example I want to ask to rephrase user message and keep it in the original language (not-English).

lofti198 avatar Mar 12 '24 12:03 lofti198

@lofti198 , you need to call SetConversationSystemMessage method of ChatGpt object. It expects two parameters, first one being 'conversationId' and second one being the 'system message'. For example, in your case, you can do:

var openai = new ChatGpt(openAiKey, options);
//set system message
openai.SetConversationSystemMessage("your-conversationId", "rephrase user message and keep it in the original language");
//chat with user message
var fixedSentence = await openai.Ask($"{instruction}: {data}");
 return fixedSentence;

zeecorleone avatar May 23 '24 16:05 zeecorleone