Skip to content

Commit 10cc87f

Browse files
committed
feat: add a chat model parameter to allow choice between models (speed vs quality)
1 parent fe1cae9 commit 10cc87f

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

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

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

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

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

85-
Optional<String> chatgptResponse =
86-
chatGptService.ask(question, "You may use markdown syntax for the response");
86+
Optional<String> chatgptResponse = chatGptService.ask(question,
87+
"You may use markdown syntax for the response", ChatModel.GPT_5_MINI);
8788
if (chatgptResponse.isPresent()) {
8889
userIdToAskedAtCache.put(event.getMember().getId(), Instant.now());
8990
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ public ChatGptService(Config config) {
5151
* @param question The question being asked of ChatGPT. Max is {@value MAX_TOKENS} tokens.
5252
* @param context The category of asked question, to set the context(eg. Java, Database, Other
5353
* etc).
54+
* @param chatModel The AI model to use for this request.
5455
* @return response from ChatGPT as a String.
5556
* @see <a href="https://platform.openai.com/docs/guides/chat/managing-tokens">ChatGPT
5657
* Tokens</a>.
5758
*/
58-
public Optional<String> ask(String question, @Nullable String context) {
59+
public Optional<String> ask(String question, @Nullable String context, ChatModel chatModel) {
5960
if (isDisabled) {
6061
return Optional.empty();
6162
}
@@ -76,7 +77,7 @@ public Optional<String> ask(String question, @Nullable String context) {
7677
String response = null;
7778
try {
7879
ResponseCreateParams params = ResponseCreateParams.builder()
79-
.model(ChatModel.GPT_5_MINI)
80+
.model(chatModel)
8081
.input(inputPrompt)
8182
.maxOutputTokens(MAX_TOKENS)
8283
.build();

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

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

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

148149
if (chatGptAnswer.isEmpty()) {
149150
return useChatGptFallbackMessage(threadChannel);

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

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

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

0 commit comments

Comments
 (0)