Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HTTP request Multiple conversations with ChatGPT while keeping context
#6
I don't quite understand the meaning of the code. The result of the code below is not correct.
 
Code:
Copy      Help
using ChatGPT.Net;
using ChatGPT.Net.DTO.ChatGPT;

void Main()
{
    // First question
    string firstQuestion = "What is the capital of Japan?";
    string firstResponse = GetGPTMes(firstQuestion, true);
    Console.WriteLine($"Question: {firstQuestion}\nAnswer: {firstResponse}\n");

    // Second question
    string secondQuestion = $"Translate the previous answer into French.";
    string secondResponse = GetGPTMes(secondQuestion, false);
    Console.WriteLine($"Question: {secondQuestion}\nAnswer: {secondResponse}\n");
}

// Define ChatGPT related functions and variables
private static string apiKey = "sk-xxx"; // ChatGpt apiKey
private static 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
};
private static ChatGpt bot;

// Define ChatGPT related functions
public static string GetGPTMes(string userMes, bool createBot)
{
  
    if (bot == null || createBot)
    {
        bot = new ChatGpt(apiKey, options);
    }

    var task = bot.Ask(userMes);
    task.Wait(); // Wait for the task to complete

    var r = task.Result; // Get the result synchronously
    return r;
}


Messages In This Thread
RE: HTTP request Multiple conversations with ChatGPT while keeping context - by Davider - 04-29-2024, 03:57 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)