From 1bf7dfff94c330020a5503db1a84b092fb1eb19c Mon Sep 17 00:00:00 2001 From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com> Date: Mon, 1 Jan 2024 17:49:42 +0700 Subject: [PATCH] Fix AI follow up message handling --- .../BotUpdate/Message/AICallCommandHandler.cs | 10 +++++++--- .../BotUpdate/Message/AIFollowUpMessageHandler.cs | 9 ++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs b/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs index d5d23ed..c6b33b4 100644 --- a/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs +++ b/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs @@ -1,19 +1,21 @@ using BotNet.Commands; using BotNet.Commands.AI.OpenAI; using BotNet.Commands.BotUpdate.Message; +using BotNet.Services.OpenAI; namespace BotNet.CommandHandlers.BotUpdate.Message { public sealed class AICallCommandHandler( ICommandQueue commandQueue, - ITelegramMessageCache telegramMessageCache + ITelegramMessageCache telegramMessageCache, + IntentDetector intentDetector ) : ICommandHandler { private readonly ICommandQueue _commandQueue = commandQueue; private readonly ITelegramMessageCache _telegramMessageCache = telegramMessageCache; + private readonly IntentDetector _intentDetector = intentDetector; public async Task Handle(AICallCommand command, CancellationToken cancellationToken) { switch (command.CallSign) { - // OpenAI GPT-4 Chat - case "AI" or "Bot" or "GPT": + case "AI" or "Bot" or "GPT" when command.ImageFileId is null: await _commandQueue.DispatchAsync( command: OpenAITextPrompt.FromAICallCommand( aiCallCommand: command, @@ -26,6 +28,8 @@ await _commandQueue.DispatchAsync( ) ); break; + case "AI" or "Bot" or "GPT" when command.ImageFileId is { } imageFileId: + break; } } } diff --git a/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs b/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs index e6e86e6..ffdebfb 100644 --- a/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs +++ b/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs @@ -17,12 +17,11 @@ public async Task Handle(AIFollowUpMessage command, CancellationToken cancellati await _commandQueue.DispatchAsync( command: OpenAITextPrompt.FromAIFollowUpMessage( aiFollowUpMessage: command, - thread: command.ReplyToMessageId.HasValue - ? _telegramMessageCache.GetThread( - messageId: command.ReplyToMessageId.Value, - chatId: command.ChatId + thread: command.ReplyToMessage is null + ? Enumerable.Empty() + : _telegramMessageCache.GetThread( + firstMessage: command.ReplyToMessage ) - : Enumerable.Empty() ) ); break;