Skip to content

Commit

Permalink
Set Gemini as default AI
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Feb 1, 2024
1 parent 71701cc commit 14c409d
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 34 deletions.
2 changes: 1 addition & 1 deletion BotNet.CommandHandlers/AI/OpenAI/AskCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ select ChatMessage.FromText(
message: AIResponseMessage.FromMessage(
message: responseMessage,
replyToMessage: askCommand.Command,
callSign: "AI",
callSign: "GPT",
commandPriorityCategorizer: _commandPriorityCategorizer
)
);
Expand Down
4 changes: 2 additions & 2 deletions BotNet.CommandHandlers/Art/ArtCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions BotNet.Commands/AI/Gemini/GeminiTextPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ IEnumerable<MessageBase> thread
}

public static GeminiTextPrompt FromAICallCommand(AICallCommand aiCallCommand, IEnumerable<MessageBase> 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
Expand All @@ -46,9 +46,9 @@ public static GeminiTextPrompt FromAICallCommand(AICallCommand aiCallCommand, IE
}

public static GeminiTextPrompt FromAIFollowUpMessage(AIFollowUpMessage aIFollowUpMessage, IEnumerable<MessageBase> 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
Expand Down
6 changes: 3 additions & 3 deletions BotNet.Commands/AI/OpenAI/OpenAIImagePrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ IEnumerable<MessageBase> thread
}

public static OpenAIImagePrompt FromAICallCommand(AICallCommand aiCallCommand, IEnumerable<MessageBase> 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
Expand Down
12 changes: 6 additions & 6 deletions BotNet.Commands/AI/OpenAI/OpenAITextPrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ IEnumerable<MessageBase> thread
}

public static OpenAITextPrompt FromAICallCommand(AICallCommand aiCallCommand, IEnumerable<MessageBase> 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
Expand Down Expand Up @@ -50,9 +50,9 @@ public static OpenAITextPrompt FromAICallCommand(AICallCommand aiCallCommand, IE
}

public static OpenAITextPrompt FromAIFollowUpMessage(AIFollowUpMessage aiFollowUpMessage, IEnumerable<MessageBase> 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
Expand Down
4 changes: 2 additions & 2 deletions BotNet.Services/BotCommands/OpenAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ await botClient.DeleteMessageAsync(
// Track generated image for continuation
serviceProvider.GetRequiredService<ThreadTracker>().TrackMessage(
messageId: generatedImageMessage.MessageId,
sender: "AI",
sender: "GPT",
text: null,
imageBase64: Convert.ToBase64String(generatedImage),
replyToMessageId: message.MessageId
Expand Down Expand Up @@ -411,7 +411,7 @@ await botClient.DeleteMessageAsync(
// Track generated image for continuation
serviceProvider.GetRequiredService<ThreadTracker>().TrackMessage(
messageId: modifiedImageMessage.MessageId,
sender: "AI",
sender: "GPT",
text: null,
imageBase64: Convert.ToBase64String(modifiedImage),
replyToMessageId: message.MessageId
Expand Down
10 changes: 5 additions & 5 deletions BotNet.Services/OpenAI/Skills/FriendlyBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Task<string> 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"
Expand Down Expand Up @@ -80,7 +80,7 @@ await _openAIStreamingClient.StreamChatAsync(
model: "gpt-4-1106-preview",
messages: messages,
maxTokens: 512,
callSign: "AI",
callSign: "GPT",
chatId: chatId,
replyToMessageId: replyToMessageId
);
Expand All @@ -92,7 +92,7 @@ public Task<string> ChatAsync(string message, ImmutableList<(string Sender, stri

from tuple in thread
let role = tuple.Sender switch {
"AI" => "assistant",
"GPT" => "assistant",
_ => "user"
}
select tuple switch {
Expand All @@ -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 {
Expand All @@ -136,7 +136,7 @@ await _openAIStreamingClient.StreamChatAsync(
model: "gpt-4-1106-preview",
messages: messages,
maxTokens: 512,
callSign: "AI",
callSign: "GPT",
chatId: chatId,
replyToMessageId: replyToMessageId
);
Expand Down
2 changes: 1 addition & 1 deletion BotNet.Services/OpenAI/Skills/SarcasticBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Task<string> 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"
Expand Down
6 changes: 3 additions & 3 deletions BotNet.Services/OpenAI/Skills/VisionBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ await _openAIStreamingClient.StreamChatAsync(
model: "gpt-4-vision-preview",
messages: messages,
maxTokens: 512,
callSign: "AI",
callSign: "GPT",
chatId: chatId,
replyToMessageId: replyToMessageId
);
Expand All @@ -43,7 +43,7 @@ int replyToMessageId

from tuple in thread
let role = tuple.Sender switch {
"AI" => "assistant",
"GPT" => "assistant",
_ => "user"
}
select tuple switch {
Expand All @@ -60,7 +60,7 @@ await _openAIStreamingClient.StreamChatAsync(
model: "gpt-4-vision-preview",
messages: messages,
maxTokens: 512,
callSign: "AI",
callSign: "GPT",
chatId: chatId,
replyToMessageId: replyToMessageId
);
Expand Down

0 comments on commit 14c409d

Please sign in to comment.