Skip to content

Commit e9a7f32

Browse files
authored
Fixed some ChatGPT issues (#888)
* url must not be fake * fixed chatgpt disabling * chatgpt logs too much * answer-attempt should be after explanation messages
1 parent 92e36aa commit e9a7f32

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

application/config.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"logInfoChannelWebhook": "<put_your_webhook_here>",
9090
"logErrorChannelWebhook": "<put_your_webhook_here>",
9191
"openaiApiKey": "<check pins in #tjbot_discussion for the key>",
92-
"sourceCodeBaseUrl": "<https://github.com/<your_account_here>/<your_repo_here>/blob/master/application/src/main/java/>",
92+
"sourceCodeBaseUrl": "https://github.com/Together-Java/TJ-Bot/blob/master/application/src/main/java/",
9393
"jshell": {
9494
"baseUrl": "<put_jshell_rest_api_url_here>",
9595
"rateLimitWindowSeconds": 10,

application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public class ChatGptService {
2323
private static final Duration TIMEOUT = Duration.ofSeconds(90);
2424
private static final int MAX_TOKENS = 3_000;
2525
private static final String AI_MODEL = "gpt-3.5-turbo";
26+
2627
private boolean isDisabled = false;
27-
private final OpenAiService openAiService;
28+
private OpenAiService openAiService;
2829

2930
/**
3031
* Creates instance of ChatGPTService
@@ -33,8 +34,10 @@ public class ChatGptService {
3334
*/
3435
public ChatGptService(Config config) {
3536
String apiKey = config.getOpenaiApiKey();
36-
if (apiKey.isBlank()) {
37+
boolean keyIsDefaultDescription = apiKey.startsWith("<") && apiKey.endsWith(">");
38+
if (apiKey.isBlank() || keyIsDefaultDescription) {
3739
isDisabled = true;
40+
return;
3841
}
3942

4043
openAiService = new OpenAiService(apiKey, TIMEOUT);

application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ RestAction<Message> constructChatGptAttempt(ThreadChannel threadChannel,
170170
}
171171
String question = questionOptional.get();
172172
logger.debug("The final question sent to chatGPT: {}", question);
173-
logger.info("The final question sent to chatGPT: {}", question);
174173

175174
chatGPTAnswer = chatGptService.ask(question);
176175
if (chatGPTAnswer.isEmpty()) {
@@ -226,7 +225,6 @@ private Optional<String> prepareChatGptQuestion(ThreadChannel threadChannel,
226225
}
227226

228227
private RestAction<Message> useChatGptFallbackMessage(ThreadChannel threadChannel) {
229-
logger.warn("Something went wrong while trying to communicate with the ChatGpt API");
230228
return mentionGuildSlashCommand(threadChannel.getGuild(), ChatGptCommand.COMMAND_NAME)
231229
.map(CHATGPT_FAILURE_MESSAGE::formatted)
232230
.flatMap(threadChannel::sendMessage);

application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ private void handleHelpThreadCreated(ThreadChannel threadChannel) {
7777
Runnable createMessages = () -> {
7878
try {
7979
createMessages(threadChannel).queue();
80-
createAIResponse(threadChannel).queue();
8180
} catch (Exception e) {
8281
logger.error(
8382
"Unknown error while creating messages after help-thread ({}) creation",
@@ -100,7 +99,8 @@ private RestAction<Message> createAIResponse(ThreadChannel threadChannel) {
10099

101100
private RestAction<Message> createMessages(ThreadChannel threadChannel) {
102101
return sendHelperHeadsUp(threadChannel).flatMap(Message::pin)
103-
.flatMap(any -> helper.sendExplanationMessage(threadChannel));
102+
.flatMap(any -> helper.sendExplanationMessage(threadChannel))
103+
.flatMap(any -> createAIResponse(threadChannel));
104104
}
105105

106106
private RestAction<Message> sendHelperHeadsUp(ThreadChannel threadChannel) {

0 commit comments

Comments
 (0)