|
9 | 9 | @using System.ComponentModel |
10 | 10 |
|
11 | 11 | @inject IConfiguration Configuration |
12 | | - |
| 12 | +@inject UserProfileStateService UserProfileStateService |
13 | 13 |
|
14 | 14 | <PageTitle>Chatbot</PageTitle> |
15 | 15 |
|
|
245 | 245 | </style> |
246 | 246 |
|
247 | 247 | @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; |
264 | 264 |
|
265 | 265 | protected override async Task OnAfterRenderAsync(bool firstRender) |
266 | 266 | { |
|
306 | 306 | Instructions = instructions, |
307 | 307 | Tools = [AIFunctionFactory.Create(GetCurrentDate)] |
308 | 308 | }, |
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() { }) |
317 | 310 | }); |
318 | 311 | } |
319 | 312 |
|
|
354 | 347 | try |
355 | 348 | { |
356 | 349 | InitializeAgent(); |
357 | | - _agentSession ??= await _agent!.GetNewSessionAsync(); |
| 350 | + _agentSession ??= await _agent!.CreateSessionAsync(); |
358 | 351 |
|
359 | 352 | var options = new AgentRunOptions(); |
360 | 353 | await foreach (var update in _agent!.RunStreamingAsync(userMessageContent, _agentSession, options, CancellationToken.None)) |
|
0 commit comments