microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
31d1aa2aae7f45f1943ebae04ce8c66899e89e48

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Samples/Samples.Lights/Program.cs

38lines · modecode

1using System.Text.Json;
2
3using Microsoft.Teams.AI.Models.OpenAI.Extensions;
4using Microsoft.Teams.Apps.Extensions;
5using Microsoft.Teams.Plugins.AspNetCore.DevTools.Extensions;
6using Microsoft.Teams.Plugins.AspNetCore.Extensions;
7
8using Samples.Lights;
9
10var builder = WebApplication.CreateBuilder(args);
11builder.AddTeams().AddTeamsDevTools().AddOpenAI<LightsPrompt>();
12
13var app = builder.Build();
14var teams = app.UseTeams();
15
16teams.OnMessage("/history", async context =>
17{
18 var state = State.From(context);
19 await context.Send(JsonSerializer.Serialize(state.Messages, new JsonSerializerOptions()
20 {
21 WriteIndented = true
22 }));
23});
24
25teams.OnMessage(async context =>
26{
27 var state = State.From(context);
28 var prompt = app.Services.GetOpenAIChatPrompt();
29
30 await prompt.Send(context.Activity.Text, new() { Messages = state.Messages }, (chunk) => Task.Run(() =>
31 {
32 context.Stream.Emit(chunk);
33 }), context.CancellationToken);
34
35 state.Save(context);
36});
37
38app.Run();