Back to Devexpress

Chat with Your Own Data

windowsforms-405582-ai-powered-extensions-ai-chat-control-chat-with-your-own-data.md

latest1.8 KB
Original Source

Chat with Your Own Data

  • Sep 29, 2025
  • 5 minutes to read

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.

  1. Install the DevExpress.AIIntegration.OpenAI NuGet package.

  2. Create an assistant.

  3. Register the OpenAI Assistant service:

  4. Handle the Initialized event with an async handler. Call the e.SetupAssistantAsync method to supply the Open AI Assistant identifier:

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:

csharp
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

AI Chat Control