microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
5f28f97ab3194cc1dc674ef145fc0afe9c4bfd21

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/AFBot/Program.cs

41lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System.ClientModel;
5using AFBot;
6using Azure.AI.OpenAI;
7using Azure.Monitor.OpenTelemetry.AspNetCore;
8using Microsoft.Agents.AI;
9using Microsoft.Bot.Core;
10using Microsoft.Bot.Core.Hosting;
11using Microsoft.Bot.Core.Schema;
12using OpenAI;
13
14WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
15
16WebApplicationBuilder webAppBuilder = WebApplication.CreateSlimBuilder(args);
17webAppBuilder.Services.AddOpenTelemetry().UseAzureMonitor();
18webAppBuilder.Services.AddBotApplication<BotApplication>();
19WebApplication webApp = webAppBuilder.Build();
20BotApplication botApp = webApp.UseBotApplication<BotApplication>();
21
22AzureOpenAIClient azureClient = new(
23 new Uri("https://ridofoundry.cognitiveservices.azure.com/"),
24 new ApiKeyCredential(Environment.GetEnvironmentVariable("AZURE_OpenAI_KEY")!));
25
26ChatClientAgent agent = azureClient.GetChatClient("gpt-5-nano").CreateAIAgent(
27 instructions: "You are an expert acronym maker, made an acronym made up from the first three characters of the user's message. " +
28 "Some examples: OMW on my way, BTW by the way, TVM thanks very much, and so on." +
29 "Always respond with the three complete words only, and include a related emoji at the end.",
30 name: "AcronymMaker");
31
32botApp.Use(new DropTypingMiddleware());
33botApp.OnActivity = async (activity, cancellationToken) =>
34{
35 await botApp.SendTypingActivityAsync(activity, cancellationToken);
36 AgentRunResponse res = await agent.RunAsync(activity?.Text ?? "OMW");
37 CoreActivity reply = activity!.CreateReplyMessageActivity(res.Text);
38 await botApp.SendActivityAsync(reply, cancellationToken);
39};
40
41webApp.Run();