Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
Expand Down Expand Up @@ -48,7 +49,13 @@ public ContentListResponse saveRecommendContents(String memberId, LocalDate date
DiaryAnalysis analysis =
diaryAnalysisService.getDiaryAnalysisByMemberIdAndDate(memberId, date);
Member member = memberService.getMemberById(memberId);
List<Content> recommendedContents = getRecommendContentsByAnalysis(analysis, member);

String prompt = "이 일기의 감정에 정신적으로 도움이 되는 메타데이터를 10개 추천해줘";
prompt = recommendService.createPrompt(
analysis.getEmotions(), analysis.getEvent(), member, prompt
);
List<Content> recommendedContents
= getRecommendContentsByAnalysis(analysis, member, prompt);

List<Content> savedContents = saveOrUpdateContents(recommendedContents);
diaryAnalysisService.saveRecommendContents(analysis, savedContents);
Expand Down Expand Up @@ -76,7 +83,12 @@ public ContentListResponse saveReRecommendContents(
Member member = memberService.getMemberById(memberId);
List<String> recommendedUrls = extractRecommendContentUrls(analysis);

List<Content> recommendedContents = getRecommendContentsByAnalysis(analysis, member);
String prompt = "지금 사용자의 상태에 따라 관련되거나 정신적으로 도움 되는 콘텐츠 10개를 추천해줘";
prompt = recommendService.createPrompt(
analysis.getEmotions(), analysis.getEvent(), member, prompt
);
List<Content> recommendedContents
= getRecommendContentsByAnalysis(analysis, member, prompt);
// TODO: 추후에 feedback을 통해서 재추천 컨텐츠를 가져와야 함

List<Content> savedContents = saveOrUpdateContents(recommendedContents);
Expand Down Expand Up @@ -119,12 +131,18 @@ public void unlikeContent(String memberId, String contentId) {
}
}

private List<Content> getRecommendContentsByAnalysis(DiaryAnalysis analysis, Member member) {

String prompt = recommendService.createPrompt(
analysis.getEmotions(), analysis.getEvent(), member);

List<String> videoIds = lambdaService.getRecommendations(prompt);
private List<Content> getRecommendContentsByAnalysis(
DiaryAnalysis analysis, Member member, String prompt
) {
List<String> videoIds = new ArrayList<>();
int lambdaCnt = 0;
while (lambdaCnt < 5) {
videoIds = lambdaService.getRecommendations(prompt);
if (!videoIds.isEmpty()) {
break;
}
lambdaCnt++;
}

try {
YouTubeResponse youTubeResponse = recommendService.getYoutubeInfo(videoIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ public class RecommendService {
@Value("${youtube.api.key}")
private String apiKey;

public String createPrompt(List<String> emotions, String event, Member member) {
public String createPrompt(List<String> emotions, String event, Member member, String prompt) {

String emotionString = String.join(", ", emotions);

return String.format(
"%s 감정을 가진 나이가 %d인 %s이 쓴 일기 내용은 %s야. 이 일기의 감정에 정신적으로 도움이 되는 메타데이터를 10개 추천해줘",
"%s 감정을 가진 나이가 %d인 %s이 쓴 일기 내용은 \"%s\"야. %s",
emotionString,
AgeConverter.convertDateToAge(member.getBirthDate()),
member.getJob(),
event
event,
prompt
);
}

Expand Down
Loading