Skip to content

Commit

Permalink
Merge pull request #116 from pre-Q/fix/#115-chatgpt-response-after-pr…
Browse files Browse the repository at this point in the history
…ocessing

Fix/#115 chatgpt response after processing
  • Loading branch information
Lightieey authored Sep 18, 2023
2 parents 93c264d + 9be8a85 commit 9fbf00e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/main/java/kr/co/preq/domain/preq/service/OpenAIService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ public class OpenAIService {

public List<String> generateQuestions(String question, String answer, List<SessionDto> sessionDtoList) {
List<Message> 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---------");
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/kr/co/preq/domain/preq/service/PreqService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public PreqAndKeywordResponseDto createPreqAndKeyword(Long applicationChildId) {
.findAllByApplicationChildIdOrderByParentIdAscNullsFirstCategoryIdAsc(applicationChildId);

List<SessionDto> parentApplicationChilds = allApplicationChilds
.subList(0, allApplicationChilds.size()-1) // remove first element (=self)
// .subList(0, allApplicationChilds.size()-1) // remove first element (=self)
.stream().map((a) -> {
List<Preq> preqList = preqRepository.findPreqsByApplicationChildIdAndIsDeleted(a.getId(), false);
return new SessionDto(a.getQuestion(), a.getAnswer(), preqList.stream().map((p) -> p.getQuestion()).collect(
Expand All @@ -64,13 +64,14 @@ public PreqAndKeywordResponseDto createPreqAndKeyword(Long applicationChildId) {
// manufacturing chatGPT response
List<String> 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<Preq> oldPreqList = preqRepository.findPreqsByApplicationChildIdAndIsDeleted(applicationChildId, false);
Expand Down

0 comments on commit 9fbf00e

Please sign in to comment.