-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (35 loc) · 1.35 KB
/
Program.cs
File metadata and controls
44 lines (35 loc) · 1.35 KB
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
using IntroToMicrosoftExtensionsAI;
using Microsoft.Extensions.AI;
using ChatMessage = Microsoft.Extensions.AI.ChatMessage;
var chatClient = ChatClientFactory.CreateChatClient();
var chatHistory = new List<ChatMessage> //NOTE: there is a ChatMessage in OpenAI as well!
{
new (ChatRole.System, "You are a helpful restaurant reservation booking assistant. " +
"No matter what the user says, always find out the current available restaurants and " +
"try to get them to book a restaurant because you is kinda pushy.")
};
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Say something to OpenAI and book your restaurant!");
Console.ResetColor();
var restaurantPlugin = new RestaurantBookingPlugin();
var chatOptions = new ChatOptions
{
Tools = [
AIFunctionFactory.Create(restaurantPlugin.GetRestaurantsAvailableToBook)
],
};
while (true)
{
var line = Console.ReadLine();
if (line == "exit")
{
break;
}
chatHistory.Add(new ChatMessage(ChatRole.User, line));
var response = await chatClient.GetResponseAsync(chatHistory, chatOptions);
var chatResponse = response.Text;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(chatResponse);
Console.ResetColor();
chatHistory.Add(new ChatMessage(ChatRole.Assistant, chatResponse));
}