You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Report Viewer and Grid for Blazor — Integrate an AI Assistant based on Azure OpenAI
6
+
# Blazor Grid and Report Viewer — Incorporate an AI Assistant (Azure OpenAI) in your next DevExpress-powered Blazor app
7
7
8
-
This example adds a Copilot-inspired chat window (the[`DxAIChat`](http://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat) component) to a Blazor application with DevExpress Report Viewer and Grid components. The chat utilizes an [Azure OpenAI Assistant](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/assistant) to answer user questions based on information displayed in the report and/or data grid.
8
+
This example adds a Copilot-inspired chat window (DevExpress[`DxAIChat`](http://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat) component) to a DevExpress-powered Blazor application (using both the DevExpress Report Viewer and Blazor Grid component). Our chat implementation utilizes [Azure OpenAI Assistant](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/assistant) to answer user questions based on information displayed in the report and/or data grid.
9
9
10
-
To integrate an AI-powered chat into your application, complete the following key steps:
10
+
To integrate AI-powered chat capabilities to your next great Blazor application, please follow the steps below:
11
11
12
-
1. Register AI Services in the application.
13
-
2. Add a `DxAIChat` component.
14
-
3. Export component data and pass it to the AI Assistant.
12
+
1. Register AI Services within the application.
13
+
2. Add the DevExpress Chat component (`DxAIChat`).
14
+
3. Export component data and pass it to the AI Assistant.
15
15
16
-
This example uses the following DevExpress Blazor Components:
16
+
The following DevExpress Blazor Components were used in this sample project:
The Report Viewer includes several reports bound to different data. Use the AI Assistant to interact with report data:
30
+
Our Report Viewer includes several reports bound to different data. Use the AI Assistant to interact with report data as follows:
30
31
31
-
-*Drill-Down Report*: Analyze invoice totals, delivery statuses, and averages.
32
+
-*Drill-Down Report*: Analyze invoice totals, delivery status, and averages.
32
33
-*Market Share Report*: Compare market share changes across regions.
33
-
-*Restaurant Menu*: Examine price ranges and categorize vegetarian options.
34
+
-*Restaurant Menu*: Examine price range and categorize vegetarian options.
34
35
35
-
Implementation details: [Use an AI Assistant with the DevExpress Blazor Report Viewer](#use-an-ai-assistant-with-the-devexpress-report-viewer).
36
+
Implementation details: [Add an AI Assistant to the DevExpress Blazor Report Viewer](#add-an-ai-assistant-to-the-devexpress-report-viewer).
36
37
37
38
>[!NOTE]
38
-
> Open AI Assistant initialization may take some time. `DxAIChat` is ready for use once the Microsoft Azure OpenAI service completes the source document scan. This example uses the following source documents: Excel file exported from the data grid and PDF file exported from the report viewer.
39
+
> Open AI Assistant initialization may take time. `DxAIChat` is ready for use once Microsoft Azure OpenAI completes its source document scan.
39
40
40
41
## Implementation Details
41
42
@@ -44,7 +45,7 @@ This example uses the following DevExpress Blazor Components:
44
45
> [!NOTE]
45
46
> DevExpress AI-powered extensions follow the "bring your own key" principle. DevExpress does not offer a REST API and does not ship any built-in LLMs/SLMs. You need an active Azure/Open AI subscription to obtain the REST API endpoint, key, and model deployment name. These variables must be specified at application startup to register AI clients and enable DevExpress AI-powered Extensions in your application.
46
47
47
-
Add the following code snippet to the *Program.cs* file to register AI Services and an [OpenAI Assistant](https://platform.openai.com/docs/assistants/overview) in your application:
48
+
Add the following code snippet to the *Program.cs* file to register AI Services and incorporate an [OpenAI Assistant](https://platform.openai.com/docs/assistants/overview) in your application:
For more information on the use of AI Assistants with `DxAIChat` and managing messages with custom RAG (Retrieval-Augmented Generation) solutions, refer to the following topic: [AI Service Assistants in the DxAIChat component](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat#ai-service-assistants).
71
+
For additional information on the use of AI Assistants with `DxAIChat` and managing messages with custom RAG (Retrieval-Augmented Generation) solutions, refer to the following topic: [AI Service Assistants in the DxAIChat component](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat#ai-service-assistants).
71
72
72
-
Note that the availability of Azure Open AI Assistants depends on the region. For more details, refer to the following article: [Azure OpenAI Service models -- Assistants (Preview)](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#assistants-preview).
73
+
>[!NOTE]
74
+
> The availability of Azure Open AI Assistants depends on region. For additional guidance in this regard, refer to the following document: [Azure OpenAI Service models -- Assistants (Preview)](https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models?tabs=global-standard%2Cstandard-chat-completions#assistants-preview).
### Use an AI Assistant with the DevExpress Blazor Grid
79
81
80
-
One page in this example displays `DxGrid` and `DxAIChat` components:
82
+
This example includes a page with both the DevExpress Blazor Grid (`DxGrid`) and Blazor Chat component (`DxAIChat`):
81
83
82
84

83
85
84
-
For `DxGrid` configuration (data binding and customizations), review the following code file: [Grid.razor](./DevExpress.AI.Samples.Blazor/Components/Pages/Grid.razor).
86
+
To configure our Blazor Grid (data binding and customizations), review the following code file: [Grid.razor](./DevExpress.AI.Samples.Blazor/Components/Pages/Grid.razor).
85
87
86
88
#### Add AI Chat to the Grid Page
87
89
@@ -117,7 +119,7 @@ Use the [`MessageContentTemplate`](https://docs.devexpress.com/Blazor/DevExpress
117
119
118
120
#### Set Up the AI Assistant
119
121
120
-
Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.IAIChat.SetupAssistantAsync(DevExpress.AIIntegration.Services.Assistant.AIAssistantOptions)) method to create an AI assistant and provide it with data and instructions. This example calls the grid's [`ExportToXlsxAsync`](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxGrid.ExportToXlsxAsync.overloads) method to generate data for the AI Assistant.
122
+
Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.IAIChat.SetupAssistantAsync(DevExpress.AIIntegration.Services.Assistant.AIAssistantOptions)) method to create your AI assistant and provide it with data and instructions. This example calls our Blazor Grid's [`ExportToXlsxAsync`](https://docs.devexpress.com/Blazor/DevExpress.Blazor.DxGrid.ExportToXlsxAsync.overloads) method to generate data for the AI Assistant.
121
123
122
124
```razor
123
125
@using DevExpress.AIIntegration.OpenAI.Services
@@ -145,22 +147,22 @@ Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https
145
147
}
146
148
```
147
149
148
-
You can review and tailor assistant instructions according to your needs in the following file: [Instructions.cs](./DevExpress.AI.Samples.Blazor/Instructions.cs).
150
+
You can review and tailor AI assistant instructions in the following file: [Instructions.cs](./DevExpress.AI.Samples.Blazor/Instructions.cs).
149
151
150
-
For information on OpenAI Assistants, refer to the following article: [Assistants API overview](https://platform.openai.com/docs/assistants/overview).
152
+
For information on OpenAI Assistants, refer to the following document: [Assistants API overview](https://platform.openai.com/docs/assistants/overview).
### Use an AI Assistant with the DevExpress Blazor Report Viewer
159
+
### Add an AI Assistant to the DevExpress Blazor Report Viewer
158
160
159
-
The following image displays the Blazor Report Viewer UI implemented in this example. The AI Assistant tab uses the `DxAIChat` component to display requests and responses:
161
+
As you can see in the following image, this sample uses our Blazor Report Viewer alongside the DevExpress Chat component (the AI Assistant tab uses the `DxAIChat` component to display requests and responses):
160
162
161
163

162
164
163
-
#### Add New Tab for AI Assistant
165
+
#### Add New Tab for Your AI Assistant
164
166
165
167
Use the [`OnCustomizeTabs`](https://docs.devexpress.com/XtraReports/DevExpress.Blazor.DxViewer.OnCustomizeTabs) event to add a new tab:
166
168
@@ -192,7 +194,7 @@ Use the [`OnCustomizeTabs`](https://docs.devexpress.com/XtraReports/DevExpress.B
192
194
193
195
A new [`TabModel`](https://docs.devexpress.com/XtraReports/DevExpress.Blazor.Reporting.Models.TabModel._members) object is added to the tab list. The [`UserAssistantTabContentModel`](https://github.com/DevExpress-Examples/blazor-grid-and-report-viewer-integrate-ai-assistant/blob/24.2.3%2B/CS/DevExpress.AI.Samples.Blazor/Models/UserAssistantTabContentModel.cs#L6) class implements the [`ITabContentModel`](https://docs.devexpress.com/XtraReports/DevExpress.Blazor.Reporting.Models.ITabContentModel) interface that specifies AI Assistant tab visibility. The tab is only visible when the report is initialized and contains at least one page.
194
196
195
-
The `TabTemplate` property specifies the tab content. It dynamically renders the `DxAIChat` component inside the tab and passes the `ContentModel` as a parameter to control the tab's content.
197
+
The `TabTemplate` property specifies tab content. It dynamically renders the `DxAIChat` component inside the tab and passes `ContentModel` as a parameter to control tab content.
196
198
197
199
The content for the AI Assistant tab is defined in the following file: [AITabRenderer.razor](./DevExpress.AI.Samples.Blazor/Components/Reporting/AITabRenderer.razor).
198
200
@@ -213,7 +215,7 @@ The content for the AI Assistant tab is defined in the following file: [AITabRen
213
215
@code {
214
216
[Parameter] public UserAssistantTabContentModel Model { get; set; }
215
217
string ClearAnnotations(string text) {
216
-
//To clear out the annotations in a response from assistant.
218
+
//To clear out annotations in a response from the assistant.
217
219
return Regex.Replace(text, @"\【.*?】", "");
218
220
}
219
221
@@ -234,7 +236,7 @@ Use the [`MessageContentTemplate`](https://docs.devexpress.com/Blazor/DevExpress
234
236
235
237
#### Set Up the AI Assistant
236
238
237
-
Handle the [`Initialized`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat.Initialized) event and call the [`SetupAssistantAsync`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.IAIChat.SetupAssistantAsync(DevExpress.AIIntegration.Services.Assistant.AIAssistantOptions)) method to create an AI assistant and provide it with data and instructions. This example calls the [`ExportToPdf`](https://docs.devexpress.com/CoreLibraries/DevExpress.XtraPrinting.PrintingSystemBase.ExportToPdf(System.IO.Stream)) method to generate data for the AI Assistant:
239
+
Handle the [`Initialized`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat.Initialized) event and call the [`SetupAssistantAsync`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.IAIChat.SetupAssistantAsync(DevExpress.AIIntegration.Services.Assistant.AIAssistantOptions)) method to create your AI assistant and provide it with data and instructions. This example calls the [`ExportToPdf`](https://docs.devexpress.com/CoreLibraries/DevExpress.XtraPrinting.PrintingSystemBase.ExportToPdf(System.IO.Stream)) method to generate data for the AI Assistant:
238
240
239
241
```razor
240
242
@using DevExpress.AIIntegration.Blazor.Chat
@@ -256,7 +258,7 @@ Handle the [`Initialized`](https://docs.devexpress.com/Blazor/DevExpress.AIInteg
256
258
}
257
259
```
258
260
259
-
You can review and tailor instructions to your needs in the following file: [Instructions.cs](./DevExpress.AI.Samples.Blazor/Instructions.cs).
261
+
You can review and tailor AI assistant instructions in the following file: [Instructions.cs](./DevExpress.AI.Samples.Blazor/Instructions.cs).
260
262
261
263
For information on OpenAI Assistants, refer to the following article: [Assistants API overview](https://platform.openai.com/docs/assistants/overview).
0 commit comments