forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
44 lines (32 loc) · 1.22 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
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.ChatCompletion;
using ProcessFramework.Aspire.Shared;
var builder = WebApplication.CreateBuilder(args);
AppContext.SetSwitch("Microsoft.SemanticKernel.Experimental.GenAI.EnableOTelDiagnosticsSensitive", true);
builder.AddServiceDefaults();
builder.AddAzureOpenAIClient("openAiConnectionName");
builder.Services.AddKernel().AddAzureOpenAIChatCompletion("gpt-4o");
var app = builder.Build();
app.UseHttpsRedirection();
app.MapPost("/api/summary", async (Kernel kernel, SummarizeRequest summarizeRequest) =>
{
ChatCompletionAgent summaryAgent =
new()
{
Name = "SummarizationAgent",
Instructions = "Summarize user input",
Kernel = kernel
};
// Add a user message to the conversation
var message = new ChatMessageContent(AuthorRole.User, summarizeRequest.TextToSummarize);
// Generate the agent response(s)
await foreach (ChatMessageContent response in summaryAgent.InvokeAsync(message).ConfigureAwait(false))
{
return response.Items.Last().ToString();
}
return null;
});
app.MapDefaultEndpoints();
app.Run();