Skip to content

Commit

Permalink
Code(WEB::CreateChatSessionHandler): Add logging for new chat creatio…
Browse files Browse the repository at this point in the history
…n and missing UpdatedAt property update
  • Loading branch information
ktutak1337 committed Jun 22, 2024
1 parent 1ef98d2 commit abdb467
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async ValueTask<Unit> Handle(CreateChatSession command, CancellationToken
}

var now = _clock.GetLocalNow();

// TODO: Retrieve activePlugins and metaprompt from settings
var activePlugins = new HashSet<string>();

Expand All @@ -46,6 +46,7 @@ public async ValueTask<Unit> Handle(CreateChatSession command, CancellationToken

_ = Task.Run(async () =>
{
_logger.LogInformation($"Generating chat title using LLM for chat ID: '{chatSession.Id}'...");
await GenerateChatTitle(chatSession, command.Message);
});

Expand All @@ -55,6 +56,7 @@ public async ValueTask<Unit> Handle(CreateChatSession command, CancellationToken
private async Task GenerateChatTitle(ChatSession chatSession, string message)
{
await Task.Delay(1000);

var chatCompletionService = _kernel.GetRequiredService<IChatCompletionService>();
var reply = new StringBuilder();

Expand All @@ -72,10 +74,15 @@ private async Task GenerateChatTitle(ChatSession chatSession, string message)
await _hubContext.Clients.All.ReceiveUpdateChatTitle(chatSession.Id, contentPiece.Content);
}
}

var now = _clock.GetLocalNow();

chatSession.Title = reply.ToString();
chatSession.UpdatedAt = now;

reply.Clear();

await _chatSessionRepository.UpdateAsync(chatSession);
_logger.LogInformation($"Chat session with ID: '{chatSession.Id}' title has been updated.");
}
}

0 comments on commit abdb467

Please sign in to comment.