AI Assistant Extensions
- 8 minutes to read
AI Assistant extensions allow you to enhance the way your users interact with and manage text content. These extensions leverage advanced natural language processing (NLP) technologies to offer automated, intelligent text manipulation capabilities directly within your Windows Forms applications.
Applies To
Activate AI Assistant
1. Install DevExpress NuGet Packages
DevExpress.AIIntegration.WinForms
DevExpress.Win.Design
(enables design-time features for DevExpress UI controls)
Read the following help topics for information on how to obtain the DevExpress NuGet Feed and install DevExpress NuGet packages:
- Choose Between Offline and Online DevExpress NuGet Feeds
- Install NuGet Packages in Visual Studio, VS Code, and Rider
2. Register AI Client
The following code snippet registers the Azure OpenAI client:
using Microsoft.Extensions.AI;
using DevExpress.AIIntegration;
internal static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
IChatClient asChatClient = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey))
.AsChatClient("GPT4o");
AIExtensionsContainerDesktop.Default.RegisterChatClient(asChatClient);
Application.Run(new Form1());
}
static string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
static string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
}
Tip
Read the following help topic for additional information: How to Register an AI Client.
3. Create and Configure AI Assistant Behaviors
Follow the steps below to apply a behavior to a control at design time:
- Drop the BehaviorManager component from the Toolbox onto a Form.
- Use the BehaviorManager’s smart tag menu to edit behaviors.
Add required AI-powered text transform behaviors and configure their settings as needed.
Run the application. Select the text in the
MemoEdit
and invoke the context menu. The context menu displays the AI Assistant submenu with AI-powered commands:Click the required command. The AI processes the command and generates an answer. The AI-generated answer is displayed in a dialog. A user can easily insert the answer directly into a document or text field with a single click.
The user can insert the AI’s answer above/below the cursor, replace all content or selected text, or copy the answer to the clipboard.
Change Style
ChangeStyleBehavior rephrases or paraphrases the selected text while retaining its original meaning. This behavior allows you to generate alternative versions of the same content to match a specific genre or format. You can choose from 12 predefined styles (see WritingStyle).
The following code snippet registers a ChangeStyleBehavior
and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration.WinForms;
//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<ChangeStyleBehavior>(memoEdit1, behavior => {
//behavior.Properties.Temperature = 0.6f;
});
}
}
Change Tone
ChangeToneBehavior adjusts the tone of the text to meet audience or context requirements. This option helps tailor the voice of your content.
Tone styles include:
- Casual
- Confident
- Friendly
- Professional
- Straightforward
The following code snippet registers a ChangeToneBehavior
and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration.WinForms;
//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<ChangeToneBehavior>(memoEdit1, behavior => {
//behavior.Properties.Temperature = 0.6f;
});
}
}
Expand
ExpandBehavior enriches your text with additional information or in-depth explanations.
The following code snippet registers an ExpandBehavior
and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration.WinForms;
//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<ExpandBehavior>(memoEdit1, behavior => {
//behavior.Properties.Temperature = 0.6f;
});
}
}
Explain
ExplainBehavior transforms text into more understandable terms that make complex content more accessible and understandable.
The following code snippet registers an ExplainBehavior
and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration.WinForms;
//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<ExplainBehavior>(memoEdit1, behavior => {
//behavior.Properties.Temperature = 0.6f;
});
}
}
Proofread
ProofreadBehavior reviews the text for spelling, grammar, punctuation, and style errors.
The following code snippet registers a ProofreadBehavior
and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration.WinForms;
//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<ProofreadBehavior>(memoEdit1, behavior => {
//behavior.Properties.Temperature = 0.6f;
});
}
}
Shorten
ShortenBehavior removes unnecessary details and makes content more concise.
The following code snippet registers a ShortenBehavior
and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration.WinForms;
//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<ShortenBehavior>(memoEdit1, behavior => {
//behavior.Properties.Temperature = 0.6f;
});
}
}
Summarize
SummarizeBehavior generates a brief summary of long text.
SummarizeBehavior
supports the following summarization modes:
Abstractive Summarization
Generates a summary by understanding the context of the original text and rephrasing it in a new, concise form. The AI essentially “writes” a new summary based on its understanding, which may include new sentences that were not present in the original text.
Extractive Summarization
Selects and extracts key sentences or phrases from the original text. The AI identifies the most important parts of the content and combines them into a summary without altering the original wording.
The following code snippet registers a SummarizeBehavior and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.WinForms;
//...
public partial class MemoEdit : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<SummarizeBehavior>(memoEdit1, behavior => {
behavior.Properties.SummarizationMode = SummarizationMode.Extractive;
});
}
}
Translate
TranslateBehavior converts the text from one language to another while maintaining the original meaning and context. Use the Languages parameter to specify target languages/cultures for text translation.
The following code snippet registers a TranslateBehavior
and assigns it to a MemoEdit
control:
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.WinForms;
using DevExpress.AIIntegration.Desktop;
//...
public partial class MemoEdit : DevExpress.XtraEditors.XtraForm {
public MemoEdit() {
InitializeComponent();
behaviorManager1.Attach<TranslateBehavior>(memoEdit1, behavior => {
behavior.Properties.Languages = new LanguageInfo[] {
new LanguageInfo("de-DE"),
new LanguageInfo("es-ES")
};
});
}
}
Ask AI Assistant (Custom Prompt)
CustomRequestBehavior displays the “Ask AI Assistant” item in the context menu. The “Ask AI Assistant” item invokes a dialog that allows users to interact with an AI-powered assistant directly within your application. A user can enter a question or prompt. The AI assistant will process the query and generate an answer.
The user can easily insert the answer directly into a document or text field with a single click. The user can insert the answer above/below the cursor, replace all content or selected text, or copy the answer to the clipboard.
Temperature
The Temperature parameter controls the balance between creativity and consistency in AI responses. Lower temperatures yield more predictable and focused outputs, while higher temperatures produce more diverse and creative responses.
The Temperature
parameter is predefined for DevExpress AI-powered behaviors.
AI-powered Behavior | Temperature (Default) |
---|---|
Summarize Behavior | 1 |
Change Style Behavior | 0.6 |
Change Tone Behavior | 0.5 |
Translate Behavior | 0.5 |
Proofread Behavior | 0.2 |
Expand Behavior | – |
Explain Behavior | – |
Shorten Behavior | – |
Chunking (Processing Long Input Text)
If input text is too long, the DevExpress control displays a dialog that informs a user that the input text must be divided into manageable chunks to ensure accurate processing.
The user can process chunks one by one by pressing the “Proceed” button, or enable the “I consent to process all remaining chunks” option to process all chunks automatically.
After processing, chunks are reassembled into a single output.
Tip
Use the ChunkMaxLength property to specify how much text can be processed simultaneously. The chunk length is limited by 6,000 symbols. The TextBufferMaxSize property specifies the maximum size of the input text, in bytes.