From e0c2542e1da03dd192239fb374ed41d0900b9be5 Mon Sep 17 00:00:00 2001 From: minwoo0419 Date: Mon, 19 Aug 2024 23:05:21 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20#120=20=ED=94=84=EB=A1=AC=ED=94=84?= =?UTF-8?q?=ED=8C=85=EC=97=90=20=EC=B6=94=EA=B0=80=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/TestController.java | 20 ++++++++++++++++--- .../server/service/openAi/OpenAiService.java | 15 ++++++++++---- .../service/question/QuestionService.java | 7 ++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/telepigeon/server/controller/TestController.java b/src/main/java/com/telepigeon/server/controller/TestController.java index 9557f71..e8a0aba 100644 --- a/src/main/java/com/telepigeon/server/controller/TestController.java +++ b/src/main/java/com/telepigeon/server/controller/TestController.java @@ -3,9 +3,12 @@ import com.telepigeon.server.domain.Token; import com.telepigeon.server.dto.TestDto; import com.telepigeon.server.dto.auth.response.JwtTokensDto; +import com.telepigeon.server.dto.naverCloud.ConfidenceDto; +import com.telepigeon.server.dto.naverCloud.request.ConfidenceCreateDto; import com.telepigeon.server.exception.code.BusinessErrorCode; import com.telepigeon.server.exception.BusinessException; import com.telepigeon.server.service.auth.TokenSaver; +import com.telepigeon.server.service.external.NaverCloudService; import com.telepigeon.server.service.openAi.OpenAiService; import com.telepigeon.server.utils.JwtUtil; import lombok.RequiredArgsConstructor; @@ -22,6 +25,7 @@ public class TestController { private final JwtUtil jwtUtil; private final TokenSaver tokenSaver; private final OpenAiService openAiService; + private final NaverCloudService naverCloudService; @GetMapping("/test") public String test() { @@ -55,11 +59,21 @@ public ResponseEntity generateToken(@PathVariable Long userId) { return ResponseEntity.ok(tokens); } - @GetMapping("test/open-ai") + @GetMapping("/test/open-ai") public ResponseEntity testOpenAi( @RequestParam String relation, - @RequestParam String keyword + @RequestParam String keyword, + @RequestParam(required = false) String gender, + @RequestParam(required = false) String ageRange, + @RequestParam boolean easyMode ) { - return ResponseEntity.ok(openAiService.createQuestion(relation, keyword)); + return ResponseEntity.ok(openAiService.createQuestion(relation, keyword, gender, ageRange, easyMode)); + } + + @GetMapping("/test/emotion") + public ResponseEntity testEmotion( + @RequestBody ConfidenceCreateDto text + ) { + return ResponseEntity.ok(naverCloudService.getConfidence(text)); } } diff --git a/src/main/java/com/telepigeon/server/service/openAi/OpenAiService.java b/src/main/java/com/telepigeon/server/service/openAi/OpenAiService.java index 80ef248..cb22bf3 100644 --- a/src/main/java/com/telepigeon/server/service/openAi/OpenAiService.java +++ b/src/main/java/com/telepigeon/server/service/openAi/OpenAiService.java @@ -31,9 +31,12 @@ public class OpenAiService { public String createQuestion( final String relation, - final String keyword + final String keyword, + final String gender, + final String ageRange, + final boolean easyMode ) { - QuestionCreateDto questionCreateDto = QuestionCreateDto.of(model, createPrompt(relation, keyword)); + QuestionCreateDto questionCreateDto = QuestionCreateDto.of(model, createPrompt(relation, keyword, gender, ageRange, easyMode)); RestClient restClient = RestClient.create(); OpenAiResponseDto response = restClient.post() .uri(url) @@ -53,7 +56,10 @@ public String createQuestion( private List createPrompt( final String relation, - final String keyword + final String keyword, + final String gender, + final String ageRange, + final boolean easyMode ) { List messages = new ArrayList<>(); //프롬프팅은 같이 찾아보면서 해야 할 것 같음. 좀 오락가락하는 경향이 많음 @@ -65,7 +71,8 @@ private List createPrompt( assistantContent)); messages.add(MessageDto.of( "user", - "역할은 " + relation + "이고, 주제는 " + keyword + "이야. 만들어 줘.")); + "'역할' 은 '" + relation + "' 이고, '주제' 는 '" + keyword + "' 이야. '연령대' 는 '" + ageRange + "' 이고, '성별' 은 '" + gender + + "'이고, 마지막으로 '쉬운 사용 모드' 는 '" + easyMode + "' 이야. 만들어 줘.")); return messages; } } \ No newline at end of file diff --git a/src/main/java/com/telepigeon/server/service/question/QuestionService.java b/src/main/java/com/telepigeon/server/service/question/QuestionService.java index 1de524b..5d5b87d 100644 --- a/src/main/java/com/telepigeon/server/service/question/QuestionService.java +++ b/src/main/java/com/telepigeon/server/service/question/QuestionService.java @@ -58,9 +58,14 @@ public Question create(final Profile profile){ } String relation = receiver.getRelation() == null ? "지인" : receiver.getRelation().getContent(); String keyword = getRandomKeyword(profile); + String gender = receiver.getGender() == null ? "-" : receiver.getGender().getContent(); + String ageRange = receiver.getAgeRange() == null ? "-" : receiver.getAgeRange().getContent(); String content = openAiService.createQuestion( relation, - keyword + keyword, + gender, + ageRange, + receiver.isEasyMode() ); Question question = questionSaver.create(Question.create( keyword,