[SpringBoot] springboot로 chat-gpt 이용해보기

WooHyunLEE·2023년 9월 7일
0

초기 세팅


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

profile
이우현의 개발 블로그입니다.

0개의 댓글