-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
30 lines (21 loc) · 815 Bytes
/
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
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
var builder = Kernel.CreateBuilder();
builder.AddOllamaChatCompletion("phi3.5:latest", new Uri("http://localhost:11434"));
var kernel = builder.Build();
var chatService = kernel.GetRequiredService<IChatCompletionService>();
var history = new ChatHistory();
history.AddSystemMessage("You are a helpful assistant.");
while (true)
{
Console.Write("You: ");
var userMessage = Console.ReadLine();
if (string.IsNullOrWhiteSpace(userMessage))
{
break;
}
history.AddUserMessage(userMessage);
var response = await chatService.GetChatMessageContentAsync(history);
Console.WriteLine($"Bot: {response.Content}");
history.AddMessage(response.Role, response.Content ?? string.Empty);
}