Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cf77a45

Browse files
committedJun 4, 2025·
update example
1 parent b8c707f commit cf77a45

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
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: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ The AI Assistant reviews and analyzes all data displayed in the dashboard to ans
1414

1515
**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.**
1616

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.
17+
> [!Note]
18+
> We use the following versions of the `Microsoft.Extensions.AI.*` libraries in our source code:
19+
>
20+
> - Microsoft.Extensions.AI.Abstractions: **9.5.0**
21+
> - Microsoft.Extensions.AI: **9.5.0**
22+
> - Microsoft.Extensions.AI.OpenAI: **9.5.0-preview.1.25265.7**
23+
>
24+
> We do not guarantee compatibility or correct operation with higher versions.
1925
2026
## Implementation Details
2127

@@ -81,13 +87,20 @@ public interface IAIAssistantProvider {
8187
}
8288
```
8389

90+
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.
91+
92+
For information on OpenAI Assistants, refer to the following documents:
93+
- [OpenAI Assistants API overview](https://platform.openai.com/docs/assistants/overview)
94+
- [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)
95+
- [OpenAI .NET API library](https://github.com/openai/openai-dotnet)
96+
8497
You can review and tailor AI assistant instructions in the following file: [AssistantHelper.cs](./CS/Services/AssistantHelper.cs)
8598

8699
Files to Review:
87-
- [AIAssistantProvider.cs](./CS/Services/AIAssistantProvider.cs)
88100
- [IAIAssistantProvider.cs](./CS/Services/IAIAssistantProvider.cs)
89-
- [AssistantHelper.cs](./CS/Services/AssistantHelper.cs)
90-
101+
- [AIAssistantProvider.cs](./CS/Services/AIAssistantProvider.cs)
102+
- [AIAssistantProvider.cs](./CS/Services/AIAssistantProvider.cs)
103+
- [AIAssistantCreator.cs](./CS/Services/AIAssistantCreator.cs)
91104

92105
### Create an AI Assistant Custom Item
93106

@@ -197,6 +210,7 @@ async onMessageEntered(e) {
197210
- [IAIAssistantProvider.cs](./CS/Services/IAIAssistantProvider.cs)
198211
- [AIChatController.cs](./CS/Controllers/AIChatController.cs)
199212
- [AssistantHelper.cs](./CS/Services/AssistantHelper.cs)
213+
- [AIAssistantCreator.cs](./CS/Services/AIAssistantCreator.cs)
200214

201215
## Documentation
202216

0 commit comments

Comments
 (0)
Please sign in to comment.