Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

BaseAIContextMenuItem Class

Implements the base functionality of AI-powered context menu items.

Namespace: DevExpress.AIIntegration.Blazor.RichEdit

Assembly: DevExpress.AIIntegration.Blazor.RichEdit.v24.2.dll

NuGet Package: DevExpress.AIIntegration.Blazor.RichEdit

#Declaration

C#
public abstract class BaseAIContextMenuItem :
    BasePopupItem

#Remarks

Use the BaseAIContextMenuItem class to implement a custom AI-powered context menu item.

  1. Create the BaseAIContextMenuItem class successor. Specify its text and provide a custom prompt.

    C#
    public class ShakespeareAIContextMenuItem : BaseAIContextMenuItem {
        [Inject] IAIExtensionsContainer? aIExtensionsContainer { get; set; }
    
        protected override string DefaultItemText => "Rewrite like Shakespeare";
    
        protected override Task<TextResponse> GetCommandTextResult(string text) {
            var customExtension = aIExtensionsContainer.CreateCustomPromptExtension();
            return customExtension.ExecuteAsync(new CustomPromptRequest("Rewrite the following text in William Shakespeare style.", text));
        }
    }
    
  2. Add the new item to the AdditionalItems collection.

    razor
    @using DevExpress.AIIntegration.Blazor.RichEdit
    @using DevExpress.Blazor.RichEdit
    
    <DxRichEdit DocumentContent="DocumentContent" CssClass="my-editor">
        <AdditionalItems>
            <ShakespeareAIContextMenuItem />
            ...
        </AdditionalItems>
    </DxRichEdit>
    

View Example: Rich Text Editor and HTML Editor for Blazor - How to integrate AI-powered extensions

See Also