-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
67 lines (48 loc) · 2.17 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
64
65
66
67
using FunctionCallingStepwiseDemo.Plugins.WeatherPlugin;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Planning;
namespace FunctionCallingStepwiseDemo
{
internal class Program
{
static async Task Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Hello, Microsoft Semantic Kernel - 1.0 - FunctionCalling-StepwisePlanner Demo");
var kernel = CreateKernelBuilder();
var prompt = "Provide me with the historical and weather details for Chennai.";
#pragma warning disable SKEXP0061
//Create a function calling stepwise planner
FunctionCallingStepwisePlanner functionCallingStepwisePlanner = new();
//Execute the planner
var result = await functionCallingStepwisePlanner.ExecuteAsync(kernel!, prompt);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine();
//Display the final answer
Console.WriteLine(result.FinalAnswer);
//Display the chat history ( plan )
if (result.ChatHistory != null)
{
Console.ForegroundColor = ConsoleColor.DarkRed;
foreach (var chat in result.ChatHistory)
{
Console.WriteLine($"{chat.Role} - {chat.Content}");
}
}
Console.Read();
#pragma warning restore SKEXP0061
}
private static Kernel? CreateKernelBuilder()
{
//Create a kernel builder and add the Azure OpenAI Chat Completion service
var builder = Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(Config.DeploymentOrModelId, Config.Endpoint, Config.ApiKey);
//Add the location plugin
var plugInDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Plugins", "location");
builder.Plugins.AddFromPromptDirectory(plugInDirectory, "location");
//Add the weather plugin
builder.Plugins.AddFromObject(new ExternalWeatherPlugin(Config.WeatherApiKey));
return builder.Build()!;
}
}
}