You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to add citations for ai messages by overriding SayCommandAsync in C# project. And I found that there will be no citation in the messages.
It works fine in js/ts projects. List the code below. Please help me to figure out the problem. Thanks.
Since the citation util class is not exposed yet mentioned in #2309, I copied the CitationUtils code from the library into my project.
usingMicrosoft.Bot.Builder;usingMicrosoft.Bot.Schema;usingMicrosoft.Teams.AI.AI.Action;usingMicrosoft.Teams.AI.AI.Planners;usingMicrosoft.Teams.AI.AI;usingNewtonsoft.Json.Linq;usingMicrosoft.Bot.Connector;usingSystem.Text.Json;usingSystem.Text.Json.Serialization;namespaceMyTeamsApp021401{publicclassActionHandlers{[Action(AIConstants.SayCommandActionName,isDefault:true)]publicasyncTask<string>SayCommandAsync([ActionTurnContext]ITurnContextturnContext,[ActionParameters]PredictedSayCommandcommand,CancellationTokencancellationToken=default){if(command.Response.Content==null||command.Response.GetContent<string>()==string.Empty){return"";}stringoriginalContent=command.Response.GetContent<string>();stringcontent="";Rootresponse=null;try{response=JsonSerializer.Deserialize<Root>(originalContent);}catch(Exceptionerror){Console.Error.WriteLine($"Response is not valid json, send the raw text. error: {error}");awaitturnContext.SendActivityAsync(MessageFactory.Text(originalContent),default);return"";}// If the response from the AI includes citations, those citations will be parsed and added to the SAY command.List<ClientCitation>citations=new();intposition=1;if(response.Results!=null&&response.Results.Count>0){foreach(varcontentIteminresponse.Results){if(!string.IsNullOrEmpty(contentItem.CitationTitle)){varclientCitation=newClientCitation{Position=position,Appearance=newClientCitationAppearance{Name=contentItem.CitationTitle??$"Document #{position}",Url=contentItem.CitationUrl,Abstract=CitationUtils.Snippet(contentItem.CitationContent,500)}};content+=$"{contentItem.Answer}[{position}]<br>";position++;citations.Add(clientCitation);}else{content+=$"{contentItem.Answer}<br>";}}}else{content=originalContent;}boolisTeamsChannel=turnContext.Activity.ChannelId==Channels.Msteams;if(isTeamsChannel){content.Replace("\n","<br>");}varcontentText=citations.Count<1?content:CitationUtils.FormatCitationsResponse(content);varreferencedCitations=citations.Count>0?CitationUtils.GetUsedCitations(contentText,citations):null;varmessage=MessageFactory.Text(contentText);message.Type=ActivityTypes.Message;if(isTeamsChannel){message.ChannelData=new{feedbackLoopEnabled=false};}message.Entities=newList<Entity>{newAIEntity{AtType="Message",AtContext="https://schema.org",AtId="",AdditionalType=newList<string>{"AIGeneratedContent"},Citation=referencedCitations,//Citation = "Source: Microsoft Teams Documentation",Type="https://schema.org/Message"}};awaitturnContext.SendActivityAsync(message,default);returnstring.Empty;}}}publicclassResult{[JsonPropertyName("answer")]publicstringAnswer{get;set;}[JsonPropertyName("citationTitle")]publicstringCitationTitle{get;set;}[JsonPropertyName("citationContent")]publicstringCitationContent{get;set;}[JsonPropertyName("citationUrl")]publicstringCitationUrl{get;set;}}publicclassRoot{// add json property name result[JsonPropertyName("results")]publicList<Result>Results{get;set;}}
Reproduction Steps
1.
2.
3.
...
The text was updated successfully, but these errors were encountered:
Hi @xzf0587,
Currently there is no information available regarding the plans to support ai labels, citations, and feedback buttons in C#.
To achieve your requirements, we recommend you give your feedback in Teams Feedback Portal and you can now get latest Teams platform updates by subscribing to the RSS feed
Language
C#
Version
latest
Description
I tried to add citations for ai messages by overriding SayCommandAsync in C# project. And I found that there will be no citation in the messages.
It works fine in js/ts projects. List the code below. Please help me to figure out the problem. Thanks.
Since the citation util class is not exposed yet mentioned in #2309, I copied the CitationUtils code from the library into my project.
Reproduction Steps
The text was updated successfully, but these errors were encountered: