Skip to content

Commit 0763cbe

Browse files
committed
feat: create an enum to house the AI models
1 parent 10cc87f commit 0763cbe

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.github.benmanes.caffeine.cache.Cache;
44
import com.github.benmanes.caffeine.cache.Caffeine;
5-
import com.openai.models.ChatModel;
65
import net.dv8tion.jda.api.entities.MessageEmbed;
76
import net.dv8tion.jda.api.entities.SelfUser;
87
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
@@ -84,7 +83,7 @@ public void onModalSubmitted(ModalInteractionEvent event, List<String> args) {
8483
String question = event.getValue(QUESTION_INPUT).getAsString();
8584

8685
Optional<String> chatgptResponse = chatGptService.ask(question,
87-
"You may use markdown syntax for the response", ChatModel.GPT_5_MINI);
86+
"You may use markdown syntax for the response", ChatGptModel.HIGH_QUALITY);
8887
if (chatgptResponse.isPresent()) {
8988
userIdToAskedAtCache.put(event.getMember().getId(), Instant.now());
9089
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.togetherjava.tjbot.features.chatgpt;
2+
3+
import com.openai.models.ChatModel;
4+
5+
/**
6+
* Logical abstraction over OpenAI chat models.
7+
* <p>
8+
* This enum allows the application to select models based on performance/quality intent rather than
9+
* hard-coding specific OpenAI model versions throughout the codebase.
10+
*
11+
*/
12+
public enum ChatGptModel {
13+
/**
14+
* Fastest response time with the lowest computational cost.
15+
*/
16+
FASTEST(ChatModel.GPT_3_5_TURBO),
17+
18+
/**
19+
* Balanced option between speed and quality.
20+
*/
21+
FAST(ChatModel.GPT_4_1_MINI),
22+
23+
/**
24+
* Highest quality responses with increased reasoning capability.
25+
*/
26+
HIGH_QUALITY(ChatModel.GPT_5_MINI);
27+
28+
private final ChatModel chatModel;
29+
30+
ChatGptModel(ChatModel chatModel) {
31+
this.chatModel = chatModel;
32+
}
33+
34+
public ChatModel toChatModel() {
35+
return chatModel;
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return chatModel.toString();
41+
}
42+
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.openai.client.OpenAIClient;
44
import com.openai.client.okhttp.OpenAIOkHttpClient;
5-
import com.openai.models.ChatModel;
65
import com.openai.models.responses.Response;
76
import com.openai.models.responses.ResponseCreateParams;
87
import com.openai.models.responses.ResponseOutputText;
@@ -56,7 +55,7 @@ public ChatGptService(Config config) {
5655
* @see <a href="https://platform.openai.com/docs/guides/chat/managing-tokens">ChatGPT
5756
* Tokens</a>.
5857
*/
59-
public Optional<String> ask(String question, @Nullable String context, ChatModel chatModel) {
58+
public Optional<String> ask(String question, @Nullable String context, ChatGptModel chatModel) {
6059
if (isDisabled) {
6160
return Optional.empty();
6261
}
@@ -77,7 +76,7 @@ public Optional<String> ask(String question, @Nullable String context, ChatModel
7776
String response = null;
7877
try {
7978
ResponseCreateParams params = ResponseCreateParams.builder()
80-
.model(chatModel)
79+
.model(chatModel.toChatModel())
8180
.input(inputPrompt)
8281
.maxOutputTokens(MAX_TOKENS)
8382
.build();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.togetherjava.tjbot.features.help;
22

3-
import com.openai.models.ChatModel;
43
import net.dv8tion.jda.api.EmbedBuilder;
54
import net.dv8tion.jda.api.entities.Guild;
65
import net.dv8tion.jda.api.entities.Member;
@@ -26,6 +25,7 @@
2625
import org.togetherjava.tjbot.db.generated.tables.HelpThreads;
2726
import org.togetherjava.tjbot.db.generated.tables.records.HelpThreadsRecord;
2827
import org.togetherjava.tjbot.features.chatgpt.ChatGptCommand;
28+
import org.togetherjava.tjbot.features.chatgpt.ChatGptModel;
2929
import org.togetherjava.tjbot.features.chatgpt.ChatGptService;
3030
import org.togetherjava.tjbot.features.componentids.ComponentIdInteractor;
3131
import org.togetherjava.tjbot.features.utils.Guilds;
@@ -144,7 +144,7 @@ RestAction<Message> constructChatGptAttempt(ThreadChannel threadChannel,
144144
String context =
145145
"Category %s on a Java Q&A discord server. You may use markdown syntax for the response"
146146
.formatted(matchingTag.getName());
147-
chatGptAnswer = chatGptService.ask(question, context, ChatModel.GPT_3_5_TURBO);
147+
chatGptAnswer = chatGptService.ask(question, context, ChatGptModel.FAST);
148148

149149
if (chatGptAnswer.isEmpty()) {
150150
return useChatGptFallbackMessage(threadChannel);

application/src/main/java/org/togetherjava/tjbot/features/moderation/TransferQuestionCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.togetherjava.tjbot.features.moderation;
22

3-
import com.openai.models.ChatModel;
43
import net.dv8tion.jda.api.EmbedBuilder;
54
import net.dv8tion.jda.api.JDA;
65
import net.dv8tion.jda.api.entities.Guild;
@@ -32,6 +31,7 @@
3231
import org.togetherjava.tjbot.features.BotCommandAdapter;
3332
import org.togetherjava.tjbot.features.CommandVisibility;
3433
import org.togetherjava.tjbot.features.MessageContextCommand;
34+
import org.togetherjava.tjbot.features.chatgpt.ChatGptModel;
3535
import org.togetherjava.tjbot.features.chatgpt.ChatGptService;
3636
import org.togetherjava.tjbot.features.utils.StringDistances;
3737

@@ -100,7 +100,7 @@ public void onMessageContext(MessageContextInteractionEvent event) {
100100
"Summarize the following question into a concise title or heading not more than 5 words, remove quotations if any: %s"
101101
.formatted(originalMessage);
102102
Optional<String> chatGptTitle =
103-
chatGptService.ask(chatGptTitleRequest, null, ChatModel.GPT_3_5_TURBO);
103+
chatGptService.ask(chatGptTitleRequest, null, ChatGptModel.FASTEST);
104104
String title = chatGptTitle.orElse(createTitle(originalMessage));
105105
if (title.startsWith("\"") && title.endsWith("\"")) {
106106
title = title.substring(1, title.length() - 1);

0 commit comments

Comments
 (0)