microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3a0ca1a8dc72b37e28eabbac76ec8e4e889b0a75

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/A365Mcp/Program.cs

39lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using System.ClientModel;
5using A365Mcp;
6using Azure.AI.OpenAI;
7using Microsoft.Extensions.AI;
8using Microsoft.Teams.Apps;
9
10// Wires up the Teams bot application and delegates AI execution to Agent.
11// Handler registration lives in TeamsBotAppHandlers.cs.
12
13WebApplicationBuilder builder = WebApplication.CreateSlimBuilder(args);
14builder.Services.AddTeamsBotApplication();
15
16builder.Services.AddChatClient(sp =>
17{
18 IConfiguration config = sp.GetRequiredService<IConfiguration>();
19 string endpoint = config["AzureOpenAI:Endpoint"] ?? throw new InvalidOperationException("AzureOpenAI:Endpoint is required.");
20 string apiKey = config["AzureOpenAI:ApiKey"] ?? throw new InvalidOperationException("AzureOpenAI:ApiKey is required.");
21 string modelId = config["AzureOpenAI:ModelId"] ?? throw new InvalidOperationException("AzureOpenAI:ModelId is required.");
22
23 return new AzureOpenAIClient(new Uri(endpoint), new ApiKeyCredential(apiKey))
24 .GetChatClient(modelId)
25 .AsIChatClient();
26})
27.UseFunctionInvocation();
28
29builder.Services.AddSingleton<IMcpClientFactory, McpClientFactory>();
30builder.Services.AddSingleton<Agent>();
31
32WebApplication webApp = builder.Build();
33
34Agent agent = webApp.Services.GetRequiredService<Agent>();
35ILogger handlerLogger = webApp.Services.GetRequiredService<ILoggerFactory>().CreateLogger("A365Mcp.TeamsBotAppHandlers");
36
37webApp.UseTeamsBotApplication().RegisterHandlers(agent, handlerLogger);
38
39webApp.Run();
40