Example T1253240
Visible to All Users

Reporting for Blazor - Summarize and Translate DevExpress Reports

This example adds AI-powered summarize/translate capabilities to the DevExpress Blazor Report Viewer. These capabilities are available within the user interface via two buttons designed to access the report document and process content as follows:

  • Summarize: Uses generative AI to summarize report content and displays core insights associated with this report.
  • Translate: Uses AI services to translate report content to another language.

These actions are also available in context menu when you select report content. Note the AI Operations icon that floats next to the report page. Users can click it to invoke the context menu.

The following is an image of the application interface. As you can see, users can process the entire document, individual pages, or selected content.

AI-Powered Summarize and Translate Buttons

Implementation Details

Add NuGet Packages

Add the following NuGet packages:

  • DevExpress.AIIntegration.Blazor.Reporting.Viewer
  • DevExpress.Drawing.Skia (if you use a non-Windows environment)
  • Microsoft.Extensions.AI.OpenAI, Azure.AI.OpenAI, Azure.Identity or Microsoft.Extensions.AI.Ollama based on your AI service preferences. This project uses Azure OpenAI. The remainder of this document describes steps related to this package.

For the list of supported AI services and the corresponding prerequisites, refer to Supported AI Services in the following help topic: AI-powered Extensions for DevExpress Reporting.

Add Personal Keys

[!NOTE]
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.

To use AI-based Summarize and Translate functionality in your application, you must create an Azure OpenAI resource in the Azure portal. Refer to the following help topic for additional information/guidance: Microsoft - Create and deploy an Azure OpenAI Service resource.

Once you obtain a private endpoint and an API key, open appsettings.json and specify DeploymentName, AzureOpenAIKey, and AzureOpenAIEndpoint values. Note that DeploymentName is set to GPT4o, but you can specify a different model:

JSON
"AISettings": { "DeploymentName": "GPT4o", "AzureOpenAIKey": "", "AzureOpenAIEndpoint": "" }

Create a class to read these settings:

C#
public class AISettings { public string AzureOpenAIKey { get; set; } public string DeploymentName { get; set; } public string AzureOpenAIEndpoint { get; set; } }

Register AI Services

Call the AddDevExpressAI method at the application startup to register AI services in your application:

C#
using DevExpress.AIIntegration; using DevExpress.AIIntegration.Reporting; using DevExpress.AIIntegration.Blazor.Reporting.Viewer.Models; using Azure.AI.OpenAI; using Azure; // ... var builder = WebApplication.CreateBuilder(args); var settings = builder.Configuration.GetSection("AISettings").Get<AISettings>(); IChatClient chatClient = new AzureOpenAIClient( new Uri(settings.AzureOpenAIEndpoint), new AzureKeyCredential(settings.AzureOpenAIKey)) .AsChatClient(settings.DeploymentName); builder.Services.AddChatClient(config => config.Use(chatClient)); builder.Services.AddDevExpressAI((config) => { config.AddBlazorReportingAIIntegration(config => { config.SummarizationMode = SummarizationMode.Abstractive; config.Languages = new List<LanguageItem>() { new LanguageItem() { Key = "de", Text = "German" }, new LanguageItem() { Key = "es", Text = "Spanish" }, new LanguageItem() { Key = "en", Text = "English" } }; }); }); var app = builder.Build(); // ...

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

BlazorReportViewer/appsettings.json
JSON
{ "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "ConnectionStrings": { "NWindConnectionString": "XpoProvider=SQLite;Data Source=|DataDirectory|Data/nwind.db", "ReportsDataConnectionString": "Filename=Data/reportsData.db" }, "AISettings": { "DeploymentName": "GPT4o", "AzureOpenAIKey": "", "AzureOpenAIEndpoint": "" } }
BlazorReportViewer/Program.cs
C#
using Azure; using Azure.AI.OpenAI; using BlazorReportViewer.Settings; using DevExpress.AIIntegration; using DevExpress.AIIntegration.Blazor.Reporting.Viewer.Models; using DevExpress.Blazor.Reporting; using Microsoft.Extensions.AI; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddDevExpressBlazor(); builder.Services.AddDevExpressServerSideBlazorReportViewer(); builder.Services.Configure<DevExpress.Blazor.Configuration.GlobalOptions>(options => { options.BootstrapVersion = DevExpress.Blazor.BootstrapVersion.v5; }); var settings = builder.Configuration.GetSection("AISettings").Get<AISettings>(); IChatClient chatClient = new AzureOpenAIClient( new Uri(settings.AzureOpenAIEndpoint), new AzureKeyCredential(settings.AzureOpenAIKey)).AsChatClient(settings.DeploymentName); builder.Services.AddChatClient(config => config.Use(chatClient)); builder.Services.AddDevExpressAI((config) => { config.AddBlazorReportingAIIntegration(config => { config.SummarizationMode = SummarizationMode.Abstractive; config.Languages = new List<LanguageItem>() { new LanguageItem() { Key = "de", Text = "German" }, new LanguageItem() { Key = "es", Text = "Spanish" }, new LanguageItem() { Key = "en", Text = "English" } }; }); }); builder.WebHost.UseStaticWebAssets(); var app = builder.Build(); // Configure the HTTP request pipeline. if(app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.MapControllers(); app.MapBlazorHub(); app.MapFallbackToPage("/_Host"); string contentPath = app.Environment.ContentRootPath; AppDomain.CurrentDomain.SetData("DataDirectory", contentPath); AppDomain.CurrentDomain.SetData("DXResourceDirectory", contentPath); app.Run();
BlazorReportViewer/Settings/AISettings.cs
C#
namespace BlazorReportViewer.Settings { public class AISettings { public string AzureOpenAIKey { get; set; } public string DeploymentName { get; set; } public string AzureOpenAIEndpoint { get; set; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.