Skip to content

Commit

Permalink
Merge pull request #16 from easy-lead/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
oU-Ua authored Jul 14, 2024
2 parents 86030ac + 548d04c commit 8454a81
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public ResponseDTO getEasyToRead(String text) throws JsonProcessingException {
public Flux<String> 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,12 @@ public Flux<String> ask(Locale locale,
}
}

@GetMapping("/custom")
public ResponseEntity<ResponseDTO> easyLeadCustom(@RequestParam String text)
throws JsonProcessingException {
return ResponseEntity.ok(gptBusiness.getEasyToReadCustom(text));

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -193,4 +196,29 @@ public Flux<String> askStream(String text) throws JsonProcessingException {
.bodyToFlux(String.class);
return eventStream;
}

public HttpRequest requestGPTCustom(String text) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
List<Message> 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;


}
}

0 comments on commit 8454a81

Please sign in to comment.