Skip to content

Commit 3f73505

Browse files
committed
title generation by ChatGPT for transfer-questions command
refactoring reviewer comments addressed prompt improved
1 parent 6c3cc81 commit 3f73505

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

application/src/main/java/org/togetherjava/tjbot/features/Features.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
133133
features.add(new HelpThreadCreatedListener(helpSystemHelper));
134134

135135
// Message context commands
136-
features.add(new TransferQuestionCommand(config));
136+
features.add(new TransferQuestionCommand(config, chatGptService));
137137

138138
// User context commands
139139

application/src/main/java/org/togetherjava/tjbot/features/moderation/TransferQuestionCommand.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.togetherjava.tjbot.features.BotCommandAdapter;
3333
import org.togetherjava.tjbot.features.CommandVisibility;
3434
import org.togetherjava.tjbot.features.MessageContextCommand;
35+
import org.togetherjava.tjbot.features.chatgpt.ChatGptService;
3536
import org.togetherjava.tjbot.features.utils.StringDistances;
3637

3738
import java.awt.Color;
@@ -64,20 +65,23 @@ public final class TransferQuestionCommand extends BotCommandAdapter
6465
private static final int INPUT_MIN_LENGTH = 3;
6566
private final Predicate<String> isHelpForumName;
6667
private final List<String> tags;
68+
private final ChatGptService chatGptService;
6769

6870

6971
/**
7072
* Creates a new instance.
7173
*
7274
* @param config to get the helper forum and tags
75+
* @param chatGptService the service used to ask ChatGPT questions via the API.
7376
*/
74-
public TransferQuestionCommand(Config config) {
77+
public TransferQuestionCommand(Config config, ChatGptService chatGptService) {
7578
super(Commands.message(COMMAND_NAME), CommandVisibility.GUILD);
7679

7780
isHelpForumName =
7881
Pattern.compile(config.getHelpSystem().getHelpForumPattern()).asMatchPredicate();
7982

8083
tags = config.getHelpSystem().getCategories();
84+
this.chatGptService = chatGptService;
8185
}
8286

8387
@Override
@@ -92,12 +96,18 @@ public void onMessageContext(MessageContextInteractionEvent event) {
9296
String originalChannelId = event.getTarget().getChannel().getId();
9397
String authorId = event.getTarget().getAuthor().getId();
9498
String mostCommonTag = tags.get(0);
99+
String chatGptPrompt = String.format(
100+
"Generate topic for question: %s. Minimum %s and maximum %s characters.",
101+
originalMessage, TITLE_MIN_LENGTH, TITLE_MAX_LENGTH);
102+
Optional<String> chatGptResponse =
103+
chatGptService.ask(chatGptPrompt, String.join(",", tags));
104+
String title = chatGptResponse.orElse(createTitle(originalMessage));
95105

96106
TextInput modalTitle = TextInput.create(MODAL_TITLE_ID, "Title", TextInputStyle.SHORT)
97107
.setMaxLength(TITLE_MAX_LENGTH)
98108
.setMinLength(TITLE_MIN_LENGTH)
99109
.setPlaceholder("Describe the question in short")
100-
.setValue(createTitle(originalMessage))
110+
.setValue(title)
101111
.build();
102112

103113
Builder modalInputBuilder =

0 commit comments

Comments
 (0)