The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 895 - File: showthread.php PHP 7.2.34 (Linux)
File Line Function
/showthread.php 895 errorHandler->error




Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTP request Multiple conversations with ChatGPT while keeping context
#1
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! Sad

Thanks in advance for any suggestions and help.
 
Code:
Copy      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:
 
Code:
Copy      Help
# 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.' }
 
 
Code:
Copy      Help
// 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;
    }
}


Messages In This Thread
HTTP request Multiple conversations with ChatGPT while keeping context - by Davider - 04-28-2024, 01:58 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)