I created a function named GetGPTMes for partial class Functions, and I put it in the project at the following link.
https://www.quickmacros.com/forum/showth...6#pid36746
I can use the PowerShell code below to execute the GetGPTMes function, but I need to implement Multiple conversations with ChatGPT while keeping context!
I can use the following C# code to implement a multi-turn ChatGPT conversation in a console window and maintain context. But how can I achieve the same effect in an HTTP request?
Additionally, there will be multiple HTTP requests simultaneously accessing the GetGPTMes function. How to handle this is a bit challenging for me!
Thanks in advance for any suggestions and help.
Powershell Code Test:
https://www.quickmacros.com/forum/showth...6#pid36746
I can use the PowerShell code below to execute the GetGPTMes function, but I need to implement Multiple conversations with ChatGPT while keeping context!
I can use the following C# code to implement a multi-turn ChatGPT conversation in a console window and maintain context. But how can I achieve the same effect in an HTTP request?
Additionally, there will be multiple HTTP requests simultaneously accessing the GetGPTMes function. How to handle this is a bit challenging for me!
Thanks in advance for any suggestions and help.
var bot = new ChatGpt(sk, options);
var prompt = string.Empty;
while (true)
{
Console.Write("You: ");
prompt = Console.ReadLine();
if (prompt is null) break;
if (string.IsNullOrWhiteSpace(prompt)) break;
if (prompt == "exit") break;
Console.Write("Gpt: ");
await bot.AskStream(Console.Write, prompt, "default");
Console.WriteLine();
}
Powershell Code Test:
# I need to implement Multiple conversations with ChatGPT while keeping context
# 1
Invoke-RestMethod http://localhost:4455/GetGPTMes -Method Post -Body @{ userMes = 'What is the population of the United States?' }
# 2
Invoke-RestMethod http://localhost:4455/GetGPTMes -Method Post -Body @{ userMes = 'Translate the previous answer into French.' }
# 3
Invoke-RestMethod http://localhost:4455/GetGPTMes -Method Post -Body @{ userMes = 'Please make it shorter.' }
// class "Functions2.cs"
/*/ nuget ChatGPTNet\ChatGPT.Net; /*/
using ChatGPT.Net;
using ChatGPT.Net.DTO.ChatGPT;
static partial class Functions
{
public static string GetGPTMes(string userMes)
{
string sk = "sk-XXXXX"; //ChatGpt apiKey
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 bot = new ChatGpt(sk, options);
var task = bot.Ask(userMes);
task.Wait(); // Wait for the task to complete
var r = task.Result; // Get the result synchronously
print.it(r);
return r;
}
}