microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Samples/Samples.AI/Handlers/CitationsHandler.cs
48lines · modecode
| 1 | using Microsoft.Teams.Api.Activities; |
| 2 | using Microsoft.Teams.Api.Entities; |
| 3 | using Microsoft.Teams.Apps; |
| 4 | |
| 5 | namespace Samples.AI.Handlers; |
| 6 | |
| 7 | public static class CitationsHandler |
| 8 | { |
| 9 | /// <summary> |
| 10 | /// Demo citations functionality |
| 11 | /// </summary> |
| 12 | public static async Task HandleCitationsDemo(IContext<MessageActivity> context, CancellationToken cancellationToken = default) |
| 13 | { |
| 14 | Console.WriteLine($"[HANDLER] Citations demo handler invoked by user: {context.Activity.From.Name}"); |
| 15 | |
| 16 | var citedDocs = new[] |
| 17 | { |
| 18 | new { Title = "Weather Documentation", Content = "Weather data shows sunny conditions across the region" }, |
| 19 | new { Title = "Pokemon Database", Content = "Comprehensive database of Pokemon characteristics and abilities" }, |
| 20 | new { Title = "AI Development Guide", Content = "Best practices for integrating AI into Teams applications" } |
| 21 | }; |
| 22 | |
| 23 | var responseText = "Here's some information with citations [1] about weather patterns, " + |
| 24 | "[2] Pokemon data, and [3] AI development best practices."; |
| 25 | |
| 26 | Console.WriteLine($"[HANDLER] Creating message with {citedDocs.Length} citations"); |
| 27 | |
| 28 | var messageActivity = new MessageActivity |
| 29 | { |
| 30 | Text = responseText, |
| 31 | }.AddAIGenerated(); |
| 32 | |
| 33 | // Add citations |
| 34 | for (int i = 0; i < citedDocs.Length; i++) |
| 35 | { |
| 36 | Console.WriteLine($"[HANDLER] Adding citation [{i + 1}]: {citedDocs[i].Title}"); |
| 37 | messageActivity.AddCitation(i + 1, new CitationAppearance |
| 38 | { |
| 39 | Name = citedDocs[i].Title, |
| 40 | Abstract = citedDocs[i].Content |
| 41 | } |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | Console.WriteLine("[HANDLER] Sending message with citations to user"); |
| 46 | await context.Send(messageActivity, cancellationToken); |
| 47 | } |
| 48 | } |