Skip to content

Commit fda4ea4

Browse files
committed
Update dependencies and refactor Chatbot for new OpenAI API
- Upgrade multiple NuGet packages to latest (incl. pre-release) versions across projects - Refactor Chatbot.razor to use AgentSession and InMemoryChatHistoryProvider per Microsoft.Agents.AI.OpenAI API changes - Update using statements and improve code clarity - Aligns chatbot logic with latest OpenAI agent session model and storage APIs
1 parent bddaa4d commit fda4ea4

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

src/Application/Application.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.1.1" />
2020
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="10.0.2" />
2121
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="10.0.2" />
22-
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
23-
<PackageReference Include="Riok.Mapperly" Version="4.3.1" />
22+
<PackageReference Include="Newtonsoft.Json" Version="13.0.5-beta1" />
23+
<PackageReference Include="Riok.Mapperly" Version="5.0.0-next.0" />
2424
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.7.1" />
2525
<PackageReference Include="Hangfire.Core" Version="1.8.22" />
2626
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.5.0" />

src/Domain/Domain.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
2121
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.2" />
2222
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.2" />
23-
<PackageReference Include="EFCore.NamingConventions" Version="10.0.0" />
23+
<PackageReference Include="EFCore.NamingConventions" Version="10.0.1" />
2424
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.0.2" />
2525
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="10.0.2" />
2626
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.2">

src/Infrastructure/Infrastructure.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
<LangVersion>default</LangVersion>
99
</PropertyGroup>
1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.260121.1" />
11+
<PackageReference Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.260128.1" />
1212
<PackageReference Include="OpenAI" Version="2.8.0" />
1313
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="10.0.2" />
1414
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="10.0.2" />
1515
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="10.0.2" />
16-
<PackageReference Include="QuestPDF" Version="2025.12.2" />
16+
<PackageReference Include="QuestPDF" Version="2025.12.3.1-alpha2" />
1717
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
18-
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="9.0.2" />
18+
<PackageReference Include="Serilog.Sinks.MSSqlServer" Version="9.0.3-dev-00155" />
1919
<PackageReference Include="Serilog.Sinks.Postgresql.Alternative" Version="4.2.0" />
2020
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
2121
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />

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

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@page "/ai/chatbot"
22

3+
@using Microsoft.Extensions.VectorData
34
@using OpenAI
45
@using OpenAI.Chat
56
@using Microsoft.Agents.AI
@@ -244,23 +245,22 @@
244245
</style>
245246

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

265265
protected override async Task OnAfterRenderAsync(bool firstRender)
266266
{
@@ -286,6 +286,7 @@
286286
{
287287
if (_agent is not null) return;
288288

289+
289290
var apiKey = Configuration["AISettings:OpenAIApiKey"];
290291
if (string.IsNullOrEmpty(apiKey) || apiKey == "your-openai-api-key")
291292
{
@@ -305,14 +306,14 @@
305306
Instructions = instructions,
306307
Tools = [AIFunctionFactory.Create(GetCurrentDate)]
307308
},
308-
ChatMessageStoreFactory = (ctx, ct) => new ValueTask<ChatMessageStore>(
309-
new InMemoryChatMessageStore(
310-
#pragma warning disable MEAI001
311-
new MessageCountingChatReducer(5),
312-
#pragma warning restore MEAI001
313-
ctx.SerializedState,
314-
ctx.JsonSerializerOptions,
315-
InMemoryChatMessageStore.ChatReducerTriggerEvent.AfterMessageAdded))
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))
316317
});
317318
}
318319

@@ -353,10 +354,10 @@
353354
try
354355
{
355356
InitializeAgent();
356-
_thread ??= await _agent!.GetNewThreadAsync();
357+
_agentSession ??= await _agent!.GetNewSessionAsync();
357358

358359
var options = new AgentRunOptions();
359-
await foreach (var update in _agent!.RunStreamingAsync(userMessageContent, _thread, options, CancellationToken.None))
360+
await foreach (var update in _agent!.RunStreamingAsync(userMessageContent, _agentSession, options, CancellationToken.None))
360361
{
361362
if (!string.IsNullOrEmpty(update.Text))
362363
{

src/Server.UI/Server.UI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.2" />
2323
<PackageReference Include="MudBlazor" Version="8.15.0" />
2424
<PackageReference Include="Toolbelt.Blazor.HotKeys2" Version="6.2.0" />
25-
<PackageReference Include="Blazor-ApexCharts" Version="6.0.2" />
25+
<PackageReference Include="Blazor-ApexCharts" Version="6.1.0" />
2626
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.2">
2727
<PrivateAssets>all</PrivateAssets>
2828
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

0 commit comments

Comments
 (0)