From d8f2c623a98f4170b5ad62fc45cc10cd2d62f919 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Wed, 15 Mar 2023 20:52:32 +0300 Subject: [PATCH] disable group config --- .../example/bot/unit/GroupChatGPTUnit.java | 144 +++++++++--------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/src/main/java/dev/struchkov/example/bot/unit/GroupChatGPTUnit.java b/src/main/java/dev/struchkov/example/bot/unit/GroupChatGPTUnit.java index 8cbe2a9..7d1cd09 100644 --- a/src/main/java/dev/struchkov/example/bot/unit/GroupChatGPTUnit.java +++ b/src/main/java/dev/struchkov/example/bot/unit/GroupChatGPTUnit.java @@ -1,72 +1,72 @@ -package dev.struchkov.example.bot.unit; - -import dev.struchkov.example.bot.util.Cmd; -import dev.struchkov.example.bot.util.UnitName; -import dev.struchkov.godfather.main.domain.annotation.Unit; -import dev.struchkov.godfather.main.domain.content.Attachment; -import dev.struchkov.godfather.main.domain.content.ChatMail; -import dev.struchkov.godfather.simple.domain.BoxAnswer; -import dev.struchkov.godfather.simple.domain.unit.AnswerText; -import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment; -import dev.struchkov.godfather.telegram.main.core.util.Attachments; -import dev.struchkov.godfather.telegram.starter.ChatUnitConfiguration; -import dev.struchkov.openai.context.GPTClient; -import dev.struchkov.openai.domain.common.GptMessage; -import dev.struchkov.openai.domain.model.gpt.GPT3Model; -import dev.struchkov.openai.domain.request.GptRequest; -import dev.struchkov.openai.domain.response.Choice; -import dev.struchkov.openai.domain.response.GptResponse; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Optional; - -import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; - -@Component -public class GroupChatGPTUnit implements ChatUnitConfiguration { - - private final GPTClient gptClient; - - public GroupChatGPTUnit( - GPTClient gptClient - ) { - this.gptClient = gptClient; - } - - @Unit(value = UnitName.PROMPT, main = true) - public AnswerText prompt() { - return AnswerText.builder() - .triggerCheck( - mail -> { - final List attachments = mail.getAttachments(); - final Optional optCommand = Attachments.findFirstCommand(attachments); - if (optCommand.isPresent()) { - final CommandAttachment command = optCommand.get(); - return Cmd.GPT.equals(command.getCommandType()); - } - return false; - } - ) - .answer( - mail -> { - final CommandAttachment promptCommand = Attachments.findFirstCommand(mail.getAttachments()).get(); - final Optional optPrompt = promptCommand.getArg(); - if (optPrompt.isPresent()) { - final String prompt = optPrompt.get(); - final GptResponse gptResponse = gptClient.execute( - GptRequest.builder() - .model(GPT3Model.GPT_3_5_TURBO) - .message(GptMessage.fromUser(prompt)) - .build() - ); - final List choices = gptResponse.getChoices(); - return boxAnswer(choices.get(choices.size() - 1).getMessage().getContent()); - } - return BoxAnswer.builder().build(); - } - ) - .build(); - } - -} +//package dev.struchkov.example.bot.unit; +// +//import dev.struchkov.example.bot.util.Cmd; +//import dev.struchkov.example.bot.util.UnitName; +//import dev.struchkov.godfather.main.domain.annotation.Unit; +//import dev.struchkov.godfather.main.domain.content.Attachment; +//import dev.struchkov.godfather.main.domain.content.ChatMail; +//import dev.struchkov.godfather.simple.domain.BoxAnswer; +//import dev.struchkov.godfather.simple.domain.unit.AnswerText; +//import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment; +//import dev.struchkov.godfather.telegram.main.core.util.Attachments; +//import dev.struchkov.godfather.telegram.starter.ChatUnitConfiguration; +//import dev.struchkov.openai.context.GPTClient; +//import dev.struchkov.openai.domain.common.GptMessage; +//import dev.struchkov.openai.domain.model.gpt.GPT3Model; +//import dev.struchkov.openai.domain.request.GptRequest; +//import dev.struchkov.openai.domain.response.Choice; +//import dev.struchkov.openai.domain.response.GptResponse; +//import org.springframework.stereotype.Component; +// +//import java.util.List; +//import java.util.Optional; +// +//import static dev.struchkov.godfather.simple.domain.BoxAnswer.boxAnswer; +// +//@Component +//public class GroupChatGPTUnit implements ChatUnitConfiguration { +// +// private final GPTClient gptClient; +// +// public GroupChatGPTUnit( +// GPTClient gptClient +// ) { +// this.gptClient = gptClient; +// } +// +// @Unit(value = UnitName.PROMPT, main = true) +// public AnswerText prompt() { +// return AnswerText.builder() +// .triggerCheck( +// mail -> { +// final List attachments = mail.getAttachments(); +// final Optional optCommand = Attachments.findFirstCommand(attachments); +// if (optCommand.isPresent()) { +// final CommandAttachment command = optCommand.get(); +// return Cmd.GPT.equals(command.getCommandType()); +// } +// return false; +// } +// ) +// .answer( +// mail -> { +// final CommandAttachment promptCommand = Attachments.findFirstCommand(mail.getAttachments()).get(); +// final Optional optPrompt = promptCommand.getArg(); +// if (optPrompt.isPresent()) { +// final String prompt = optPrompt.get(); +// final GptResponse gptResponse = gptClient.execute( +// GptRequest.builder() +// .model(GPT3Model.GPT_3_5_TURBO) +// .message(GptMessage.fromUser(prompt)) +// .build() +// ); +// final List choices = gptResponse.getChoices(); +// return boxAnswer(choices.get(choices.size() - 1).getMessage().getContent()); +// } +// return BoxAnswer.builder().build(); +// } +// ) +// .build(); +// } +// +//}