Notitie
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen u aan te melden of de directory te wijzigen.
Voor toegang tot deze pagina is autorisatie vereist. U kunt proberen de mappen te wijzigen.
AI-reacties bevatten vaak citatie- en feedbackcontroles. Een AI-engine kan bronmarkeringen teruggeven, zoals [doc1] in gegenereerde tekst.
StreamingResponse zet die markeringen om in genummerde verwijzingen, voegt de bijbehorende citatiemetadata toe en voegt bedieningselementen voor duimpje omhoog en duimpje omlaag toe aan het uiteindelijke bericht.
Voeg citaties en feedback toe aan een streaming-antwoord
Voeg elke citatie toe in dezelfde volgorde als de marker in de gegenereerde tekst. Wanneer tekst in de wachtrij staat, zet de streamingrespons [doc1] of [docs1] om in [1] met behulp van CitationUtils.FormatCitationsResponse. Je hoeft de formatteringstool meestal niet direct aan te roepen.
using Microsoft.Agents.Core.Models;
var citations = new List<Citation>
{
new(
content: "Contoso offers 30 days of annual leave.",
title: "Contoso employee handbook",
url: "https://www.example.com/handbook")
};
turnContext.StreamingResponse.FeedbackLoopEnabled = true;
turnContext.StreamingResponse.EnableGeneratedByAILabel = true;
turnContext.StreamingResponse.QueueTextChunk(
"Contoso employees receive 30 days of annual leave [doc1].");
turnContext.StreamingResponse.AddCitations(citations);
await turnContext.StreamingResponse.EndStreamAsync(cancellationToken);
Gebruik AddCitation(citation, position) wanneer je een specifiek referentienummer moet toewijzen. Gebruik AddCitations(citations) om een verzameling in lijstvolgorde te nummeren.
context.streamingResponse.setFeedbackLoop(true)
context.streamingResponse.queueTextChunk(
'Contoso employees receive 30 days of annual leave [doc1].'
)
context.streamingResponse.setCitations([
{
content: 'Contoso offers 30 days of annual leave.',
title: 'Contoso employee handbook',
url: 'https://www.example.com/handbook',
filepath: null
}
])
await context.streamingResponse.endStream()
from microsoft_agents.hosting.core import Citation
context.streaming_response.set_feedback_loop(True)
context.streaming_response.queue_text_chunk(
"Contoso employees receive 30 days of annual leave [doc1]."
)
context.streaming_response.set_citations(
[
Citation(
content="Contoso offers 30 days of annual leave.",
title="Contoso employee handbook",
url="https://www.example.com/handbook",
)
]
)
await context.streaming_response.end_stream()
Ingediende feedback afhandelen
Registreer een AgentApplication.OnFeedbackLoop handler in de agent constructor:
public MyAgent(AgentApplicationOptions options) : base(options)
{
OnFeedbackLoop(OnFeedbackAsync);
}
private Task OnFeedbackAsync(
ITurnContext turnContext,
ITurnState turnState,
FeedbackData feedbackData,
CancellationToken cancellationToken)
{
var reaction = feedbackData.ActionValue?.Reaction;
var feedbackText = feedbackData.ActionValue?.Feedback;
var activityId = feedbackData.ReplyToId;
// Store or process the feedback for the referenced activity.
return Task.CompletedTask;
}
import { onTeamsFeedbackLoop } from '@microsoft/agents-hosting-extensions-msteams'
onTeamsFeedbackLoop(app, async (context, state, feedbackData) => {
const reaction = feedbackData.actionValue?.reaction
const feedbackText = feedbackData.actionValue?.feedback
const activityId = feedbackData.replyToId
// Store or process the feedback for the referenced activity.
})
De Python SDK kan feedbackcontroles op een streamingrespons mogelijk maken. Een getypte binnenkomende feedbackroute is momenteel niet beschikbaar.
De waarde in FeedbackData.ActionValue.Reaction geeft de geselecteerde feedbackoptie met een duim omhoog of omlaag aan. Het staat los van een activiteit rond emoji-reacties op berichten.
Reacties op berichten beheren
Berichtreacties zijn emoji-reacties die gebruikers toevoegen aan of verwijderen uit een bericht. Ze komen aan als reactie-acties op berichten in plaats van als feedbacklus-inzendingen.
Registreer de standaard AgentApplication reactieroutes voor berichten:
public MyAgent(AgentApplicationOptions options) : base(options)
{
OnMessageReactionsAdded(OnReactionsAddedAsync);
OnMessageReactionsRemoved(OnReactionsRemovedAsync);
}
private Task OnReactionsAddedAsync(
ITurnContext turnContext,
ITurnState turnState,
CancellationToken cancellationToken)
{
foreach (var reaction in turnContext.Activity.ReactionsAdded)
{
// Process reaction.Type for turnContext.Activity.ReplyToId.
}
return Task.CompletedTask;
}
private Task OnReactionsRemovedAsync(
ITurnContext turnContext,
ITurnState turnState,
CancellationToken cancellationToken)
{
foreach (var reaction in turnContext.Activity.ReactionsRemoved)
{
// Process reaction.Type for turnContext.Activity.ReplyToId.
}
return Task.CompletedTask;
}
import {
onTeamsMessageReactionsAdded,
onTeamsMessageReactionsRemoved
} from '@microsoft/agents-hosting-extensions-msteams'
onTeamsMessageReactionsAdded(app, async (context) => {
for (const reaction of context.activity.reactionsAdded ?? []) {
// Process reaction.type for context.activity.replyToId.
}
})
onTeamsMessageReactionsRemoved(app, async (context) => {
for (const reaction of context.activity.reactionsRemoved ?? []) {
// Process reaction.type for context.activity.replyToId.
}
})
Een getypte Teams-berichtreactieroute is momenteel niet beschikbaar in de Python SDK.
Voor ondersteunde reactietypen en cliëntgedrag, zie: