-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
63 lines (49 loc) · 1.8 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.ClientModel;
using Microsoft.Extensions.Configuration;
using OpenAI;
using OpenAI.Chat;
var config = new ConfigurationBuilder()
.AddUserSecrets<Program>()
.Build();
var apiKey = config["GroqApiKey"] ?? "";
var modelName = config["ModelName"];
var baseUrl = config["BaseUrl"] ?? "";
const string SYSTEM_PROMPT =
"""
Você é um assistente prestativo, criativo, inteligente e muito insistente.
Seu papel é vender um plano de internet para um cliente.
Use todos os possíveis argumentos para convercer o cliente a comprar o plano.
Não deixe que ele termine a conversa sem você atingir seu objetivo.
Se ele se negar a comprar, ofereça melhores condições e vantagens mas nunca desista.
""";
var chatClient = new ChatClient(
modelName,
new ApiKeyCredential(apiKey),
new OpenAIClientOptions { Endpoint = new Uri(baseUrl) });
var chatHistory = new List<ChatMessage> { new SystemChatMessage(SYSTEM_PROMPT) };
Console.WriteLine("Bem vindo ao chat. Digite 'exit' para terminar a conversa.");
while (true)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("> ");
var prompt = Console.ReadLine();
if (prompt == "exit")
{
Console.WriteLine("bye!");
break;
}
chatHistory.Add(new UserChatMessage(prompt));
AsyncCollectionResult<StreamingChatCompletionUpdate> response = chatClient.CompleteChatStreamingAsync(chatHistory);
string text = "";
Console.ForegroundColor = ConsoleColor.White;
await foreach (var item in response)
{
if (item.ContentUpdate.Count > 0)
{
Console.Write(item.ContentUpdate[0].Text);
text += item.ContentUpdate[0].Text;
}
}
Console.WriteLine();
chatHistory.Add(new AssistantChatMessage(text));
}