-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9432ab3
commit 1280ce4
Showing
18 changed files
with
188 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BotNet.Services.OpenAI.Models; | ||
|
||
namespace BotNet.Services.OpenAI { | ||
public sealed class IntentDetector( | ||
OpenAIClient openAIClient | ||
) { | ||
private readonly OpenAIClient _openAIClient = openAIClient; | ||
|
||
public async Task<ChatIntent> DetectChatIntentAsync( | ||
string message, | ||
CancellationToken cancellationToken | ||
) { | ||
List<ChatMessage> messages = [ | ||
new("user", $$""" | ||
These are available intents that one might query when they provide a text prompt: | ||
Question, | ||
ImageGeneration | ||
Which intent is this query asking for? If none match, respond with Unknown. | ||
{{message}} | ||
Intent: | ||
""") | ||
]; | ||
|
||
string answer = await _openAIClient.ChatAsync( | ||
model: "gpt-3.5-turbo", | ||
messages: messages, | ||
maxTokens: 128, | ||
cancellationToken: cancellationToken | ||
); | ||
|
||
return answer switch { | ||
"Question" => ChatIntent.Question, | ||
"ImageGeneration" => ChatIntent.ImageGeneration, | ||
"Unknown" => ChatIntent.Question, | ||
_ => ChatIntent.Question | ||
}; | ||
} | ||
|
||
public async Task<ImagePromptIntent> DetectImagePromptIntentAsync( | ||
string message, | ||
CancellationToken cancellationToken | ||
) { | ||
List<ChatMessage> messages = [ | ||
new("user", $$""" | ||
These are available intents that one might query when they provide a prompt which contain an image: | ||
Vision, | ||
ImageEdit, | ||
ImageVariation | ||
Which intent is this query asking for? If none match, respond with Unknown. | ||
{{message}} | ||
Intent: | ||
""") | ||
]; | ||
|
||
string answer = await _openAIClient.ChatAsync( | ||
model: "gpt-3.5-turbo", | ||
messages: messages, | ||
maxTokens: 128, | ||
cancellationToken: cancellationToken | ||
); | ||
|
||
return answer switch { | ||
"Vision" => ImagePromptIntent.Vision, | ||
"ImageEdit" => ImagePromptIntent.ImageEdit, | ||
"ImageVariation" => ImagePromptIntent.ImageVariation, | ||
"Unknown" => ImagePromptIntent.Vision, | ||
_ => ImagePromptIntent.Vision | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace BotNet.Services.OpenAI.Models { | ||
public enum ChatIntent { | ||
Question, | ||
ImageGeneration | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace BotNet.Services.OpenAI.Models { | ||
public enum ImagePromptIntent { | ||
Vision, | ||
ImageEdit, | ||
ImageVariation | ||
|
||
// TODO: OCR, VisualSearch, ImageCaptioning, ImageOutpainting | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.