|
1 | 1 | package org.example.project.service; |
2 | 2 |
|
| 3 | +import com.plexpt.chatgpt.entity.chat.ChatCompletion; |
3 | 4 | import lombok.extern.slf4j.Slf4j; |
4 | 5 | import org.example.project.configuration.ApplicationConfig; |
5 | 6 | import org.example.project.domain.Users; |
@@ -41,6 +42,8 @@ public class TelegramBot extends TelegramLongPollingBot { |
41 | 42 |
|
42 | 43 | private DialogMode dialogMode; |
43 | 44 |
|
| 45 | + private String gptVersion = ""; |
| 46 | + |
44 | 47 | static final String HELP_TEXT = "This bot is created by Demyan Zverev and for his own purpose\n\n" + |
45 | 48 | "You can execute from the main menu on the left or by typing command: \n\n" + |
46 | 49 | "Type /start to see a welcome message\n\n" + |
@@ -76,6 +79,7 @@ public void onUpdateReceived(Update update) { |
76 | 79 | String messageText = update.getMessage().getText(); |
77 | 80 | long chatId = update.getMessage().getChatId(); |
78 | 81 |
|
| 82 | + |
79 | 83 | switch(dialogMode) { |
80 | 84 | case MAIN: |
81 | 85 | switch (messageText) { |
@@ -114,25 +118,50 @@ public void onUpdateReceived(Update update) { |
114 | 118 | case WAIT_DEPARTURE_PLACE: |
115 | 119 | sendBusSchedule(chatId, messageText); |
116 | 120 | break; |
| 121 | + case WAIT_GPT_VERSION: |
| 122 | + gptVersion = gptVersionReceived(chatId, messageText); |
| 123 | + break; |
117 | 124 | case WAIT_QUESTION: |
118 | | - questionToGptReceived(chatId, messageText); |
| 125 | + questionToGptReceived(chatId, messageText, gptVersion); |
119 | 126 | break; |
120 | 127 | } |
121 | 128 | } |
122 | 129 | } |
123 | 130 |
|
124 | 131 | // TODO: Изменить взаимодействие с ChatGPT в боте |
125 | | - private void questionToGptReceived(long chatId, String question) { |
| 132 | + private void questionToGptReceived(long chatId, String question, String model) { |
126 | 133 | log.info("Send message to ChatGPT"); |
127 | | - String answer = chatGPTService.sendMessage("", question); |
| 134 | + String answer = chatGPTService.sendMessage("", question, model); |
128 | 135 | sendMessage(chatId, answer); |
129 | 136 | dialogMode = DialogMode.MAIN; |
130 | 137 | } |
131 | 138 |
|
132 | 139 | private void gptReceived(long chatId) { |
| 140 | + String answer = """ |
| 141 | + Choose version of ChatGPT: |
| 142 | + 1) GPT 3.5 Turbo |
| 143 | + 2) GPT 4 |
| 144 | + 3) GPT 4o mini |
| 145 | + 4) GPT 4o |
| 146 | + Print only digit"""; |
| 147 | + sendMessage(chatId, answer); |
| 148 | + dialogMode = DialogMode.WAIT_GPT_VERSION; |
| 149 | + } |
| 150 | + |
| 151 | + private String gptVersionReceived(long chatId, String gptVersion) { |
133 | 152 | String answer = "Write your question:"; |
134 | 153 | sendMessage(chatId, answer); |
135 | 154 | dialogMode = DialogMode.WAIT_QUESTION; |
| 155 | + return whichGptVersion(gptVersion); |
| 156 | + } |
| 157 | + |
| 158 | + private String whichGptVersion(String version) { |
| 159 | + return switch (version) { |
| 160 | + case "2" -> ChatCompletion.Model.GPT4; |
| 161 | + case "3" -> ChatCompletion.Model.GPT4oMini; |
| 162 | + case "4" -> ChatCompletion.Model.GPT4o; |
| 163 | + default -> ChatCompletion.Model.GPT_3_5_TURBO; |
| 164 | + }; |
136 | 165 | } |
137 | 166 |
|
138 | 167 | private void getIP(long chatId) { |
|
0 commit comments