Skip to content

Commit 1d7f7f2

Browse files
authored
update example
Update example readme
2 parents 41682b8 + b88c0d9 commit 1d7f7f2

File tree

5 files changed

+97
-25
lines changed

5 files changed

+97
-25
lines changed

CS/DevExpress.AI.Samples.Blazor/Components/Pages/Grid.razor

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@using Markdig
77

88
@inject IssuesDataService IssuesDataService
9-
@inject AIAssistantCreator assistantCreator;
9+
@inject AIAssistantCreator assistantCreator
1010

1111
<DxGrid @ref="grid" Data="@DataSource" CssClass="my-grid" ShowGroupPanel="true" TextWrapEnabled="false" AutoExpandAllGroupRows="true"
1212
CustomizeFilterRowEditor="Grid_CustomizeFilterRowEditor" FilterMenuButtonDisplayMode="GridFilterMenuButtonDisplayMode.Always"
@@ -23,7 +23,7 @@
2323
</DxGridDataColumn>
2424
<DxGridDataColumn FieldName="ProjectID" Caption="Project" GroupIndex="0" Width="220px">
2525
<EditSettings>
26-
<DxComboBoxSettings Data="ProjectList" ValueFieldName="ID" TextFieldName="Name"
26+
<DxComboBoxSettings Data="ProjectList" ValueFieldName="ID" TextFieldName="Name"
2727
SearchFilterCondition="ListSearchFilterCondition.Contains" />
2828
</EditSettings>
2929
</DxGridDataColumn>
@@ -155,7 +155,12 @@
155155
ExportDisplayText = true
156156
});
157157

158-
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(ms, "grid_data.xlsx", AssistantHelper.GetAIAssistantInstructions("xlsx"), false);
158+
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(
159+
ms,
160+
"grid_data.xlsx",
161+
AssistantHelper.GetAIAssistantInstructions("xlsx"),
162+
false
163+
);
159164
await chat.SetupAssistantAsync(assistantId, threadId);
160165

161166
grid.ShowGroupedColumns = false;

CS/DevExpress.AI.Samples.Blazor/Components/Reporting/AITabRenderer.razor

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@using DevExpress.AIIntegration.OpenAI.Services
66
@using Markdig
77

8-
@inject AIAssistantCreator assistantCreator;
8+
@inject AIAssistantCreator assistantCreator
99

1010
<DxAIChat CssClass="my-report-chat" Initialized="ChatInitialized">
1111
<MessageContentTemplate>
@@ -29,7 +29,11 @@
2929

3030
async Task ChatInitialized(IAIChat aIChat) {
3131
using (MemoryStream ms = Model.GetReportData()) {
32-
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(ms, "report.pdf", AssistantHelper.GetAIAssistantInstructions("pdf"));
32+
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(
33+
ms,
34+
"report.pdf",
35+
AssistantHelper.GetAIAssistantInstructions("pdf")
36+
);
3337
await aIChat.SetupAssistantAsync(assistantId, threadId);
3438
}
3539
}

CS/DevExpress.AI.Samples.Blazor/DevExpress.AI.Samples.Blazor.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<PackageReference Include="DevExpress.Reporting.Demos" Version="25.1.*-*" />
1717
<PackageReference Include="Markdig" Version="0.38.0" />
1818
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.7" />
19-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.4.3-preview.1.25230.7" />
20-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.3-preview.1.25230.7" />
19+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.5.0" />
20+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.5.0-preview.1.25265.7" />
2121
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
2222
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
2323
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />

CS/DevExpress.AI.Samples.Blazor/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
builder.Services.AddDevExpressServerSideBlazorReportViewer();
3030
builder.Services.AddChatClient(chatClient);
3131
builder.Services.AddDevExpressAI((config) => {
32-
//Reference the DevExpress.AIIntegration.OpenAI NuGet package to use Open AI Asisstants
32+
//Reference the DevExpress.AIIntegration.OpenAI NuGet package to use Open AI Assistants
3333
config.RegisterOpenAIAssistants(azureOpenAIClient, deploymentName);
3434
});
3535
builder.Services.AddSingleton(assistantCreator);

README.md

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<!-- default badges list -->
2-
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/904202803/25.1.3%2B)
32
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T1268742)
43
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
54
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
@@ -41,7 +40,9 @@ Open AI Assistant initialization may take time. `DxAIChat` is ready for use once
4140
> [!Note]
4241
> We use the following versions of the `Microsoft.Extensions.AI.*` libraries in our source code:
4342
>
44-
> v25.1.2+ | **9.4.3-preview.1.25230.7**
43+
> - Microsoft.Extensions.AI.Abstractions: **9.5.0**
44+
> - Microsoft.Extensions.AI: **9.5.0**
45+
> - Microsoft.Extensions.AI.OpenAI: **9.5.0-preview.1.25265.7**
4546
>
4647
> We do not guarantee compatibility or correct operation with higher versions.
4748
@@ -71,7 +72,7 @@ var azureOpenAIClient = new AzureOpenAIClient(
7172
var chatClient = azureOpenAIClient.GetChatClient(deploymentName).AsIChatClient();
7273
builder.Services.AddChatClient(chatClient);
7374
builder.Services.AddDevExpressAI((config) => {
74-
//Reference the DevExpress.AIIntegration.OpenAI NuGet package to use Open AI Asisstants
75+
//Reference the DevExpress.AIIntegration.OpenAI NuGet package to use Open AI Assistants
7576
config.RegisterOpenAIAssistants(azureOpenAIClient, deploymentName);
7677
});
7778
```
@@ -125,12 +126,42 @@ Use the [`MessageContentTemplate`](https://docs.devexpress.com/Blazor/DevExpress
125126

126127
- [Grid.razor](./CS/DevExpress.AI.Samples.Blazor/Components/Pages/Grid.razor)
127128

129+
#### Create an AI Assistant
130+
131+
In this example, the `AIAssistantCreator.CreateAssistantAsync` method uploads a file to OpenAI, configures tool resources, creates an assistant with specified instructions and tools, initializes a new thread, and returns the assistant and thread IDs.
132+
133+
For information on OpenAI Assistants, refer to the following documents:
134+
- [OpenAI Assistants API overview](https://platform.openai.com/docs/assistants/overview)
135+
- [Azure OpenAI: OpenAI Assistants client library for .NET](https://learn.microsoft.com/en-us/dotnet/api/overview/azure/ai.openai.assistants-readme?view=azure-dotnet-preview)
136+
- [OpenAI .NET API library](https://github.com/openai/openai-dotnet)
137+
138+
In the *Program.cs* file, add the `AIAssistantCreator` service to the application's service collection:
139+
140+
```cs
141+
// ...
142+
var azureOpenAIClient = new AzureOpenAIClient(
143+
new Uri(azureOpenAIEndpoint),
144+
new ApiKeyCredential(azureOpenAIKey));
145+
146+
var assistantCreator = new AIAssistantCreator(azureOpenAIClient, deploymentName);
147+
148+
builder.Services.AddSingleton(assistantCreator);
149+
// ...
150+
```
151+
152+
**Files to Review:**
153+
154+
- [AIAssistantCreator.cs](./CS/DevExpress.AI.Samples.Blazor/Services/AIAssistantCreator.cs)
155+
- [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs)
156+
- [Program.cs](./CS/DevExpress.AI.Samples.Blazor/Program.cs)
157+
128158
#### Set Up the AI Assistant
129159

130-
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.
160+
Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.IAIChat.SetupAssistantAsync(System.String-System.String)?v=25.1) method to set up your AI assistant based on the assistant and thread IDs created in the previous step. 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.
131161

132162
```razor
133163
@using DevExpress.AIIntegration.OpenAI.Services
164+
@inject AIAssistantCreator assistantCreator
134165
135166
@* ... *@
136167
@code {
@@ -142,10 +173,13 @@ Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https
142173
await grid.ExportToXlsxAsync(ms, new GridXlExportOptions() {
143174
ExportDisplayText = true
144175
});
145-
await chat.SetupAssistantAsync(new OpenAIAssistantOptions("grid_data.xlsx", ms) {
146-
Instructions = AssistantHelper.GetAIAssistantInstructions("xlsx"),
147-
UseFileSearchTool = false
148-
});
176+
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(
177+
ms,
178+
"grid_data.xlsx",
179+
AssistantHelper.GetAIAssistantInstructions("xlsx"),
180+
false
181+
);
182+
await chat.SetupAssistantAsync(assistantId, threadId);
149183
grid.ShowGroupedColumns = false;
150184
grid.EndUpdate();
151185
}
@@ -157,12 +191,9 @@ Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https
157191

158192
You can review and tailor AI assistant instructions in the following file: [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs).
159193

160-
For information on OpenAI Assistants, refer to the following document: [Assistants API overview](https://platform.openai.com/docs/assistants/overview).
161-
162194
**Files to Review:**
163195

164196
- [Grid.razor](./CS/DevExpress.AI.Samples.Blazor/Components/Pages/Grid.razor)
165-
- [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs)
166197

167198
### Add an AI Assistant to the DevExpress Blazor Report Viewer
168199

@@ -242,13 +273,44 @@ Use the [`MessageContentTemplate`](https://docs.devexpress.com/Blazor/DevExpress
242273
- [AITabRenderer.razor](./CS/DevExpress.AI.Samples.Blazor/Components/Reporting/AITabRenderer.razor)
243274
- [UserAssistantTabContentModel.cs](./CS/DevExpress.AI.Samples.Blazor/Models/UserAssistantTabContentModel.cs)
244275

276+
#### Create an AI Assistant
277+
278+
In this example, the `AIAssistantCreator.CreateAssistantAsync` method uploads a file to OpenAI, configures tool resources, creates an assistant with specified instructions and tools, initializes a new thread, and returns the assistant and thread IDs.
279+
280+
For information on OpenAI Assistants, refer to the following documents:
281+
- [OpenAI Assistants API overview](https://platform.openai.com/docs/assistants/overview)
282+
- [Azure OpenAI: OpenAI Assistants client library for .NET](https://learn.microsoft.com/en-us/dotnet/api/overview/azure/ai.openai.assistants-readme?view=azure-dotnet-preview)
283+
- [OpenAI .NET API library](https://github.com/openai/openai-dotnet)
284+
285+
In the *Program.cs* file, add the `AIAssistantCreator` service to the application's service collection:
286+
287+
```cs
288+
// ...
289+
var azureOpenAIClient = new AzureOpenAIClient(
290+
new Uri(azureOpenAIEndpoint),
291+
new ApiKeyCredential(azureOpenAIKey));
292+
293+
var assistantCreator = new AIAssistantCreator(azureOpenAIClient, deploymentName);
294+
295+
builder.Services.AddSingleton(assistantCreator);
296+
// ...
297+
```
298+
299+
**Files to Review:**
300+
301+
- [AIAssistantCreator.cs](./CS/DevExpress.AI.Samples.Blazor/Services/AIAssistantCreator.cs)
302+
- [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs)
303+
- [Program.cs](./CS/DevExpress.AI.Samples.Blazor/Program.cs)
304+
245305
#### Set Up the AI Assistant
246306

247-
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:
307+
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(System.String-System.String)?v=25.1) method to set up your AI assistant based on the assistant and thread IDs created in the previous step. 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:
248308

249309
```razor
250310
@using DevExpress.AIIntegration.Blazor.Chat
251311
@using DevExpress.AIIntegration.OpenAI.Services
312+
// ...
313+
@inject AIAssistantCreator assistantCreator
252314
253315
<DxAIChat CssClass="my-report-chat" Initialized="ChatInitialized">
254316
@* ... *@
@@ -258,24 +320,25 @@ Handle the [`Initialized`](https://docs.devexpress.com/Blazor/DevExpress.AIInteg
258320
// ...
259321
async Task ChatInitialized(IAIChat aIChat) {
260322
using (MemoryStream ms = Model.GetReportData()) {
261-
await aIChat.SetupAssistantAsync(new OpenAIAssistantOptions("report.pdf", ms) {
262-
Instructions = AssistantHelper.GetAIAssistantInstructions("pdf")
263-
});
323+
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(
324+
ms,
325+
"report.pdf",
326+
AssistantHelper.GetAIAssistantInstructions("pdf")
327+
);
328+
await aIChat.SetupAssistantAsync(assistantId, threadId);
264329
}
265330
}
266331
}
267332
```
268333

269334
You can review and tailor AI assistant instructions in the following file: [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs).
270335

271-
For information on OpenAI Assistants, refer to the following article: [Assistants API overview](https://platform.openai.com/docs/assistants/overview).
272336

273337
**Files to Review:**
274338

275339
- [ReportViewer.razor](./CS/DevExpress.AI.Samples.Blazor/Components/Pages/ReportViewer.razor)
276340
- [AITabRenderer.razor](./CS/DevExpress.AI.Samples.Blazor/Components/Reporting/AITabRenderer.razor)
277341
- [UserAssistantTabContentModel.cs](./CS/DevExpress.AI.Samples.Blazor/Models/UserAssistantTabContentModel.cs)
278-
- [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs)
279342

280343
## Files to Review
281344

0 commit comments

Comments
 (0)