-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
110 lines (92 loc) · 4.2 KB
/
Copy pathProgram.cs
File metadata and controls
110 lines (92 loc) · 4.2 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using Azure.Core;
using Azure.Identity;
using Microsoft.DurableTask.Client;
using Microsoft.DurableTask.Client.AzureManaged;
using Microsoft.DurableTask.Worker;
using Microsoft.DurableTask.Worker.AzureManaged;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Process.Runtime.DurableTask;
using Microsoft.SemanticKernel.Process.Tools;
namespace SampleApp;
internal class Program
{
static async Task<int> Main(string[] args)
{
// TODO: Convert to web app where each sample is a different API
HostApplicationBuilder hostBuilder = Host.CreateApplicationBuilder(args);
// Configure logging
hostBuilder.Services.AddLogging((logging) =>
{
logging.AddDebug();
logging.AddSimpleConsole(options =>
{
options.IncludeScopes = true;
options.SingleLine = true;
options.TimestampFormat = "[HH:mm:ss.fff] ";
});
});
// Configure the Kernel with DI and Azure OpenAI.
TokenCredential credential = new DefaultAzureCredential();
string? azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
if (string.IsNullOrEmpty(azureOpenAIEndpoint))
{
Console.Error.WriteLine("Please set a value for the AZURE_OPENAI_ENDPOINT environment variable.");
Console.Error.WriteLine("Example: https://[name].openai.azure.com");
return 1;
}
string? deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME");
if (string.IsNullOrEmpty(deploymentName))
{
Console.Error.WriteLine("Please set a value for the AZURE_OPENAI_DEPLOYMENT_NAME environment variable.");
Console.Error.WriteLine("Example: gpt-4o-mini");
return 1;
}
hostBuilder.Services.AddKernel().AddAzureOpenAIChatCompletion(deploymentName, azureOpenAIEndpoint, credential);
// Configure the Durable Task Scheduler managed backend (state storage and distributed task dispatching)
string dtsConnectionString = Environment.GetEnvironmentVariable("DTS_CONNECTION_STRING")
?? "Endpoint=http://localhost:8080;TaskHub=default;Authentication=None";
hostBuilder.Services
.AddDurableTaskClient(cfg => cfg.UseDurableTaskScheduler(dtsConnectionString))
.AddDurableTaskWorker(
cfg =>
{
cfg.UseDurableTaskScheduler(dtsConnectionString);
cfg.AddProcessFrameworkSupport();
});
// Create the process builder
ProcessBuilder processBuilder = new("DocumentationGeneration");
// Add the steps
ProcessStepBuilder infoGatheringStep = processBuilder.AddStepFromType<GatherProductInfoStep>();
ProcessStepBuilder docsGenerationStep = processBuilder.AddStepFromType<GenerateDocumentationStep>();
ProcessStepBuilder docsPublishStep = processBuilder.AddStepFromType<PublishDocumentationStep>();
// Orchestrate the events
processBuilder
.OnInputEvent("Start")
.SendEventTo(new(infoGatheringStep));
infoGatheringStep
.OnFunctionResult()
.SendEventTo(new(docsGenerationStep));
docsGenerationStep
.OnEvent("DocumentationGenerated")
.SendEventTo(new(docsPublishStep));
// Build and run the process
KernelProcess process = processBuilder.Build();
Console.WriteLine("Process definition:");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(process.ToMermaid());
Console.WriteLine();
Console.ResetColor();
IHost host = hostBuilder.Build();
await host.StartAsync();
// Start a process instance
Kernel kernel = host.Services.GetRequiredService<Kernel>();
await process.StartAsync(kernel, new KernelProcessEvent { Id = "Start", Data = "Contoso GlowBrew" });
Console.WriteLine("Press [ENTER] to exit.");
Console.ReadLine();
await host.StopAsync();
return 0;
}
}