Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions ProjectVG.Application/Services/Chat/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ public async Task<ChatRequestResult> EnqueueChatRequestAsync(ChatRequestCommand

var preprocessContext = await PrepareChatRequestAsync(command);

LogChatRequestCommand(command);

_ = Task.Run(async () => {
await ProcessChatRequestInternalAsync(preprocessContext);
await ProcessChatRequestInternalAsync(preprocessContext).ConfigureAwait(false);
});

return ChatRequestResult.Accepted(command.Id.ToString(), command.UserId, command.CharacterId);
Expand Down Expand Up @@ -109,36 +107,24 @@ private async Task ProcessChatRequestInternalAsync(ChatProcessContext context)
{
using var scope = _scopeFactory.CreateScope();
try {
await _llmProcessor.ProcessAsync(context);
await _ttsProcessor.ProcessAsync(context);
await _llmProcessor.ProcessAsync(context).ConfigureAwait(false);
await _ttsProcessor.ProcessAsync(context).ConfigureAwait(false);

// ChatSuccessHandler와 ChatResultProcessor를 같은 스코프에서 실행

var successHandler = scope.ServiceProvider.GetRequiredService<ChatSuccessHandler>();
var resultProcessor = scope.ServiceProvider.GetRequiredService<ChatResultProcessor>();
await successHandler.HandleAsync(context);
await resultProcessor.PersistResultsAsync(context);

await successHandler.HandleAsync(context).ConfigureAwait(false);
await resultProcessor.PersistResultsAsync(context).ConfigureAwait(false);
}
catch (Exception) {
var failureHandler = scope.ServiceProvider.GetRequiredService<ChatFailureHandler>();
await failureHandler.HandleAsync(context);
await failureHandler.HandleAsync(context).ConfigureAwait(false);
}
finally {
LogChatProcessContext(context);
_metricsService.EndChatMetrics();
_metricsService.LogChatMetrics();
}
}

private void LogChatRequestCommand(ChatRequestCommand command)
{
_logger.LogInformation("Starting chat process: {CommandInfo}", command.ToDebugString());
}

private void LogChatProcessContext(ChatProcessContext context)
{
_logger.LogInformation("Chat process completed: {ContextInfo}", context.ToDebugString());
}
}
}
Loading