Skip to content

Commit

Permalink
Fix AI follow up message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Jan 1, 2024
1 parent d39d65c commit 1bf7dff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
10 changes: 7 additions & 3 deletions BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs
Original file line number Diff line number Diff line change
@@ -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<AICallCommand> {
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,
Expand All @@ -26,6 +28,8 @@ await _commandQueue.DispatchAsync(
)
);
break;
case "AI" or "Bot" or "GPT" when command.ImageFileId is { } imageFileId:
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MessageBase>()
: _telegramMessageCache.GetThread(
firstMessage: command.ReplyToMessage
)
: Enumerable.Empty<MessageBase>()
)
);
break;
Expand Down

0 comments on commit 1bf7dff

Please sign in to comment.