From f383248189337f866af2e4442878b5b968f84650 Mon Sep 17 00:00:00 2001 From: DDonghyeo Date: Fri, 12 Jan 2024 02:15:05 +0900 Subject: [PATCH] feat: GPT User Advice --- .../yourprotein/controller/GptController.java | 18 ++++++++++++++---- .../gpt/controller/ChatGPTRestController.java | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/kim3ho1/yourprotein/controller/GptController.java b/src/main/java/com/kim3ho1/yourprotein/controller/GptController.java index b73a1fa..9a535ef 100644 --- a/src/main/java/com/kim3ho1/yourprotein/controller/GptController.java +++ b/src/main/java/com/kim3ho1/yourprotein/controller/GptController.java @@ -1,5 +1,8 @@ package com.kim3ho1.yourprotein.controller; +import com.kim3ho1.yourprotein.gpt.dto.request.GPTCompletionChatRequest; +import com.kim3ho1.yourprotein.gpt.dto.response.CompletionChatResponse; +import com.kim3ho1.yourprotein.gpt.service.GPTChatRestService; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -16,13 +19,20 @@ @RequestMapping("/gpt") public class GptController { private final GptService gptService; + + private final GPTChatRestService gptChatRestService; + @GetMapping("/total") - public ResponseEntity totalAdvice() { - return ResponseEntity.ok(gptService.totalAdvice()); + public ResponseEntity totalAdvice() { + return ResponseEntity.ok( + gptChatRestService.completionChat(new GPTCompletionChatRequest("gpt-3.5-turbo", "user", gptService.totalAdvice(), 5000)) + ); } @GetMapping("/plan") - public ResponseEntity planAdvice() { - return ResponseEntity.ok(gptService.planAdvice()); + public ResponseEntity planAdvice() { + return ResponseEntity.ok( + gptChatRestService.completionChat(new GPTCompletionChatRequest("gpt-3.5-turbo", "user", gptService.planAdvice(), 5000)) + ); } } diff --git a/src/main/java/com/kim3ho1/yourprotein/gpt/controller/ChatGPTRestController.java b/src/main/java/com/kim3ho1/yourprotein/gpt/controller/ChatGPTRestController.java index 0ce4d18..e6fe298 100644 --- a/src/main/java/com/kim3ho1/yourprotein/gpt/controller/ChatGPTRestController.java +++ b/src/main/java/com/kim3ho1/yourprotein/gpt/controller/ChatGPTRestController.java @@ -6,6 +6,7 @@ import com.kim3ho1.yourprotein.gpt.dto.response.CompletionChatResponse; import com.kim3ho1.yourprotein.gpt.dto.response.CompletionResponse; import com.kim3ho1.yourprotein.gpt.service.GPTChatRestService; +import com.theokanning.openai.completion.chat.ChatMessage; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -23,7 +24,7 @@ public class ChatGPTRestController { @PostMapping("/completion/chat") public CompletionChatResponse chat(final @RequestBody HashMap prompt) { - return completionChat(new GPTCompletionChatRequest("gpt-3.5-turbo", "user", prompt.get("prompt"), 1000)); + return completionChat(new GPTCompletionChatRequest("gpt-3.5-turbo", "user", prompt.get("prompt"), 5000)); }