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,20 @@ 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 =
100+ "Summarize the following text into a concise title or heading not more than 4-5 words, remove quotations if any: %s"
101+ .formatted (originalMessage );
102+ Optional <String > chatGptResponse = chatGptService .ask (chatGptPrompt , "" );
103+ String title = chatGptResponse .orElse (createTitle (originalMessage ));
104+ if (title .length () > TITLE_MAX_LENGTH ) {
105+ title = title .substring (0 , TITLE_MAX_LENGTH );
106+ }
95107
96108 TextInput modalTitle = TextInput .create (MODAL_TITLE_ID , "Title" , TextInputStyle .SHORT )
97109 .setMaxLength (TITLE_MAX_LENGTH )
98110 .setMinLength (TITLE_MIN_LENGTH )
99111 .setPlaceholder ("Describe the question in short" )
100- .setValue (createTitle ( originalMessage ) )
112+ .setValue (title )
101113 .build ();
102114
103115 Builder modalInputBuilder =
0 commit comments