From 14c409d7164033d035a50a0fc349ff79f984b23e Mon Sep 17 00:00:00 2001 From: Ronny Gunawan <3048897+ronnygunawan@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:52:41 +0700 Subject: [PATCH] Set Gemini as default AI --- .../AI/OpenAI/AskCommandHandler.cs | 2 +- BotNet.CommandHandlers/Art/ArtCommandHandler.cs | 4 ++-- .../BotUpdate/Message/AICallCommandHandler.cs | 6 +++--- .../BotUpdate/Message/AIFollowUpMessageHandler.cs | 6 ++++-- BotNet.Commands/AI/Gemini/GeminiTextPrompt.cs | 12 ++++++------ BotNet.Commands/AI/OpenAI/OpenAIImagePrompt.cs | 6 +++--- BotNet.Commands/AI/OpenAI/OpenAITextPrompt.cs | 12 ++++++------ BotNet.Services/BotCommands/OpenAI.cs | 4 ++-- BotNet.Services/OpenAI/Skills/FriendlyBot.cs | 10 +++++----- BotNet.Services/OpenAI/Skills/SarcasticBot.cs | 2 +- BotNet.Services/OpenAI/Skills/VisionBot.cs | 6 +++--- 11 files changed, 36 insertions(+), 34 deletions(-) diff --git a/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs b/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs index a8f9fbc..fb8c236 100644 --- a/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs +++ b/BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs @@ -105,7 +105,7 @@ select ChatMessage.FromText( message: AIResponseMessage.FromMessage( message: responseMessage, replyToMessage: askCommand.Command, - callSign: "AI", + callSign: "GPT", commandPriorityCategorizer: _commandPriorityCategorizer ) ); diff --git a/BotNet.CommandHandlers/Art/ArtCommandHandler.cs b/BotNet.CommandHandlers/Art/ArtCommandHandler.cs index cae9481..d4cd363 100644 --- a/BotNet.CommandHandlers/Art/ArtCommandHandler.cs +++ b/BotNet.CommandHandlers/Art/ArtCommandHandler.cs @@ -48,7 +48,7 @@ public Task Handle(ArtCommand command, CancellationToken cancellationToken) { await _commandQueue.DispatchAsync( new OpenAIImageGenerationPrompt( - callSign: "AI", + callSign: "GPT", prompt: command.Prompt, promptMessageId: command.PromptMessageId, responseMessageId: new(busyMessage.MessageId), @@ -69,7 +69,7 @@ await _commandQueue.DispatchAsync( await _commandQueue.DispatchAsync( new StabilityTextToImagePrompt( - callSign: "AI", + callSign: "GPT", prompt: command.Prompt, promptMessageId: command.PromptMessageId, responseMessageId: new(busyMessage.MessageId), diff --git a/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs b/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs index 2aacc4c..78577fa 100644 --- a/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs +++ b/BotNet.CommandHandlers/BotUpdate/Message/AICallCommandHandler.cs @@ -16,7 +16,7 @@ IntentDetector intentDetector public async Task Handle(AICallCommand command, CancellationToken cancellationToken) { switch (command.CallSign) { - case "AI" or "Bot" or "GPT" when command.ImageFileId is null && command.ReplyToMessage?.ImageFileId is null: { + case "GPT" when command.ImageFileId is null && command.ReplyToMessage?.ImageFileId is null: { await _commandQueue.DispatchAsync( command: OpenAITextPrompt.FromAICallCommand( aiCallCommand: command, @@ -27,7 +27,7 @@ await _commandQueue.DispatchAsync( ); break; } - case "AI" or "Bot" or "GPT" when command.ImageFileId is not null || command.ReplyToMessage?.ImageFileId is not null: { + case "GPT" when command.ImageFileId is not null || command.ReplyToMessage?.ImageFileId is not null: { await _commandQueue.DispatchAsync( command: OpenAIImagePrompt.FromAICallCommand( aiCallCommand: command, @@ -38,7 +38,7 @@ await _commandQueue.DispatchAsync( ); break; } - case "Gemini" when command.ImageFileId is null && command.ReplyToMessage?.ImageFileId is null: { + case "AI" or "Bot" or "Gemini" when command.ImageFileId is null && command.ReplyToMessage?.ImageFileId is null: { await _commandQueue.DispatchAsync( command: GeminiTextPrompt.FromAICallCommand( aiCallCommand: command, diff --git a/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs b/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs index 2d4e023..b05e37c 100644 --- a/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs +++ b/BotNet.CommandHandlers/BotUpdate/Message/AIFollowUpMessageHandler.cs @@ -14,7 +14,7 @@ ITelegramMessageCache telegramMessageCache public async Task Handle(AIFollowUpMessage command, CancellationToken cancellationToken) { switch (command.CallSign) { // OpenAI GPT-4 Chat - case "AI" or "Bot" or "GPT": + case "GPT": await _commandQueue.DispatchAsync( command: OpenAITextPrompt.FromAIFollowUpMessage( aiFollowUpMessage: command, @@ -26,7 +26,9 @@ await _commandQueue.DispatchAsync( ) ); break; - case "Gemini": + + // Google Gemini Chat + case "AI" or "Bot" or "Gemini": await _commandQueue.DispatchAsync( command: GeminiTextPrompt.FromAIFollowUpMessage( aIFollowUpMessage: command, diff --git a/BotNet.Commands/AI/Gemini/GeminiTextPrompt.cs b/BotNet.Commands/AI/Gemini/GeminiTextPrompt.cs index e19d460..0d5b8f8 100644 --- a/BotNet.Commands/AI/Gemini/GeminiTextPrompt.cs +++ b/BotNet.Commands/AI/Gemini/GeminiTextPrompt.cs @@ -17,9 +17,9 @@ IEnumerable thread } public static GeminiTextPrompt FromAICallCommand(AICallCommand aiCallCommand, IEnumerable thread) { - // Call sign must be Gemini - if (aiCallCommand.CallSign != "Gemini") { - throw new ArgumentException("Call sign must be Gemini", nameof(aiCallCommand)); + // Call sign must be Gemini, AI, or Bot + if (aiCallCommand.CallSign is not "Gemini" and not "AI" and not "Bot") { + throw new ArgumentException("Call sign must be Gemini, AI, or Bot", nameof(aiCallCommand)); } // Prompt must be non-empty @@ -46,9 +46,9 @@ public static GeminiTextPrompt FromAICallCommand(AICallCommand aiCallCommand, IE } public static GeminiTextPrompt FromAIFollowUpMessage(AIFollowUpMessage aIFollowUpMessage, IEnumerable thread) { - // Call sign must be Gemini - if (aIFollowUpMessage.CallSign != "Gemini") { - throw new ArgumentException("Call sign must be Gemini", nameof(aIFollowUpMessage)); + // Call sign must be Gemini, AI, or Bot + if (aIFollowUpMessage.CallSign is not "Gemini" and not "AI" and not "Bot") { + throw new ArgumentException("Call sign must be Gemini, AI, or Bot", nameof(aIFollowUpMessage)); } // Prompt must be non-empty diff --git a/BotNet.Commands/AI/OpenAI/OpenAIImagePrompt.cs b/BotNet.Commands/AI/OpenAI/OpenAIImagePrompt.cs index f416d4e..4f8657f 100644 --- a/BotNet.Commands/AI/OpenAI/OpenAIImagePrompt.cs +++ b/BotNet.Commands/AI/OpenAI/OpenAIImagePrompt.cs @@ -23,9 +23,9 @@ IEnumerable thread } public static OpenAIImagePrompt FromAICallCommand(AICallCommand aiCallCommand, IEnumerable thread) { - // Call sign must be AI, Bot, or GPT - if (aiCallCommand.CallSign is not "AI" and not "Bot" and not "GPT") { - throw new ArgumentException("Call sign must be AI, Bot, or GPT.", nameof(aiCallCommand)); + // Call sign must be GPT + if (aiCallCommand.CallSign is not "GPT") { + throw new ArgumentException("Call sign must be GPT.", nameof(aiCallCommand)); } // Prompt must be non-empty diff --git a/BotNet.Commands/AI/OpenAI/OpenAITextPrompt.cs b/BotNet.Commands/AI/OpenAI/OpenAITextPrompt.cs index e55b608..2f6f706 100644 --- a/BotNet.Commands/AI/OpenAI/OpenAITextPrompt.cs +++ b/BotNet.Commands/AI/OpenAI/OpenAITextPrompt.cs @@ -20,9 +20,9 @@ IEnumerable thread } public static OpenAITextPrompt FromAICallCommand(AICallCommand aiCallCommand, IEnumerable thread) { - // Call sign must be AI, Bot, or GPT - if (aiCallCommand.CallSign is not "AI" and not "Bot" and not "GPT") { - throw new ArgumentException("Call sign must be AI, Bot, or GPT.", nameof(aiCallCommand)); + // Call sign must be GPT + if (aiCallCommand.CallSign is not "GPT") { + throw new ArgumentException("Call sign must be GPT.", nameof(aiCallCommand)); } // Prompt must be non-empty @@ -50,9 +50,9 @@ public static OpenAITextPrompt FromAICallCommand(AICallCommand aiCallCommand, IE } public static OpenAITextPrompt FromAIFollowUpMessage(AIFollowUpMessage aiFollowUpMessage, IEnumerable thread) { - // Call sign must be AI, Bot, or GPT - if (aiFollowUpMessage.CallSign is not "AI" and not "Bot" and not "GPT") { - throw new ArgumentException("Call sign must be AI, Bot, or GPT.", nameof(aiFollowUpMessage)); + // Call sign must be GPT + if (aiFollowUpMessage.CallSign is not "GPT") { + throw new ArgumentException("Call sign must be GPT.", nameof(aiFollowUpMessage)); } // Prompt must be non-empty diff --git a/BotNet.Services/BotCommands/OpenAI.cs b/BotNet.Services/BotCommands/OpenAI.cs index 8479a85..6357e42 100644 --- a/BotNet.Services/BotCommands/OpenAI.cs +++ b/BotNet.Services/BotCommands/OpenAI.cs @@ -285,7 +285,7 @@ await botClient.DeleteMessageAsync( // Track generated image for continuation serviceProvider.GetRequiredService().TrackMessage( messageId: generatedImageMessage.MessageId, - sender: "AI", + sender: "GPT", text: null, imageBase64: Convert.ToBase64String(generatedImage), replyToMessageId: message.MessageId @@ -411,7 +411,7 @@ await botClient.DeleteMessageAsync( // Track generated image for continuation serviceProvider.GetRequiredService().TrackMessage( messageId: modifiedImageMessage.MessageId, - sender: "AI", + sender: "GPT", text: null, imageBase64: Convert.ToBase64String(modifiedImage), replyToMessageId: message.MessageId diff --git a/BotNet.Services/OpenAI/Skills/FriendlyBot.cs b/BotNet.Services/OpenAI/Skills/FriendlyBot.cs index d45976f..b1a4013 100644 --- a/BotNet.Services/OpenAI/Skills/FriendlyBot.cs +++ b/BotNet.Services/OpenAI/Skills/FriendlyBot.cs @@ -38,7 +38,7 @@ public Task RespondToThreadAsync(string callSign, string name, string qu + $"{callSign}: I am an AI created by TEKNUM. How can I help you today?\n\n"; foreach ((string sender, string text) in thread) { prompt += $"{sender}: {text}\n"; - if (sender is "AI" or "Pakde") prompt += "\n"; + if (sender is "GPT" or "Pakde") prompt += "\n"; } prompt += $"{name}: {question}\n" @@ -80,7 +80,7 @@ await _openAIStreamingClient.StreamChatAsync( model: "gpt-4-1106-preview", messages: messages, maxTokens: 512, - callSign: "AI", + callSign: "GPT", chatId: chatId, replyToMessageId: replyToMessageId ); @@ -92,7 +92,7 @@ public Task ChatAsync(string message, ImmutableList<(string Sender, stri from tuple in thread let role = tuple.Sender switch { - "AI" => "assistant", + "GPT" => "assistant", _ => "user" } select tuple switch { @@ -119,7 +119,7 @@ public async Task StreamChatAsync(string message, ImmutableList<(string Sender, from tuple in thread let role = tuple.Sender switch { - "AI" => "assistant", + "GPT" => "assistant", _ => "user" } select tuple switch { @@ -136,7 +136,7 @@ await _openAIStreamingClient.StreamChatAsync( model: "gpt-4-1106-preview", messages: messages, maxTokens: 512, - callSign: "AI", + callSign: "GPT", chatId: chatId, replyToMessageId: replyToMessageId ); diff --git a/BotNet.Services/OpenAI/Skills/SarcasticBot.cs b/BotNet.Services/OpenAI/Skills/SarcasticBot.cs index 084b559..5d45139 100644 --- a/BotNet.Services/OpenAI/Skills/SarcasticBot.cs +++ b/BotNet.Services/OpenAI/Skills/SarcasticBot.cs @@ -45,7 +45,7 @@ public Task RespondToThreadAsync(string callSign, string name, string qu + $"{callSign}: Entahlah. Nanti coba saya tanya ke teman saya Google.\n\n"; foreach ((string sender, string? text, string? imageBase64) in thread) { prompt += $"{sender}: {text}\n"; - if (sender is "AI" or "Pakde") prompt += "\n"; + if (sender is "GPT" or "Pakde") prompt += "\n"; } prompt += $"{name}: {question}\n" diff --git a/BotNet.Services/OpenAI/Skills/VisionBot.cs b/BotNet.Services/OpenAI/Skills/VisionBot.cs index 8227de4..05d8db5 100644 --- a/BotNet.Services/OpenAI/Skills/VisionBot.cs +++ b/BotNet.Services/OpenAI/Skills/VisionBot.cs @@ -25,7 +25,7 @@ await _openAIStreamingClient.StreamChatAsync( model: "gpt-4-vision-preview", messages: messages, maxTokens: 512, - callSign: "AI", + callSign: "GPT", chatId: chatId, replyToMessageId: replyToMessageId ); @@ -43,7 +43,7 @@ int replyToMessageId from tuple in thread let role = tuple.Sender switch { - "AI" => "assistant", + "GPT" => "assistant", _ => "user" } select tuple switch { @@ -60,7 +60,7 @@ await _openAIStreamingClient.StreamChatAsync( model: "gpt-4-vision-preview", messages: messages, maxTokens: 512, - callSign: "AI", + callSign: "GPT", chatId: chatId, replyToMessageId: replyToMessageId );