Skip to content

Commit 2e2c4ee

Browse files
pollyndosDevExpressExampleBotalbertov05
authored
update example
* update example * README auto update [skip ci] * Update README.md Co-authored-by: Albert Totten <[email protected]> --------- Co-authored-by: DevExpressExampleBot <[email protected]> Co-authored-by: Albert Totten <[email protected]>
1 parent b8c707f commit 2e2c4ee

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

CS/DashboardAIAssistant.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
<PackageReference Include="DevExpress.AIIntegration.OpenAI" Version="25.1.*-*" />
2323
<PackageReference Include="Azure.AI.OpenAI" Version="2.2.0-beta.4" />
2424
<PackageReference Include="Azure.AI.OpenAI.Assistants" Version="1.0.0-beta.4" />
25-
<PackageReference Include="Microsoft.Extensions.AI" Version="9.4.3-preview.1.25230.7" />
26-
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.3-preview.1.25230.7" />
25+
<PackageReference Include="Microsoft.Extensions.AI" Version="9.5.0" />
26+
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.5.0-preview.1.25265.7" />
2727
</ItemGroup>
2828

2929
<ItemGroup>

CS/Services/AIAssistantCreator.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,24 @@ public AIAssistantCreator(OpenAIClient client, string deployment) {
2020
this.deployment = deployment;
2121
}
2222

