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

Allow invoking vision by replying to image #102

Merged
merged 1 commit into from
Jan 30, 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
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
Loading