-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
10 deletions.
There are no files selected for viewing
21 changes: 11 additions & 10 deletions
21
src/main/java/com/project/oof/gpt/controller/ChatGPTController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
package com.project.oof.gpt.controller; | ||
|
||
import com.project.oof.gpt.dto.MessageDto; | ||
import com.project.oof.gpt.service.ChatGPTService; | ||
import com.project.oof.storage.service.ChatHistoryService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(value = "/api") | ||
public class ChatGPTController { | ||
private final ChatHistoryService chatHistoryService; | ||
|
||
private final ChatGPTService chatGPTService; | ||
|
||
@PostMapping("/translate") | ||
public ResponseEntity<String> selectPrompt(@RequestBody String message) { | ||
String result = chatGPTService.translateMessage(message); | ||
public ResponseEntity<MessageDto> selectPrompt(@RequestBody MessageDto request) { | ||
MessageDto result = chatGPTService.translateMessage(request.message()); | ||
return new ResponseEntity<>(result, HttpStatus.OK); | ||
} | ||
|
||
@PostMapping("/refresh") | ||
public ResponseEntity<String> refresh() { | ||
String result = chatGPTService.refreshResult(); | ||
public ResponseEntity<MessageDto> refresh() { | ||
MessageDto result = chatGPTService.refreshResult(); | ||
return new ResponseEntity<>(result, HttpStatus.OK); | ||
} | ||
|
||
@PostMapping("/clear") | ||
public ResponseEntity<String> clearChatHistory() { | ||
chatHistoryService.clearChatHistory(); // 대화 기록 초기화 | ||
return ResponseEntity.ok("Chat history cleared."); | ||
@GetMapping() | ||
public ResponseEntity<List<String>> getAnswers() { | ||
return new ResponseEntity<>(chatGPTService.getAnswers(), HttpStatus.OK); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.project.oof.gpt.dto; | ||
|
||
public record MessageDto ( | ||
String message | ||
){ | ||
public static MessageDto of(String message) { | ||
return new MessageDto(message); | ||
} | ||
} |