3232import org .togetherjava .tjbot .features .BotCommandAdapter ;
3333import org .togetherjava .tjbot .features .CommandVisibility ;
3434import org .togetherjava .tjbot .features .MessageContextCommand ;
35+ import org .togetherjava .tjbot .features .chatgpt .ChatGptService ;
3536import org .togetherjava .tjbot .features .utils .StringDistances ;
3637
3738import 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