How to access AnnotationContent with OpenAI assistant, streaming mode in c# #9327
-
Hi team can someone post how to access Annotations in c# when OpenAi assistant is in streaming thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@crickman - do you know if we have a sample for this? |
Beta Was this translation helpful? Give feedback.
-
Hi @JP-droidic - I don't believe we have a sample in the repo that combines file-search with streaming for the assistant-agent. We have, however, recently published a few examples to our learn-site documentation that covers this: In this example, the List<StreamingAnnotationContent> footnotes = [];
await foreach (StreamingChatMessageContent chunk in agent.InvokeStreamingAsync(threadId))
{
// Capture annotations for footnotes
footnotes.AddRange(chunk.Items.OfType<StreamingAnnotationContent>());
// Render chunk with replacements for unicode brackets.
Console.Write(chunk.Content.ReplaceUnicodeBrackets());
} A somewhat raw version of the citation is then displayed: if (footnotes.Count > 0)
{
Console.WriteLine();
foreach (StreamingAnnotationContent footnote in footnotes)
{
Console.WriteLine($"#{footnote.Quote.ReplaceUnicodeBrackets()} - {fileReferences[footnote.FileId!].Filename} (Index: {footnote.StartIndex} - {footnote.EndIndex})");
}
} For a more full citation expression, the file information must be retrieved via the
Appreciate any feedback you have on this example. |
Beta Was this translation helpful? Give feedback.
Hi @JP-droidic - I don't believe we have a sample in the repo that combines file-search with streaming for the assistant-agent. We have, however, recently published a few examples to our learn-site documentation that covers this:
https://learn.microsoft.com/en-us/semantic-kernel/frameworks/agent/examples/example-assistant-search?pivots=programming-language-csharp
In this example, the
StreamingAnnotationContent
is being incrementally added to a list to that it may be rendered as foot-notes to the response: