Skip to content

Commit 7593850

Browse files
committed
update readme
1 parent 1c64bb0 commit 7593850

File tree

5 files changed

+95
-23
lines changed

5 files changed

+95
-23
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: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ var azureOpenAIClient = new AzureOpenAIClient(
7171
var chatClient = azureOpenAIClient.GetChatClient(deploymentName).AsIChatClient();
7272
builder.Services.AddChatClient(chatClient);
7373
builder.Services.AddDevExpressAI((config) => {
74-
//Reference the DevExpress.AIIntegration.OpenAI NuGet package to use Open AI Asisstants
74+
//Reference the DevExpress.AIIntegration.OpenAI NuGet package to use Open AI Assistants
7575
config.RegisterOpenAIAssistants(azureOpenAIClient, deploymentName);
7676
});
7777
```
@@ -119,18 +119,48 @@ The following code snippet adds the [`DxAIChat`](https://docs.devexpress.com/Bla
119119
}
120120
```
121121

122-
Use the [`MessageContentTemplate`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat.MessageContentTemplate) property to display rich-formatted messages. Use a markdown processor to convert response content to HTML code.
122+
Use the [`MessageContentTemplate`](https://docs.devexpress.com/Blazor/DevExpress.AIIntegration.Blazor.Chat.DxAIChat.MessageContentTemplate) property to display rich-formatted messages. Use a markdown processor to convert response content to HTML code.
123123

124124
**Files to Review:**
125125

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

128+
#### Create an AI Assistant
129+
130+
In this example, the `AIAssistantCreator.CreateAssistantAsync` method creates an assistant with the specified [options](https://learn.microsoft.com/en-us/dotnet/api/azure.ai.openai.assistants.assistantcreationoptions?view=azure-dotnet-preview) and a thread. The
131+
132+
You can review and tailor AI assistant instructions in the following file: [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs).
133+
134+
For information on OpenAI Assistants, refer to the following documents:
135+
- [OpenAI Assistants API overview](https://platform.openai.com/docs/assistants/overview)
136+
- [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)
137+
138+
In the *Program.cs* file, add the `AIAssistantCreator` service to the applications'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+
128157
#### Set Up the AI Assistant
129158

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.
159+
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's ID and thread's ID 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.
131160

132161
```razor
133162
@using DevExpress.AIIntegration.OpenAI.Services
163+
@inject AIAssistantCreator assistantCreator;
134164
135165
@* ... *@
136166
@code {
@@ -142,10 +172,13 @@ Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https
142172
await grid.ExportToXlsxAsync(ms, new GridXlExportOptions() {
143173
ExportDisplayText = true
144174
});
145-
await chat.SetupAssistantAsync(new OpenAIAssistantOptions("grid_data.xlsx", ms) {
146-
Instructions = AssistantHelper.GetAIAssistantInstructions("xlsx"),
147-
UseFileSearchTool = false
148-
});
175+
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(
176+
ms,
177+
"grid_data.xlsx",
178+
AssistantHelper.GetAIAssistantInstructions("xlsx"),
179+
false
180+
);
181+
await chat.SetupAssistantAsync(assistantId, threadId);
149182
grid.ShowGroupedColumns = false;
150183
grid.EndUpdate();
151184
}
@@ -157,12 +190,10 @@ Handle the `OnAfterRenderAsync` event and call the [`SetupAssistantAsync`](https
157190

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

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

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 creates an assistant with the specified [options](https://learn.microsoft.com/en-us/dotnet/api/azure.ai.openai.assistants.assistantcreationoptions?view=azure-dotnet-preview) and a thread. The
279+
280+
You can review and tailor AI assistant instructions in the following file: [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.cs).
281+
282+
For information on OpenAI Assistants, refer to the following documents:
283+
- [OpenAI Assistants API overview](https://platform.openai.com/docs/assistants/overview)
284+
- [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)
285+
286+
In the *Program.cs* file, add the `AIAssistantCreator` service to the applications's service collection:
287+
288+
```cs
289+
// ...
290+
var azureOpenAIClient = new AzureOpenAIClient(
291+
new Uri(azureOpenAIEndpoint),
292+
new ApiKeyCredential(azureOpenAIKey));
293+
294+
var assistantCreator = new AIAssistantCreator(azureOpenAIClient, deploymentName);
295+
296+
builder.Services.AddSingleton(assistantCreator);
297+
// ...
298+
```
299+
300+
**Files to Review:**
301+
302+
- [AIAssistantCreator.cs](./CS/DevExpress.AI.Samples.Blazor/Services/AIAssistantCreator.cs)
303+
- [Instructions.cs](./CS/DevExpress.AI.Samples.Blazor/Instructions.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 method to set up your AI assistant based on the Assistant's ID and thread's ID 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)