Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion application/config.json.template
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"logInfoChannelWebhook": "<put_your_webhook_here>",
"logErrorChannelWebhook": "<put_your_webhook_here>",
"openaiApiKey": "<check pins in #tjbot_discussion for the key>",
"sourceCodeBaseUrl": "<https://github.com/<your_account_here>/<your_repo_here>/blob/master/application/src/main/java/>",
"sourceCodeBaseUrl": "https://github.com/Together-Java/TJ-Bot/blob/master/application/src/main/java/",
"jshell": {
"baseUrl": "<put_jshell_rest_api_url_here>",
"rateLimitWindowSeconds": 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ RestAction<Message> 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()) {
Expand Down Expand Up @@ -226,7 +225,6 @@ private Optional<String> prepareChatGptQuestion(ThreadChannel threadChannel,
}

private RestAction<Message> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -100,7 +99,8 @@ private RestAction<Message> createAIResponse(ThreadChannel threadChannel) {

private RestAction<Message> 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<Message> sendHelperHeadsUp(ThreadChannel threadChannel) {
Expand Down