disable group config
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-03-15 20:52:32 +03:00
parent 2dc7f11e4e
commit d8f2c623a9
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6

View File

@ -1,72 +1,72 @@
package dev.struchkov.example.bot.unit; //package dev.struchkov.example.bot.unit;
//
import dev.struchkov.example.bot.util.Cmd; //import dev.struchkov.example.bot.util.Cmd;
import dev.struchkov.example.bot.util.UnitName; //import dev.struchkov.example.bot.util.UnitName;
import dev.struchkov.godfather.main.domain.annotation.Unit; //import dev.struchkov.godfather.main.domain.annotation.Unit;
import dev.struchkov.godfather.main.domain.content.Attachment; //import dev.struchkov.godfather.main.domain.content.Attachment;
import dev.struchkov.godfather.main.domain.content.ChatMail; //import dev.struchkov.godfather.main.domain.content.ChatMail;
import dev.struchkov.godfather.simple.domain.BoxAnswer; //import dev.struchkov.godfather.simple.domain.BoxAnswer;
import dev.struchkov.godfather.simple.domain.unit.AnswerText; //import dev.struchkov.godfather.simple.domain.unit.AnswerText;
import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment; //import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment;
import dev.struchkov.godfather.telegram.main.core.util.Attachments; //import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.starter.ChatUnitConfiguration; //import dev.struchkov.godfather.telegram.starter.ChatUnitConfiguration;
import dev.struchkov.openai.context.GPTClient; //import dev.struchkov.openai.context.GPTClient;
import dev.struchkov.openai.domain.common.GptMessage; //import dev.struchkov.openai.domain.common.GptMessage;
import dev.struchkov.openai.domain.model.gpt.GPT3Model; //import dev.struchkov.openai.domain.model.gpt.GPT3Model;
import dev.struchkov.openai.domain.request.GptRequest; //import dev.struchkov.openai.domain.request.GptRequest;
import dev.struchkov.openai.domain.response.Choice; //import dev.struchkov.openai.domain.response.Choice;
import dev.struchkov.openai.domain.response.GptResponse; //import dev.struchkov.openai.domain.response.GptResponse;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
//
import java.util.List; //import java.util.List;
import java.util.Optional; //import java.util.Optional;
//
import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; //import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer;
//
@Component //@Component
public class GroupChatGPTUnit implements ChatUnitConfiguration { //public class GroupChatGPTUnit implements ChatUnitConfiguration {
//
private final GPTClient gptClient; // private final GPTClient gptClient;
//
public GroupChatGPTUnit( // public GroupChatGPTUnit(
GPTClient gptClient // GPTClient gptClient
) { // ) {
this.gptClient = gptClient; // this.gptClient = gptClient;
} // }
//
@Unit(value = UnitName.PROMPT, main = true) // @Unit(value = UnitName.PROMPT, main = true)
public AnswerText<ChatMail> prompt() { // public AnswerText<ChatMail> prompt() {
return AnswerText.<ChatMail>builder() // return AnswerText.<ChatMail>builder()
.triggerCheck( // .triggerCheck(
mail -> { // mail -> {
final List<Attachment> attachments = mail.getAttachments(); // final List<Attachment> attachments = mail.getAttachments();
final Optional<CommandAttachment> optCommand = Attachments.findFirstCommand(attachments); // final Optional<CommandAttachment> optCommand = Attachments.findFirstCommand(attachments);
if (optCommand.isPresent()) { // if (optCommand.isPresent()) {
final CommandAttachment command = optCommand.get(); // final CommandAttachment command = optCommand.get();
return Cmd.GPT.equals(command.getCommandType()); // return Cmd.GPT.equals(command.getCommandType());
} // }
return false; // return false;
} // }
) // )
.answer( // .answer(
mail -> { // mail -> {
final CommandAttachment promptCommand = Attachments.findFirstCommand(mail.getAttachments()).get(); // final CommandAttachment promptCommand = Attachments.findFirstCommand(mail.getAttachments()).get();
final Optional<String> optPrompt = promptCommand.getArg(); // final Optional<String> optPrompt = promptCommand.getArg();
if (optPrompt.isPresent()) { // if (optPrompt.isPresent()) {
final String prompt = optPrompt.get(); // final String prompt = optPrompt.get();
final GptResponse gptResponse = gptClient.execute( // final GptResponse gptResponse = gptClient.execute(
GptRequest.builder() // GptRequest.builder()
.model(GPT3Model.GPT_3_5_TURBO) // .model(GPT3Model.GPT_3_5_TURBO)
.message(GptMessage.fromUser(prompt)) // .message(GptMessage.fromUser(prompt))
.build() // .build()
); // );
final List<Choice> choices = gptResponse.getChoices(); // final List<Choice> choices = gptResponse.getChoices();
return boxAnswer(choices.get(choices.size() - 1).getMessage().getContent()); // return boxAnswer(choices.get(choices.size() - 1).getMessage().getContent());
} // }
return BoxAnswer.builder().build(); // return BoxAnswer.builder().build();
} // }
) // )
.build(); // .build();
} // }
//
} //}