Skip to content

Commit

Permalink
Merge pull request #102 from teknologi-umum/vision
Browse files Browse the repository at this point in the history
Allow invoking vision by replying to image
  • Loading branch information
ronnygunawan authored Jan 30, 2024
2 parents e15d496 + f874d72 commit cf42dc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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: {
case "AI" or "Bot" or "GPT" when command.ImageFileId is null && command.ReplyToMessage?.ImageFileId is null: {
await _commandQueue.DispatchAsync(
command: OpenAITextPrompt.FromAICallCommand(
aiCallCommand: command,
Expand All @@ -26,7 +26,7 @@ await _commandQueue.DispatchAsync(
);
break;
}
case "AI" or "Bot" or "GPT" when command.ImageFileId is { } imageFileId: {
case "AI" or "Bot" or "GPT" when command.ImageFileId is not null || command.ReplyToMessage?.ImageFileId is not null: {
await _commandQueue.DispatchAsync(
command: OpenAIImagePrompt.FromAICallCommand(
aiCallCommand: command,
Expand Down
9 changes: 7 additions & 2 deletions BotNet.Commands/AI/OpenAI/OpenAIImagePrompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public static OpenAIImagePrompt FromAICallCommand(AICallCommand aiCallCommand, I
}

// File ID must be non-empty
if (string.IsNullOrWhiteSpace(aiCallCommand.ImageFileId)) {
string imageFileId;
if (!string.IsNullOrWhiteSpace(aiCallCommand.ImageFileId)) {
imageFileId = aiCallCommand.ImageFileId;
} else if (!string.IsNullOrWhiteSpace(thread.FirstOrDefault()?.ImageFileId)) {
imageFileId = thread.First().ImageFileId!;
} else {
throw new ArgumentException("File ID must be non-empty.", nameof(aiCallCommand));
}

Expand All @@ -52,7 +57,7 @@ public static OpenAIImagePrompt FromAICallCommand(AICallCommand aiCallCommand, I
return new(
callSign: aiCallCommand.CallSign,
prompt: aiCallCommand.Text,
imageFileId: aiCallCommand.ImageFileId,
imageFileId: imageFileId,
command: aiCallCommand,
thread: thread
);
Expand Down

0 comments on commit cf42dc8

Please sign in to comment.