From 7e6db07598b2a56f527525ef9d0e1f22c76a05be Mon Sep 17 00:00:00 2001 From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:39:35 +0700 Subject: [PATCH] Fix reply to user --- .../AI/Gemini/GeminiTextPromptHandler.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs index 826b5d9..89e2fa4 100644 --- a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs @@ -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; @@ -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,