Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show which AI generated the response #108

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions BotNet.CommandHandlers/AI/Gemini/GeminiTextPromptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
);
Expand Down
7 changes: 7 additions & 0 deletions BotNet.CommandHandlers/AI/OpenAI/OpenAIImagePromptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions BotNet.CommandHandlers/AI/OpenAI/OpenAITextPromptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
);
Expand Down
Loading