Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.openai.models.ChatModel;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.SelfUser;
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
Expand Down Expand Up @@ -82,8 +83,8 @@ public void onModalSubmitted(ModalInteractionEvent event, List<String> args) {

String question = event.getValue(QUESTION_INPUT).getAsString();

Optional<String> chatgptResponse =
chatGptService.ask(question, "You may use markdown syntax for the response");
Optional<String> chatgptResponse = chatGptService.ask(question,
"You may use markdown syntax for the response", ChatModel.GPT_5_MINI);
if (chatgptResponse.isPresent()) {
userIdToAskedAtCache.put(event.getMember().getId(), Instant.now());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public ChatGptService(Config config) {
* @param question The question being asked of ChatGPT. Max is {@value MAX_TOKENS} tokens.
* @param context The category of asked question, to set the context(eg. Java, Database, Other
* etc).
* @param chatModel The AI model to use for this request.
* @return response from ChatGPT as a String.
* @see <a href="https://platform.openai.com/docs/guides/chat/managing-tokens">ChatGPT
* Tokens</a>.
*/
public Optional<String> ask(String question, @Nullable String context) {
public Optional<String> ask(String question, @Nullable String context, ChatModel chatModel) {
if (isDisabled) {
return Optional.empty();
}
Expand All @@ -76,7 +77,7 @@ public Optional<String> ask(String question, @Nullable String context) {
String response = null;
try {
ResponseCreateParams params = ResponseCreateParams.builder()
.model(ChatModel.GPT_5_NANO)
.model(chatModel)
.input(inputPrompt)
.maxOutputTokens(MAX_TOKENS)
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.togetherjava.tjbot.features.help;

import com.openai.models.ChatModel;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
Expand Down Expand Up @@ -143,7 +144,7 @@ RestAction<Message> constructChatGptAttempt(ThreadChannel threadChannel,
String context =
"Category %s on a Java Q&A discord server. You may use markdown syntax for the response"
.formatted(matchingTag.getName());
chatGptAnswer = chatGptService.ask(question, context);
chatGptAnswer = chatGptService.ask(question, context, ChatModel.GPT_3_5_TURBO);

if (chatGptAnswer.isEmpty()) {
return useChatGptFallbackMessage(threadChannel);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.togetherjava.tjbot.features.moderation;

import com.openai.models.ChatModel;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.Guild;
Expand Down Expand Up @@ -98,7 +99,8 @@ public void onMessageContext(MessageContextInteractionEvent event) {
String chatGptTitleRequest =
"Summarize the following question into a concise title or heading not more than 5 words, remove quotations if any: %s"
.formatted(originalMessage);
Optional<String> chatGptTitle = chatGptService.ask(chatGptTitleRequest, null);
Optional<String> chatGptTitle =
chatGptService.ask(chatGptTitleRequest, null, ChatModel.GPT_3_5_TURBO);
String title = chatGptTitle.orElse(createTitle(originalMessage));
if (title.startsWith("\"") && title.endsWith("\"")) {
title = title.substring(1, title.length() - 1);
Expand Down
Loading