From f0013531db114db2fbe0262aa02912e7d4a02817 Mon Sep 17 00:00:00 2001 From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:33:16 +0700 Subject: [PATCH] Show which AI generated the response --- .../AI/Gemini/GeminiTextPromptHandler.cs | 7 +++++++ BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs | 10 ++++++++++ .../AI/OpenAI/OpenAIImageGenerationPromptHandler.cs | 7 +++++++ .../AI/OpenAI/OpenAIImagePromptHandler.cs | 7 +++++++ .../AI/OpenAI/OpenAITextPromptHandler.cs | 10 ++++++++++ .../AI/Stability/StabilityTextToImagePromptHandler.cs | 7 +++++++ 6 files changed, 48 insertions(+) diff --git a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs index f08202d..826b5d9 100644 --- a/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs @@ -15,6 +15,7 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; +using Telegram.Bot.Types.ReplyMarkups; namespace BotNet.CommandHandlers.AI.Gemini { public sealed class GeminiTextPromptHandler( @@ -174,6 +175,12 @@ await _telegramBotClient.EditMessageTextAsync( messageId: responseMessage.MessageId, text: MarkdownV2Sanitizer.Sanitize(response), parseMode: ParseMode.MarkdownV2, + replyMarkup: new InlineKeyboardMarkup( + InlineKeyboardButton.WithUrl( + text: "Generated by Google Gemini Pro", + url: "https://deepmind.google/technologies/gemini/" + ) + ), cancellationToken: cancellationToken ); } catch (Exception exc) { diff --git a/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs index b3c58bf..a8f9fbc 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs @@ -12,6 +12,7 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; +using Telegram.Bot.Types.ReplyMarkups; namespace BotNet.CommandHandlers.AI.OpenAI { public sealed class AskCommandHandler( @@ -83,6 +84,15 @@ select ChatMessage.FromText( messageId: responseMessage.MessageId, text: MarkdownV2Sanitizer.Sanitize(response), parseMode: ParseMode.MarkdownV2, + replyMarkup: new InlineKeyboardMarkup( + InlineKeyboardButton.WithUrl( + text: askCommand switch { + ({ Command: { Sender: VIPSender } or { Chat: HomeGroupChat } }) => "Generated by OpenAI GPT-4", + _ => "Generated by OpenAI GPT-3.5 Turbo" + }, + url: "https://openai.com/gpt-4" + ) + ), cancellationToken: cancellationToken ); } catch (Exception exc) { diff --git a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs index fd1833d..b599153 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImageGenerationPromptHandler.cs @@ -7,6 +7,7 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; +using Telegram.Bot.Types.ReplyMarkups; namespace BotNet.CommandHandlers.AI.OpenAI { public sealed class OpenAIImageGenerationPromptHandler( @@ -59,6 +60,12 @@ await _telegramBotClient.DeleteMessageAsync( Message responseMessage = await _telegramBotClient.SendPhotoAsync( chatId: command.Chat.Id, photo: new InputFileUrl(generatedImageUrl), + replyMarkup: new InlineKeyboardMarkup( + InlineKeyboardButton.WithUrl( + text: "Generated by OpenAI DALL-E 3", + url: "https://openai.com/dall-e-3" + ) + ), replyToMessageId: command.PromptMessageId, cancellationToken: cancellationToken ); diff --git a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs index 4677450..d67fd5a 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs @@ -15,6 +15,7 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; +using Telegram.Bot.Types.ReplyMarkups; namespace BotNet.CommandHandlers.AI.OpenAI { public sealed class OpenAIImagePromptHandler( @@ -181,6 +182,12 @@ await _telegramBotClient.EditMessageTextAsync( messageId: responseMessage.MessageId, text: MarkdownV2Sanitizer.Sanitize(response), parseMode: ParseMode.MarkdownV2, + replyMarkup: new InlineKeyboardMarkup( + InlineKeyboardButton.WithUrl( + text: "Generated by OpenAI GPT-4", + url: "https://openai.com/gpt-4" + ) + ), cancellationToken: cancellationToken ); } catch (Exception exc) { diff --git a/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs index ebe4527..070992e 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs @@ -14,6 +14,7 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; +using Telegram.Bot.Types.ReplyMarkups; namespace BotNet.CommandHandlers.AI.OpenAI { public sealed class OpenAITextPromptHandler( @@ -147,6 +148,15 @@ await _telegramBotClient.EditMessageTextAsync( messageId: responseMessage.MessageId, text: MarkdownV2Sanitizer.Sanitize(response), parseMode: ParseMode.MarkdownV2, + replyMarkup: new InlineKeyboardMarkup( + InlineKeyboardButton.WithUrl( + text: textPrompt switch { + ({ Command: { Sender: VIPSender } or { Chat: HomeGroupChat } }) => "Generated by OpenAI GPT-4", + _ => "Generated by OpenAI GPT-3.5 Turbo" + }, + url: "https://openai.com/gpt-4" + ) + ), cancellationToken: cancellationToken ); } catch (Exception exc) { diff --git a/BotNet.CommandHandlers/AI/Stability/StabilityTextToImagePromptHandler.cs b/BotNet.CommandHandlers/AI/Stability/StabilityTextToImagePromptHandler.cs index 6222aaf..73dfdfe 100644 --- a/BotNet.CommandHandlers/AI/Stability/StabilityTextToImagePromptHandler.cs +++ b/BotNet.CommandHandlers/AI/Stability/StabilityTextToImagePromptHandler.cs @@ -7,6 +7,7 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; +using Telegram.Bot.Types.ReplyMarkups; namespace BotNet.CommandHandlers.AI.Stability { public sealed class StabilityTextToImagePromptHandler( @@ -66,6 +67,12 @@ await _telegramBotClient.DeleteMessageAsync( Message responseMessage = await _telegramBotClient.SendPhotoAsync( chatId: command.Chat.Id, photo: new InputFileStream(generatedImageStream, "art.png"), + replyMarkup: new InlineKeyboardMarkup( + InlineKeyboardButton.WithUrl( + text: "Generated by stability.ai SDXL", + url: "https://stability.ai/stable-image" + ) + ), replyToMessageId: command.PromptMessageId, cancellationToken: cancellationToken );