diff --git a/src/main/java/com/easylead/easylead/domain/gpt/business/GptBusiness.java b/src/main/java/com/easylead/easylead/domain/gpt/business/GptBusiness.java index 9909e7f..7c0bf02 100644 --- a/src/main/java/com/easylead/easylead/domain/gpt/business/GptBusiness.java +++ b/src/main/java/com/easylead/easylead/domain/gpt/business/GptBusiness.java @@ -25,4 +25,9 @@ public ResponseDTO getEasyToRead(String text) throws JsonProcessingException { public Flux ask(String text) throws JsonProcessingException { return gptService.askStream(text); } + + public ResponseDTO getEasyToReadCustom(String text) throws JsonProcessingException { + HttpRequest request = gptService.requestGPTCustom(text); + return gptConverter.toResponseDTO(gptService.responseGPT(request)); + } } diff --git a/src/main/java/com/easylead/easylead/domain/gpt/controller/GptController.java b/src/main/java/com/easylead/easylead/domain/gpt/controller/GptController.java index 6418deb..c7bcaa6 100644 --- a/src/main/java/com/easylead/easylead/domain/gpt/controller/GptController.java +++ b/src/main/java/com/easylead/easylead/domain/gpt/controller/GptController.java @@ -40,5 +40,12 @@ public Flux ask(Locale locale, } } + @GetMapping("/custom") + public ResponseEntity easyLeadCustom(@RequestParam String text) + throws JsonProcessingException { + return ResponseEntity.ok(gptBusiness.getEasyToReadCustom(text)); + + } + } diff --git a/src/main/java/com/easylead/easylead/domain/gpt/service/GptService.java b/src/main/java/com/easylead/easylead/domain/gpt/service/GptService.java index 8b35731..c7a59a0 100644 --- a/src/main/java/com/easylead/easylead/domain/gpt/service/GptService.java +++ b/src/main/java/com/easylead/easylead/domain/gpt/service/GptService.java @@ -32,6 +32,9 @@ public class GptService { @Value("${gpt.api_key}") private String gptApiKey; + + @Value("${gpt.api_key_custom}") + private String gptApiCustomkey; private final ObjectMapper objectMapper = new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE ); @@ -193,4 +196,29 @@ public Flux askStream(String text) throws JsonProcessingException { .bodyToFlux(String.class); return eventStream; } + + public HttpRequest requestGPTCustom(String text) throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + List messages = new ArrayList<>(); + // Assistant API 사용할지 Prompt를 변경할지 선택하기 + // 시스템 역할 설정 + messages.add(new Message(text, "user")); + + ChatGPTRequestDTO chatGptRequest = new ChatGPTRequestDTO("ft:gpt-3.5-turbo-0125:personal::9klL6p0E", messages, 0.3,false); + String input = null; + input = mapper.writeValueAsString(chatGptRequest); + System.out.println(input); + System.out.println("apikey : " + gptApiCustomkey); + + HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("https://api.openai.com/v1/chat/completions")) + .header("Content-Type", "application/json") + .header("Authorization", "Bearer " + gptApiCustomkey) + .POST(HttpRequest.BodyPublishers.ofString(input)) + .build(); + + return request; + + + } }