|
9 | 9 | import java.util.function.Function;
|
10 | 10 | import java.util.stream.Collectors;
|
11 | 11 | import lombok.RequiredArgsConstructor;
|
| 12 | +import org.checkerframework.checker.units.qual.A; |
12 | 13 | import org.springframework.data.mongodb.core.MongoTemplate;
|
13 | 14 | import org.springframework.data.mongodb.core.query.Criteria;
|
14 | 15 | import org.springframework.data.mongodb.core.query.Query;
|
@@ -48,7 +49,13 @@ public ContentListResponse saveRecommendContents(String memberId, LocalDate date
|
48 | 49 | DiaryAnalysis analysis =
|
49 | 50 | diaryAnalysisService.getDiaryAnalysisByMemberIdAndDate(memberId, date);
|
50 | 51 | Member member = memberService.getMemberById(memberId);
|
51 |
| - List<Content> recommendedContents = getRecommendContentsByAnalysis(analysis, member); |
| 52 | + |
| 53 | + String prompt = "이 일기의 감정에 정신적으로 도움이 되는 메타데이터를 10개 추천해줘"; |
| 54 | + prompt = recommendService.createPrompt( |
| 55 | + analysis.getEmotions(), analysis.getEvent(), member, prompt |
| 56 | + ); |
| 57 | + List<Content> recommendedContents |
| 58 | + = getRecommendContentsByAnalysis(analysis, member, prompt); |
52 | 59 |
|
53 | 60 | List<Content> savedContents = saveOrUpdateContents(recommendedContents);
|
54 | 61 | diaryAnalysisService.saveRecommendContents(analysis, savedContents);
|
@@ -76,7 +83,12 @@ public ContentListResponse saveReRecommendContents(
|
76 | 83 | Member member = memberService.getMemberById(memberId);
|
77 | 84 | List<String> recommendedUrls = extractRecommendContentUrls(analysis);
|
78 | 85 |
|
79 |
| - List<Content> recommendedContents = getRecommendContentsByAnalysis(analysis, member); |
| 86 | + String prompt = "지금 사용자의 상태에 따라 관련되거나 정신적으로 도움 되는 콘텐츠 10개를 추천해줘"; |
| 87 | + prompt = recommendService.createPrompt( |
| 88 | + analysis.getEmotions(), analysis.getEvent(), member, prompt |
| 89 | + ); |
| 90 | + List<Content> recommendedContents |
| 91 | + = getRecommendContentsByAnalysis(analysis, member, prompt); |
80 | 92 | // TODO: 추후에 feedback을 통해서 재추천 컨텐츠를 가져와야 함
|
81 | 93 |
|
82 | 94 | List<Content> savedContents = saveOrUpdateContents(recommendedContents);
|
@@ -119,12 +131,18 @@ public void unlikeContent(String memberId, String contentId) {
|
119 | 131 | }
|
120 | 132 | }
|
121 | 133 |
|
122 |
| - private List<Content> getRecommendContentsByAnalysis(DiaryAnalysis analysis, Member member) { |
123 |
| - |
124 |
| - String prompt = recommendService.createPrompt( |
125 |
| - analysis.getEmotions(), analysis.getEvent(), member); |
126 |
| - |
127 |
| - List<String> videoIds = lambdaService.getRecommendations(prompt); |
| 134 | + private List<Content> getRecommendContentsByAnalysis( |
| 135 | + DiaryAnalysis analysis, Member member, String prompt |
| 136 | + ) { |
| 137 | + List<String> videoIds = new ArrayList<>(); |
| 138 | + int lambdaCnt = 0; |
| 139 | + while (lambdaCnt < 5) { |
| 140 | + videoIds = lambdaService.getRecommendations(prompt); |
| 141 | + if (!videoIds.isEmpty()) { |
| 142 | + break; |
| 143 | + } |
| 144 | + lambdaCnt++; |
| 145 | + } |
128 | 146 |
|
129 | 147 | try {
|
130 | 148 | YouTubeResponse youTubeResponse = recommendService.getYoutubeInfo(videoIds);
|
|
0 commit comments