Skip to content

Commit

Permalink
Fix reply to user
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Feb 1, 2024
1 parent e164662 commit 7e6db07
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using BotNet.Services.Gemini.Models;
using BotNet.Services.MarkdownV2;
using BotNet.Services.RateLimit;
using Google.Protobuf;
using Microsoft.Extensions.Logging;
using Telegram.Bot;
using Telegram.Bot.Types;
Expand Down Expand Up @@ -95,9 +96,13 @@ public Task Handle(GeminiTextPrompt textPrompt, CancellationToken cancellationTo
messages.RemoveAt(0);
}

messages.Add(
Content.FromText("user", textPrompt.Prompt)
);
// Merge user message with replied to message if thread is initiated by replying to another user
if (messages.Count > 0
&& messages[^1].Role == "user") {
messages[^1].Add(Content.FromText("user", textPrompt.Prompt));
} else {
messages.Add(Content.FromText("user", textPrompt.Prompt));
}

Message responseMessage = await _telegramBotClient.SendTextMessageAsync(
chatId: textPrompt.Command.Chat.Id,
Expand Down

0 comments on commit 7e6db07

Please sign in to comment.