초기 세팅
build.gralde
// chat-gpt
implementation 'io.github.flashvayne:chatgpt-spring-boot-starter:1.0.4'
application.yml
chatgpt:
{api-key}
ChatService
@Service
@RequiredArgsConstructor
public class ChatService {
private final ChatgptService chatgptService;
public String getChatResponse(String prompt) {
return chatgptService.sendMessage(prompt);
}
}
GptController
@RequiredArgsConstructor
@RestController
@Slf4j
@RequestMapping("/api/v1/chat-gpt")
public class GptController {
private final ChatService chatService;
private final ChatgptService chatgptService;
//chat-gpt 와 간단한 채팅 서비스 소스
@PostMapping("")
public String test(@RequestBody String question){
return chatService.getChatResponse(question);
}
}
참고
https://yjkim-dev.tistory.com/56