diff --git a/application/config.json.template b/application/config.json.template index 0ce8d2c59d..80585e39b4 100644 --- a/application/config.json.template +++ b/application/config.json.template @@ -89,7 +89,7 @@ "logInfoChannelWebhook": "", "logErrorChannelWebhook": "", "openaiApiKey": "", - "sourceCodeBaseUrl": "//blob/master/application/src/main/java/>", + "sourceCodeBaseUrl": "https://github.com/Together-Java/TJ-Bot/blob/master/application/src/main/java/", "jshell": { "baseUrl": "", "rateLimitWindowSeconds": 10, diff --git a/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptService.java b/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptService.java index 11f057e296..24cf088852 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptService.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/chatgpt/ChatGptService.java @@ -23,8 +23,9 @@ public class ChatGptService { private static final Duration TIMEOUT = Duration.ofSeconds(90); private static final int MAX_TOKENS = 3_000; private static final String AI_MODEL = "gpt-3.5-turbo"; + private boolean isDisabled = false; - private final OpenAiService openAiService; + private OpenAiService openAiService; /** * Creates instance of ChatGPTService @@ -33,8 +34,10 @@ public class ChatGptService { */ public ChatGptService(Config config) { String apiKey = config.getOpenaiApiKey(); - if (apiKey.isBlank()) { + boolean keyIsDefaultDescription = apiKey.startsWith("<") && apiKey.endsWith(">"); + if (apiKey.isBlank() || keyIsDefaultDescription) { isDisabled = true; + return; } openAiService = new OpenAiService(apiKey, TIMEOUT); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java index 1fa5dcaf7c..8604ac631b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpSystemHelper.java @@ -170,7 +170,6 @@ RestAction constructChatGptAttempt(ThreadChannel threadChannel, } String question = questionOptional.get(); logger.debug("The final question sent to chatGPT: {}", question); - logger.info("The final question sent to chatGPT: {}", question); chatGPTAnswer = chatGptService.ask(question); if (chatGPTAnswer.isEmpty()) { @@ -226,7 +225,6 @@ private Optional prepareChatGptQuestion(ThreadChannel threadChannel, } private RestAction useChatGptFallbackMessage(ThreadChannel threadChannel) { - logger.warn("Something went wrong while trying to communicate with the ChatGpt API"); return mentionGuildSlashCommand(threadChannel.getGuild(), ChatGptCommand.COMMAND_NAME) .map(CHATGPT_FAILURE_MESSAGE::formatted) .flatMap(threadChannel::sendMessage); diff --git a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java index b38d35fcc1..6bbf80eff7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/help/HelpThreadCreatedListener.java @@ -77,7 +77,6 @@ private void handleHelpThreadCreated(ThreadChannel threadChannel) { Runnable createMessages = () -> { try { createMessages(threadChannel).queue(); - createAIResponse(threadChannel).queue(); } catch (Exception e) { logger.error( "Unknown error while creating messages after help-thread ({}) creation", @@ -100,7 +99,8 @@ private RestAction createAIResponse(ThreadChannel threadChannel) { private RestAction createMessages(ThreadChannel threadChannel) { return sendHelperHeadsUp(threadChannel).flatMap(Message::pin) - .flatMap(any -> helper.sendExplanationMessage(threadChannel)); + .flatMap(any -> helper.sendExplanationMessage(threadChannel)) + .flatMap(any -> createAIResponse(threadChannel)); } private RestAction sendHelperHeadsUp(ThreadChannel threadChannel) {