Skip to content
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 @@ -133,7 +133,7 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
features.add(new HelpThreadCreatedListener(helpSystemHelper));

// Message context commands
features.add(new TransferQuestionCommand(config));
features.add(new TransferQuestionCommand(config, chatGptService));

// User context commands

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.togetherjava.tjbot.features.BotCommandAdapter;
import org.togetherjava.tjbot.features.CommandVisibility;
import org.togetherjava.tjbot.features.MessageContextCommand;
import org.togetherjava.tjbot.features.chatgpt.ChatGptService;
import org.togetherjava.tjbot.features.utils.StringDistances;

import java.awt.Color;
Expand Down Expand Up @@ -64,20 +65,23 @@ public final class TransferQuestionCommand extends BotCommandAdapter
private static final int INPUT_MIN_LENGTH = 3;
private final Predicate<String> isHelpForumName;
private final List<String> tags;
private final ChatGptService chatGptService;


/**
* Creates a new instance.
*
* @param config to get the helper forum and tags
* @param chatGptService the service used to ask ChatGPT questions via the API.
*/
public TransferQuestionCommand(Config config) {
public TransferQuestionCommand(Config config, ChatGptService chatGptService) {
Comment thread
ankitsmt211 marked this conversation as resolved.
super(Commands.message(COMMAND_NAME), CommandVisibility.GUILD);

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

tags = config.getHelpSystem().getCategories();
this.chatGptService = chatGptService;
}

@Override
Expand All @@ -92,12 +96,20 @@ public void onMessageContext(MessageContextInteractionEvent event) {
String originalChannelId = event.getTarget().getChannel().getId();
String authorId = event.getTarget().getAuthor().getId();
String mostCommonTag = tags.get(0);
String chatGptPrompt =
"Summarize the following text into a concise title or heading not more than 4-5 words, remove quotations if any: %s"
.formatted(originalMessage);
Optional<String> chatGptResponse = chatGptService.ask(chatGptPrompt, "");
Comment thread
ankitsmt211 marked this conversation as resolved.
String title = chatGptResponse.orElse(createTitle(originalMessage));
if (title.length() > TITLE_MAX_LENGTH) {
title = title.substring(0, TITLE_MAX_LENGTH);
}

TextInput modalTitle = TextInput.create(MODAL_TITLE_ID, "Title", TextInputStyle.SHORT)
.setMaxLength(TITLE_MAX_LENGTH)
.setMinLength(TITLE_MIN_LENGTH)
.setPlaceholder("Describe the question in short")
.setValue(createTitle(originalMessage))
.setValue(title)
.build();

Builder modalInputBuilder =
Expand Down