Skip to content

Commit 6d276cb

Browse files
committed
Update OpenAI/QuestPDF packages and Chatbot logic
Updated Microsoft.Agents.AI.OpenAI and QuestPDF package versions. Refactored Chatbot.razor to use UserProfileStateService for user profile access. Changed agent session creation to CreateSessionAsync. Simplified ChatHistoryProvider instantiation and removed factory/reducer logic. Minor code cleanup and formatting improvements.
1 parent 05ab781 commit 6d276cb

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

src/Infrastructure/Infrastructure.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<LangVersion>default</LangVersion>
99
</PropertyGroup>
1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.260128.1" />
11+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-rc2" />
1212
<PackageReference Include="OpenAI" Version="2.8.0" />
1313
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="10.0.3" />
1414
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="10.0.3" />
1515
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="10.0.3" />
16-
<PackageReference Include="QuestPDF" Version="2026.2.1" />
16+
<PackageReference Include="QuestPDF" Version="2026.2.2" />
1717
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
1818
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="9.0.3" />
1919
<PackageReference Include="Serilog.Sinks.Postgresql.Alternative" Version="4.2.0" />

src/Server.UI/Pages/AI/Chatbot.razor

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@using System.ComponentModel
1010

1111
@inject IConfiguration Configuration
12-
12+
@inject UserProfileStateService UserProfileStateService
1313

1414
<PageTitle>Chatbot</PageTitle>
1515

@@ -245,22 +245,22 @@
245245
</style>
246246

247247
@code {
248-
// Define local data model
249-
private class ChatMessage
250-
{
251-
public string Role { get; set; } = "user";
252-
public string Content { get; set; } = string.Empty;
253-
}
254-
255-
private List<ChatMessage> messages = new();
256-
private string userInput = string.Empty;
257-
private bool isLoading = false;
258-
private bool preventDefaultEnter = false;
259-
private ElementReference messagesEndRef;
260-
private AIAgent? _agent;
261-
private AgentSession? _agentSession;
262-
[CascadingParameter]
263-
private UserProfile UserProfile { get; set; }
248+
// Define local data model
249+
private class ChatMessage
250+
{
251+
public string Role { get; set; } = "user";
252+
public string Content { get; set; } = string.Empty;
253+
}
254+
255+
private List<ChatMessage> messages = new();
256+
private string userInput = string.Empty;
257+
private bool isLoading = false;
258+
private bool preventDefaultEnter = false;
259+
private ElementReference messagesEndRef;
260+
private AIAgent? _agent;
261+
private AgentSession? _agentSession;
262+
263+
private UserProfile UserProfile => UserProfileStateService.UserProfile;
264264

265265
protected override async Task OnAfterRenderAsync(bool firstRender)
266266
{
@@ -306,14 +306,7 @@
306306
Instructions = instructions,
307307
Tools = [AIFunctionFactory.Create(GetCurrentDate)]
308308
},
309-
ChatHistoryProviderFactory = (ctx, ct) => new ValueTask<ChatHistoryProvider>(
310-
new InMemoryChatHistoryProvider(
311-
#pragma warning disable MEAI001
312-
new MessageCountingChatReducer(5),
313-
#pragma warning restore MEAI001
314-
ctx.SerializedState,
315-
ctx.JsonSerializerOptions,
316-
InMemoryChatHistoryProvider.ChatReducerTriggerEvent.AfterMessageAdded))
309+
ChatHistoryProvider = new InMemoryChatHistoryProvider(new() { })
317310
});
318311
}
319312

@@ -354,7 +347,7 @@
354347
try
355348
{
356349
InitializeAgent();
357-
_agentSession ??= await _agent!.GetNewSessionAsync();
350+
_agentSession ??= await _agent!.CreateSessionAsync();
358351

359352
var options = new AgentRunOptions();
360353
await foreach (var update in _agent!.RunStreamingAsync(userMessageContent, _agentSession, options, CancellationToken.None))

0 commit comments

Comments
 (0)