|
1 | 1 | <!-- default badges list --> |
2 | | - |
3 | 2 | [](https://supportcenter.devexpress.com/ticket/details/T1251646) |
4 | 3 | [](https://docs.devexpress.com/GeneralInformation/403183) |
5 | 4 | [](#does-this-example-address-your-development-requirementsobjectives) |
6 | 5 | <!-- default badges end --> |
7 | | -# Product/Platform - Task |
| 6 | +# Rich Text Editor and HTML Editor for Blazor - How to integrate AI-powered extensions |
8 | 7 |
|
9 | | -This is the repository template for creating new examples. Describe the solved task here. |
| 8 | +This example enables AI-powered extensions for both the DevExpress Blazor Rich Text Editor and HTML Editor. These extensions supply AI functions designed to process text/HTML content. |
10 | 9 |
|
11 | | -Put a screenshot that illustrates the result here. |
| 10 | +## Implementation Details |
12 | 11 |
|
13 | | -Then, add implementation details (steps, code snippets, and other technical information in a free form), or add a link to an existing document with implementation details. |
| 12 | +Both the DevExpress Blazor Rich Text Editor ([DxRichEdit](https://docs.devexpress.com/Blazor/DevExpress.Blazor.RichEdit.DxRichEdit)) and Blazor HTML Editor ([DxHtmlEditor](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxHtmlEditor)) ship with an `AdditionalSettings` property. You can populate this property with commands and allow users to process editor text as needs dictate. Available commands for both editors are as follows: |
| 13 | + |
| 14 | +* `CustomAISettings` allows user to process text according to a custom prompt. |
| 15 | +* `ExpandAISettings` expands the text. |
| 16 | +* `ExplainAISettings` explains the text. |
| 17 | +* `ProofreadAISettings` proofreads the text. |
| 18 | +* `RewriteAISettings` rewrite text using a specified style. |
| 19 | +* `ShortenAISettings` shortens the text. |
| 20 | +* `SummaryAISettings` summarizes the text. |
| 21 | +* `ToneAISettings` rewrite text using a specified tone. |
| 22 | +* `TranslateAISettings` translates the text into the specified language. |
| 23 | + |
| 24 | +### Register AI Services |
| 25 | + |
| 26 | +Add the following code to the _Program.cs_ file to register AI services in the application: |
| 27 | + |
| 28 | +```cs |
| 29 | +using DevExpress.AIIntegration; |
| 30 | + |
| 31 | +string azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); |
| 32 | +string azureOpenAIKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY"); |
| 33 | +... |
| 34 | +builder.Services.AddDevExpressAI((config) => { |
| 35 | + var client = new AzureOpenAIClient( |
| 36 | + new Uri(azureOpenAIEndpoint), |
| 37 | + new AzureKeyCredential(azureOpenAIKey)); |
| 38 | + config.RegisterChatClientOpenAIService(client, "gpt4o"); |
| 39 | + config.RegisterOpenAIAssistants(client, "gpt4o"); |
| 40 | +}); |
| 41 | +``` |
| 42 | + |
| 43 | +### Enable AI-powered extension for the DevExpress Rich Text Editor |
| 44 | + |
| 45 | +AI-powered extension for Rich Text Editor adds AI-related commands to the editor's context menu. |
| 46 | + |
| 47 | +Declare DxRichEdit's `AdditionalSettings` and populate it with commands in the following manner: |
| 48 | + |
| 49 | +```razor |
| 50 | +@using DevExpress.AIIntegration.Blazor.RichEdit |
| 51 | +@using DevExpress.Blazor.RichEdit |
| 52 | +
|
| 53 | +<DxRichEdit DocumentContent="DocumentContent" CssClass="my-editor"> |
| 54 | + <AdditionalSettings> |
| 55 | + <SummaryAISettings /> |
| 56 | + <ExplainAISettings /> |
| 57 | + <ProofreadAISettings /> |
| 58 | + <ExpandAISettings /> |
| 59 | + <ShortenAISettings /> |
| 60 | + <CustomAISettings /> |
| 61 | + <RewriteAISettings /> |
| 62 | + <ToneAISettings /> |
| 63 | + <TranslateAISettings Languages="@("German, French, Chinese")" /> |
| 64 | + </AdditionalSettings> |
| 65 | +</DxRichEdit> |
| 66 | +``` |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +### Enable AI-powered extension for the DevExpress HTML Editor |
| 71 | + |
| 72 | +The AI-powered extension for our HTML Editor adds AI-related commands to the editor's toolbar. |
| 73 | + |
| 74 | +Declare DxHtmlEditor's `AdditionalSettings` and populate it with commands in the following manner: |
| 75 | + |
| 76 | +```razor |
| 77 | +@using DevExpress.AIIntegration.Blazor.HtmlEditor |
| 78 | +
|
| 79 | +<DxHtmlEditor @bind-Markup="Value" CssClass="my-editor" BindMarkupMode="HtmlEditorBindMarkupMode.OnLostFocus"> |
| 80 | + <AdditionalSettings> |
| 81 | + <SummaryAISettings /> |
| 82 | + <ExplainAISettings /> |
| 83 | + <ProofreadAISettings /> |
| 84 | + <ExpandAISettings /> |
| 85 | + <ShortenAISettings /> |
| 86 | + <CustomAISettings /> |
| 87 | + <RewriteAISettings /> |
| 88 | + <ToneAISettings /> |
| 89 | + <TranslateAISettings Languages="@("German, French, Chinese")" /> |
| 90 | + </AdditionalSettings> |
| 91 | +</DxHtmlEditor> |
| 92 | +``` |
| 93 | + |
| 94 | + |
14 | 95 |
|
15 | 96 | ## Files to Review |
16 | 97 |
|
17 | | -- link.cs (VB: link.vb) |
18 | | -- link.js |
19 | | -- ... |
| 98 | +* [RichEdit.razor](./CS/DevExpress.AI.Samples.Blazor.Editors/Components/Pages/RichEdit.razor) |
| 99 | +* [HtmlEditor.razor](./CS/DevExpress.AI.Samples.Blazor.Editors/Components/Pages/HtmlEditor.razor) |
| 100 | +* [Program.cs](./CS/DevExpress.AI.Samples.Blazor.Editors/Program.cs) |
20 | 101 |
|
| 102 | +<!-- add later |
21 | 103 | ## Documentation |
22 | 104 |
|
23 | 105 | - link |
24 | 106 | - link |
25 | | -- ... |
| 107 | +--> |
26 | 108 |
|
27 | 109 | ## More Examples |
28 | 110 |
|
29 | | -- link |
30 | | -- link |
31 | | -- ... |
| 111 | +* [AI Chat for Blazor - How to add DxAIChat component in Blazor, MAUI, WPF, and WinForms applications](https://github.com/DevExpress-Examples/devexpress-ai-chat-samples) |
| 112 | + |
32 | 113 | <!-- feedback --> |
33 | 114 | ## Does this example address your development requirements/objectives? |
34 | 115 |
|
|
0 commit comments