cleanup and advancements
This commit is contained in:
@@ -8,18 +8,50 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
static async Task Main()
|
static async Task Main()
|
||||||
{
|
{
|
||||||
string apiKey = "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";
|
string apiKey = "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";
|
||||||
string prompt = "What is the meaning of life?";
|
|
||||||
|
|
||||||
string response = await GetChatGPTResponse(apiKey, prompt);
|
singleMessage[] allMessages = [];
|
||||||
|
//allMessages = allMessages.Append(new singleMessage("system", "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair.")).ToArray();
|
||||||
|
//allMessages = allMessages.Append(new singleMessage("system", "You are a personal assistant, you give brief but exact answers.")).ToArray();
|
||||||
|
allMessages = allMessages.Append(new singleMessage("system", @"
|
||||||
|
You are a spanish teacher.
|
||||||
|
You speak simple spanish language.
|
||||||
|
|
||||||
Console.WriteLine("ChatGPT Response: ");
|
When the user makes mistakes
|
||||||
Console.WriteLine(response);
|
- You point out errors to the user
|
||||||
|
- English language is used to describe error details.
|
||||||
|
- Do not correct accents of characters.
|
||||||
|
- Do not correct upper- lower case errors.
|
||||||
|
")).ToArray();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
Console.Write(">> ");
|
||||||
|
var prompt = Console.ReadLine();
|
||||||
|
if (prompt?.ToLower() == "bye")
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
allMessages = allMessages.Append(new singleMessage("user", prompt)).ToArray();
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine();
|
||||||
|
var currentResponse = String.Empty;
|
||||||
|
var response = await GetChatGPTResponse(apiKey, allMessages);
|
||||||
|
|
||||||
|
Console.WriteLine(response);
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
allMessages = allMessages.Append(new singleMessage("assistant", response)).ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async Task<string> GetChatGPTResponse(string apiKey, string prompt)
|
static async Task<string> GetChatGPTResponse(string apiKey, singleMessage[] allMessages)
|
||||||
{
|
{
|
||||||
using (HttpClient client = new HttpClient())
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
@@ -28,13 +60,12 @@ class Program
|
|||||||
// Prepare the request data
|
// Prepare the request data
|
||||||
var requestData = new
|
var requestData = new
|
||||||
{
|
{
|
||||||
messages = new[] {
|
|
||||||
new { role = "system", content = "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair." },
|
|
||||||
new { role = "user", content = "Compose a poem that explains the concept of recursion in programming." }
|
|
||||||
},
|
|
||||||
model = "gpt-3.5-turbo",
|
model = "gpt-3.5-turbo",
|
||||||
max_tokens = 100,
|
messages = allMessages,
|
||||||
temperature = 0.7
|
max_tokens = 256,
|
||||||
|
top_p = 1,
|
||||||
|
frequency_penalty = 0,
|
||||||
|
presence_penalty = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
string jsonData = JsonSerializer.Serialize(requestData);
|
string jsonData = JsonSerializer.Serialize(requestData);
|
||||||
@@ -61,3 +92,14 @@ class Program
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class singleMessage
|
||||||
|
{
|
||||||
|
public string role { get; set; }
|
||||||
|
public string content { get; set; }
|
||||||
|
public singleMessage(string intitRole, string initContent)
|
||||||
|
{
|
||||||
|
role = intitRole;
|
||||||
|
content = initContent;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user