32
32
import org .togetherjava .tjbot .features .BotCommandAdapter ;
33
33
import org .togetherjava .tjbot .features .CommandVisibility ;
34
34
import org .togetherjava .tjbot .features .MessageContextCommand ;
35
+ import org .togetherjava .tjbot .features .chatgpt .ChatGptService ;
35
36
import org .togetherjava .tjbot .features .utils .StringDistances ;
36
37
37
38
import java .awt .Color ;
@@ -64,20 +65,23 @@ public final class TransferQuestionCommand extends BotCommandAdapter
64
65
private static final int INPUT_MIN_LENGTH = 3 ;
65
66
private final Predicate <String > isHelpForumName ;
66
67
private final List <String > tags ;
68
+ private final ChatGptService chatGptService ;
67
69
68
70
69
71
/**
70
72
* Creates a new instance.
71
73
*
72
74
* @param config to get the helper forum and tags
75
+ * @param chatGptService the service used to ask ChatGPT questions via the API.
73
76
*/
74
- public TransferQuestionCommand (Config config ) {
77
+ public TransferQuestionCommand (Config config , ChatGptService chatGptService ) {
75
78
super (Commands .message (COMMAND_NAME ), CommandVisibility .GUILD );
76
79
77
80
isHelpForumName =
78
81
Pattern .compile (config .getHelpSystem ().getHelpForumPattern ()).asMatchPredicate ();
79
82
80
83
tags = config .getHelpSystem ().getCategories ();
84
+ this .chatGptService = chatGptService ;
81
85
}
82
86
83
87
@ Override
@@ -92,12 +96,20 @@ public void onMessageContext(MessageContextInteractionEvent event) {
92
96
String originalChannelId = event .getTarget ().getChannel ().getId ();
93
97
String authorId = event .getTarget ().getAuthor ().getId ();
94
98
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
+ }
95
107
96
108
TextInput modalTitle = TextInput .create (MODAL_TITLE_ID , "Title" , TextInputStyle .SHORT )
97
109
.setMaxLength (TITLE_MAX_LENGTH )
98
110
.setMinLength (TITLE_MIN_LENGTH )
99
111
.setPlaceholder ("Describe the question in short" )
100
- .setValue (createTitle ( originalMessage ) )
112
+ .setValue (title )
101
113
.build ();
102
114
103
115
Builder modalInputBuilder =
0 commit comments