23-
public async Task<(string assistantId, string threadId)> CreateAssistantAsync(Stream data, string fileName, string instructions, bool useFileSearchTool = true, CancellationToken ct = default) {
23+
public async Task<(string assistantId, string threadId)> CreateAssistantAndThreadAsync(Stream data, string fileName, string instructions, CancellationToken ct = default) {
2424
data.Position = 0;
2525

2626
ClientResult<OpenAIFile> fileResponse = await fileClient.UploadFileAsync(data, fileName, FileUploadPurpose.Assistants, ct);
2727
OpenAIFile file = fileResponse.Value;
2828

2929
var resources = new ToolResources() {
30-
CodeInterpreter = new CodeInterpreterToolResources(),
31-
FileSearch = useFileSearchTool ? new FileSearchToolResources() : null
30+
CodeInterpreter = new CodeInterpreterToolResources()
3231
};
33-
resources.FileSearch?.NewVectorStores.Add(new VectorStoreCreationHelper([file.Id]));
3432
resources.CodeInterpreter.FileIds.Add(file.Id);
3533

3634
AssistantCreationOptions assistantCreationOptions = new AssistantCreationOptions() {
3735
Name = Guid.NewGuid().ToString(),
3836
Instructions = instructions,
39-
ToolResources = resources
37+
ToolResources = resources,
38+
Tools = { new CodeInterpreterToolDefinition() }
4039
};
41-
assistantCreationOptions.Tools.Add(new CodeInterpreterToolDefinition());
42-
if (useFileSearchTool) {
43-
assistantCreationOptions.Tools.Add(new FileSearchToolDefinition());
44-
}
40+
4541

4642
ClientResult<Assistant> assistantResponse = await assistantClient.CreateAssistantAsync(deployment, assistantCreationOptions, ct);
4743
ClientResult<AssistantThread> threadResponse = await assistantClient.CreateThreadAsync(cancellationToken: ct);

CS/Services/AIAssistantProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task<string> CreateAssistant(Stream fileContent, string prompt) {
2121
Guard.ArgumentIsNotNullOrEmpty(prompt, nameof(prompt));
2222

2323
string assistantName = Guid.NewGuid().ToString();
24-
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAsync(fileContent, $"{assistantName}.xlsx", prompt, false);
24+
(string assistantId, string threadId) = await assistantCreator.CreateAssistantAndThreadAsync(fileContent, $"{assistantName}.xlsx", prompt);
2525

2626
IAIAssistant assistant = await assistantFactory.GetAssistant(assistantId, threadId);
2727
await assistant.InitializeAsync();

CS/Services/IAIAssistantProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace DashboardAIAssistant.Services {
66
public interface IAIAssistantProvider {
77
Task<string> CreateAssistant(Stream fileContent, string prompt);
8-
IAIAssistant GetAssistant(string assistantId);
9-
void DisposeAssistant(string assistantId);
8+
IAIAssistant GetAssistant(string assistantName);
9+
void DisposeAssistant(string assistantName);
1010
}
1111
}

CS/wwwroot/js/aiChatCustomItem.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,16 @@ let AIChatCustomItem = (function() {
143143
};
144144

145145
normalizeAIResponse(text) {
146-
text = text.replace(/\d+:\d+[^\】]+/g, "");
147-
let html = marked.parse(text);
148-
if (/<p>\.\s*<\/p>\s*$/.test(html))
149-
html = html.replace(/<p>\.\s*<\/p>\s*$/, "")
150-
return html;
146+
if (text) {
147+
text = text.replace(/\d+:\d+[^\】]+/g, "");
148+
let html = marked.parse(text);
149+
if (/<p>\.\s*<\/p>\s*$/.test(html))
150+
html = html.replace(/<p>\.\s*<\/p>\s*$/, "")
151+
return html;
152+
}
153+
else {
154+
return "Please try again later."
155+
}
151156
}
152157

153158
renderAssistantMessage(instance, message) {

README.md

Lines changed: 20 additions & 7 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/938296554/25.1.2%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/T1279614)
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)
@@ -14,8 +13,14 @@ The AI Assistant reviews and analyzes all data displayed in the dashboard to ans
1413

1514
**Please note that AI Assistant initialization takes time. The assistant is ready for interaction once Microsoft Azure scans the source document on the server side.**
1615

17-
> [!Important]
18-
> We use version **9.4.3-preview.1.25230.7** of the _Microsoft.Extensions.AI.*_ libraries in our source code. We do not guarantee compatibility or correct operation with higher versions.
16+
> [!Note]
17+
> We use the following versions of the `Microsoft.Extensions.AI.*` libraries in our source code:
18+
>
19+
> - Microsoft.Extensions.AI.Abstractions: **9.5.0**
20+
> - Microsoft.Extensions.AI: **9.5.0**
21+
> - Microsoft.Extensions.AI.OpenAI: **9.5.0-preview.1.25265.7**
22+
>
23+
> We do not guarantee compatibility or correct operation with higher versions.
1924
2025
## Implementation Details
2126

@@ -81,13 +86,20 @@ public interface IAIAssistantProvider {
8186
}
8287
```
8388

84-
You can review and tailor AI assistant instructions in the following file: [AssistantHelper.cs](./CS/Services/AssistantHelper.cs)
89+
The `AIAssistantCreator.CreateAssistantAndThreadAsync` 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. The generated assistant and thread IDs are then passed to the `IAIAssistantFactory.GetAssistant` method, which returns an `IAIAssistant` instance. The created instance is added to the application's assistant collection and is referenced by its unique name.
90+
91+
For information on OpenAI Assistants, refer to the following documents:
92+
- [OpenAI Assistants API overview](https://platform.openai.com/docs/assistants/overview)
93+
- [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)
94+
- [OpenAI .NET API library](https://github.com/openai/openai-dotnet)
95+
96+
You can review and tailor AI assistant instructions in the following file: [AssistantHelper.cs](./CS/Services/AssistantHelper.cs).
8597

8698
Files to Review:
87-
- [AIAssistantProvider.cs](./CS/Services/AIAssistantProvider.cs)
8899
- [IAIAssistantProvider.cs](./CS/Services/IAIAssistantProvider.cs)
89-
- [AssistantHelper.cs](./CS/Services/AssistantHelper.cs)
90-
100+
- [AIAssistantProvider.cs](./CS/Services/AIAssistantProvider.cs)
101+
- [AIAssistantProvider.cs](./CS/Services/AIAssistantProvider.cs)
102+
- [AIAssistantCreator.cs](./CS/Services/AIAssistantCreator.cs)
91103

92104
### Create an AI Assistant Custom Item
93105

@@ -197,6 +209,7 @@ async onMessageEntered(e) {
197209
- [IAIAssistantProvider.cs](./CS/Services/IAIAssistantProvider.cs)
198210
- [AIChatController.cs](./CS/Controllers/AIChatController.cs)
199211
- [AssistantHelper.cs](./CS/Services/AssistantHelper.cs)
212+
- [AIAssistantCreator.cs](./CS/Services/AIAssistantCreator.cs)
200213

201214
## Documentation
202215

0 commit comments

Comments
 (0)