diff --git a/src/main/java/kr/co/preq/domain/preq/service/OpenAIService.java b/src/main/java/kr/co/preq/domain/preq/service/OpenAIService.java index d22029f..d8e8e65 100644 --- a/src/main/java/kr/co/preq/domain/preq/service/OpenAIService.java +++ b/src/main/java/kr/co/preq/domain/preq/service/OpenAIService.java @@ -46,13 +46,16 @@ public class OpenAIService { public List generateQuestions(String question, String answer, List sessionDtoList) { List sessions = new ArrayList<>(); - sessionDtoList.forEach((a) -> { - sessions.add(new Message("user", makeUserPrompt(a.getQuestion(), a.getAnswer()))); - sessions.add(new Message("assistant", a.getPreqList().toString())); + + for (int i = 0; i < sessionDtoList.size() - 1; i++) { + sessions.add(new Message("user", makeUserPrompt(sessionDtoList.get(i).getQuestion(), + sessionDtoList.get(i).getAnswer()))); + sessions.add(new Message("assistant", sessionDtoList.get(i+1).getQuestion())); System.out.println("session--------"); - System.out.println(makeUserPrompt(a.getQuestion(), a.getAnswer())); - System.out.println(a.getPreqList().toString()); - }); + System.out.println(makeUserPrompt(sessionDtoList.get(i).getQuestion(), + sessionDtoList.get(i).getAnswer())); + System.out.println(sessionDtoList.get(i+1).getQuestion()); + } String prompt = makeUserPrompt(question, answer); System.out.println("new---------"); diff --git a/src/main/java/kr/co/preq/domain/preq/service/PreqService.java b/src/main/java/kr/co/preq/domain/preq/service/PreqService.java index 7108d15..62dc8bc 100644 --- a/src/main/java/kr/co/preq/domain/preq/service/PreqService.java +++ b/src/main/java/kr/co/preq/domain/preq/service/PreqService.java @@ -51,7 +51,7 @@ public PreqAndKeywordResponseDto createPreqAndKeyword(Long applicationChildId) { .findAllByApplicationChildIdOrderByParentIdAscNullsFirstCategoryIdAsc(applicationChildId); List parentApplicationChilds = allApplicationChilds - .subList(0, allApplicationChilds.size()-1) // remove first element (=self) + // .subList(0, allApplicationChilds.size()-1) // remove first element (=self) .stream().map((a) -> { List preqList = preqRepository.findPreqsByApplicationChildIdAndIsDeleted(a.getId(), false); return new SessionDto(a.getQuestion(), a.getAnswer(), preqList.stream().map((p) -> p.getQuestion()).collect( @@ -64,13 +64,14 @@ public PreqAndKeywordResponseDto createPreqAndKeyword(Long applicationChildId) { // manufacturing chatGPT response List cutQuestions = new ArrayList<>(); questions.forEach(q -> { - if (q.contains(": ")) { - String[] str = q.split(": "); - cutQuestions.add(str[1]); - } else { - cutQuestions.add(q); + if (q.contains(": ")) { + String[] str = q.split(": "); + cutQuestions.add(str[1].replaceAll("[^ㄱ-ㅎㅏ-ㅣ가-힣a-zA-Z0-9,.? ]", "")); + } else { + cutQuestions.add(q.replaceAll("[^ㄱ-ㅎㅏ-ㅣ가-힣a-zA-Z0-9,.? ]", "")); + } } - }); + ); // soft delete old preQuestions List oldPreqList = preqRepository.findPreqsByApplicationChildIdAndIsDeleted(applicationChildId, false);