Skip to content

Commit

Permalink
fix: 여러 개의 quest를 한 번에 저장하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
koosco committed Dec 7, 2024
1 parent d0144e6 commit f9a47fb
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

@Builder
public record CreateVectorDto(
Long memberId, String memberName, List<String> interestJobs, String goal, String quest) {}
Long memberId,
String memberName,
List<String> interestJobs,
List<String> goals,
List<String> quests) {}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public RecommendQuestListResponseDto recommendQuest(Long memberId, MemberGoal me
Map.of(
"job",
convertListToString(myVector.interestJobs()),
"goal",
"goals",
memberGoal.getGoal().getTitle(),
"myQuest",
convertListToString(myVector.quests()),
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/groom/orbit/ai/app/pinecone/PineconeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void save(CreateVectorDto dto) {
dto.memberId(),
dto.memberName(),
dto.interestJobs(),
dto.goal(),
dto.quest()));
dto.goals(),
dto.quests()));

saveVector(vector, dto.memberId());
}
Expand Down Expand Up @@ -180,15 +180,18 @@ private Vector mergeVector(Vector existingVector, CreateVectorDto dto) {
dto.interestJobs() != null && !dto.interestJobs().isEmpty()
? dto.interestJobs()
: existingVector.interestJobs())
.goals(addUniqueValue(existingVector.goals(), dto.goal()))
.quests(addUniqueValue(existingVector.quests(), dto.quest()))
.goals(addUniqueValue(existingVector.goals(), dto.goals()))
.quests(addUniqueValue(existingVector.quests(), dto.quests()))
.build();
}

private List<String> addUniqueValue(List<String> existingList, String newValue) {
if (newValue != null && !existingList.contains(newValue)) {
existingList.add(newValue);
}
private List<String> addUniqueValue(List<String> existingList, List<String> newValues) {
newValues.forEach(
newValue -> {
if (newValue != null && !existingList.contains(newValue)) {
existingList.add(newValue);
}
});
return existingList;
}

Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/groom/orbit/goal/app/MemberGoalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ public GetMemberGoalResponseDto createGoal(Long memberId, MemberGoalRequestDto d
int memberGoalSize = memberGoalRepository.findAllByMemberIdAndIsCompleteFalse(memberId).size();

MemberGoal memberGoal = MemberGoal.create(member, goal, memberGoalSize);
dto.quests().forEach(quest -> Quest.copyQuest(quest.title(), memberGoal));
List<String> goalTitles = List.of(memberGoal.getTitle());
List<String> questTitles =
dto.quests().stream()
.map(quest -> Quest.copyQuest(quest.title(), memberGoal))
.map(Quest::getTitle)
.toList();

MemberGoal savedMemberGoal = memberGoalRepository.save(memberGoal);
saveVector(memberId, goal);
saveVector(memberId, goalTitles, questTitles);

List<GetQuestResponseDto> questDtos =
savedMemberGoal.getQuests().stream()
Expand All @@ -112,20 +118,20 @@ public GetMemberGoalResponseDto createGoal(Long memberId, MemberGoalRequestDto d
questDtos);
}

private void saveVector(Long memberId, Goal goal) {
private void saveVector(Long memberId, List<String> goalTitles, List<String> questTitles) {
CreateVectorDto vectorDto =
CreateVectorDto.builder().memberId(memberId).goal(goal.getTitle()).build();
CreateVectorDto.builder().memberId(memberId).goals(goalTitles).quests(questTitles).build();
vectorService.save(vectorDto);
}

public CommonSuccessDto updateMemberGoal(
Long memberId, Long memberGoalId, MemberGoalRequestDto dto) {
MemberGoal memberGoal = findMemberGoal(memberGoalId);
Goal goal = findGoal(dto.title(), dto.category());

memberGoal.validateMember(memberId);

updateVector(memberId, dto, memberGoal);
memberGoal.updateGoal(goal);
memberGoal.update(goal);

return new CommonSuccessDto(true);
}
Expand All @@ -134,6 +140,7 @@ private void updateVector(Long memberId, MemberGoalRequestDto dto, MemberGoal me
if (dto.title() == null) {
return;
}

UpdateVectorGoalDto updateDto =
UpdateVectorGoalDto.builder()
.memberId(memberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public String getTitle() {
return this.goal.getTitle();
}

public void updateGoal(Goal goal) {
public void update(Goal goal) {
this.goal.decreaseCount();
goal.increaseCount();
this.goal = goal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.groom.orbit.quest.app;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -61,7 +63,7 @@ public CommonSuccessDto updateQuest(Long memberId, Long questId, UpdateQuestRequ

private void saveVector(Long memberId, CreateQuestRequestDto dto) {
CreateVectorDto vectorDto =
CreateVectorDto.builder().memberId(memberId).quest(dto.title()).build();
CreateVectorDto.builder().memberId(memberId).quests(List.of(dto.title())).build();
vectorService.save(vectorDto);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public List<String> getRecommendedQuests(Long memberGoalId) {
Set<Quest> myQuests = new HashSet<>(memberGoal.getQuests());

List<MemberGoal> memberGoals =
memberGoalService.findMemberGoalsByGoalId(memberGoal.getGoal().getGoalId()); // goal 조회
memberGoalService.findMemberGoalsByGoalId(memberGoal.getGoal().getGoalId()); // goals 조회
Set<Quest> quests =
memberGoals.stream()
.map(MemberGoal::getQuests)
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/templates/goal-recommend-prompt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
category null이 아닌지 다시 한 번 확인해주세요.

## 조건2
새로운 목표의 종결 어미는 "~하기"여야 합니다.

## 조건3
- 해당 목표를 왜 추천했는지에 대한 설명(descriptions)을 같이 작성해주세요.
- descriptions에 나오는 내용은 "~요" 어미로 끝나야 해요.
- descriptions의 개수는 2 ~ 3개를 반드시 포함해요.
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/templates/quest-recommend-prompt.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 상황
저의 관심 직무는 {job}입니다. 저의 목표는 {goal}입니다.
저의 관심 직무는 {job}입니다. 저의 목표는 {goals}입니다.

- {myQuest}는 제가 여태까지 작성했던 목표입니다.
- {questList}에 포함된 퀘스트 중 제가 아직 수행하지 않은 퀘스트을(를) 선택하려고 합니다.
- {questList}에 포함된 퀘스트 중 저의 직무, 목표와 관련성이 가장 높은 퀘스트를 *세 개* 선택해주세요.
- {questList}에서 선택한 퀘스트가 {job}, {goal}과 관련이 있는지 판단해주세요.
- 만약 선택된 퀘스트가 {job} 또는 {goal} 과 관련이 없다면, {job}과 {goal}, {myQuest}을 기준으로 새로운 퀘스트를 만들어주세요.
- {questList}에서 선택한 퀘스트가 {job}, {goals}과 관련이 있는지 판단해주세요.
- 만약 선택된 퀘스트가 {job} 또는 {goals} 과 관련이 없다면, {job}과 {goal}, {myQuest}을 기준으로 새로운 퀘스트를 만들어주세요.
- 새로운 퀘스트는 {myQuest}에 해당되면 안됩니다. 해당되지 않는다는 것은 비슷한 내용도 포함됩니다.

- 퀘스트는 {goal}을 성취하기 위한 더 작은 목표입니다.
- 퀘스트는 {goals}을 성취하기 위한 더 작은 목표입니다.
예를 들어,
1)
- input
Expand Down

0 comments on commit f9a47fb

Please sign in to comment.