wpf-405606-ai-powered-extensions-ai-chat-control-chat-with-your-own-data.md
When integrating the AI Chat Control with the OpenAI Assistant API, you can configure it to retain and reference a specific context (for example, a text file or a PDF document). By providing a supplementary document as a context source, the assistant is primed with background information. OpenAI automatically parses the document and searches through it to retrieve relevant content to better respond to user queries.
Install the DevExpress.AIIntegration.OpenAI NuGet package.
Create an assistant.
Register the OpenAI Assistant service in the App.xaml.cs file:
The following screenshot shows the result:
Tip
The AI Chat Control does not render citation references as clickable links. These references appear as plain text (for example, [6:2†source]) in the output. To remove citation references from the AI response before display, handle the AI Chat Control’s MarkdownConvert event:
using Markdig;
using System.Text.RegularExpressions;
void AiChatControl1_MarkdownConvert(object sender, AIChatControlMarkdownConvertEventArgs e) {
string output = ClearCitationReferences(e.MarkdownText);
e.HtmlText = (MarkupString)Markdown.ToHtml(output);
}
string ClearCitationReferences(string text) {
return Regex.Replace(text, @"\【.*?】", "");
}
See Also