-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat][Recommendation] gemini 통해서 책 추천받기 #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @AlphaBs, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 PR은 Gemini AI를 활용한 도서 추천 시스템을 도입합니다. 사용자 온보딩 데이터를 기반으로 개인화된 도서 추천을 생성하고, 이를 API를 통해 제공하며, 추천된 도서 목록을 저장하고 조회할 수 있는 기능을 추가합니다. 기존 크롤링 로직에서 책 검색 및 저장 부분을 Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Test Results103 files 103 suites 22s ⏱️ Results for commit bcb5109. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
이 PR은 Gemini를 사용하여 도서 추천 기능을 추가하는 것을 목표로 합니다. 전반적인 코드 구조는 컨트롤러, 서비스, 리포지토리로 잘 분리되어 있으며 명확합니다. 도서 검색 로직을 AladinService로 리팩토링한 점도 좋은 개선입니다. 코드 품질을 더욱 향상시키기 위해 엔티티 설계, 성능, API 사용 패턴과 관련하여 몇 가지 제안 사항을 남깁니다.
src/main/java/book/book/recommendation/entity/MemberBookRecommendation.java
Outdated
Show resolved
Hide resolved
src/main/java/book/book/recommendation/service/GeminiBookRecommendationProvider.java
Show resolved
Hide resolved
src/main/java/book/book/recommendation/service/RecommendationService.java
Show resolved
Hide resolved
src/main/java/book/book/recommendation/service/RecommendationService.java
Outdated
Show resolved
Hide resolved
src/main/java/book/book/recommendation/service/RecommendationService.java
Show resolved
Hide resolved
| return geminiSdkClient.generateContent(request); | ||
| } | ||
|
|
||
| private GeminiRequest<BookRecommendationResponses> createRequest(OnboardingResultResponse onboarding) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/main/java/book/book/recommendation/service/RecommendationService.java
Show resolved
Hide resolved
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
Gemini를 이용한 도서 추천 기능 추가 PR 잘 보았습니다. 새로운 기능을 추가하면서 책임에 따라 서비스와 컨트롤러를 분리하고, 기존의 책 검색 및 저장 로직을 AladinService로 중앙화하는 리팩토링을 진행한 점이 인상적입니다. 코드 구조가 전반적으로 잘 잡혀있으나, API 응답 설계, 동시성 처리, 프롬프트 생성 및 예외 처리 등 몇 가지 개선할 수 있는 부분들이 보여 의견을 남깁니다.
| private final GeminiBookRecommendationProvider geminiBookRecommendationProvider; | ||
| private final AladinService aladinService; | ||
|
|
||
| @DistributedLock(key = "'recommendation_lock:' + #member.id", waitTime = 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gemini API 호출을 포함하는 generateBookRecommendationForMember 메서드 전체에 @DistributedLock이 적용되어 있습니다. API 호출은 시간이 오래 걸릴 수 있는데, 기본 leaseTime인 10초를 초과할 경우 락이 조기 해제될 위험이 있습니다. 이 경우 다른 스레드가 진입하여 추천 컬렉션을 중복으로 저장하는 등의 경쟁 상태(race condition)가 발생할 수 있습니다. leaseTime을 API 타임아웃보다 충분히 긴 시간으로 명시적으로 설정하는 것을 권장합니다.
| @DistributedLock(key = "'recommendation_lock:' + #member.id", waitTime = 0) | |
| @DistributedLock(key = "'recommendation_lock:' + #member.id", waitTime = 0, leaseTime = 30) |
| private final MemberRepository memberRepository; | ||
|
|
||
| @GetMapping("/members/{memberId}/books/refresh") | ||
| public List<Book> refreshBooksForMember(@PathVariable Long memberId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
|
|
||
| @GetMapping("/members/{memberId}/books") | ||
| public List<Book> getBooksForMember(@PathVariable Long memberId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| onboarding.favoriteAuthor(), | ||
| onboarding.favoriteBook()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gemini 프롬프트 생성 시 onboarding.favoriteAuthor()와 onboarding.favoriteBook()이 null이거나 비어있을 경우, 문자열 "null"이 프롬프트에 포함됩니다. 이는 모델에게 혼란을 줄 수 있습니다. keywords처럼 isBlank() 체크와 함께 "없음"과 같은 명확한 플레이스홀더를 사용하는 것이 좋습니다.
| onboarding.favoriteAuthor(), | |
| onboarding.favoriteBook()); | |
| (onboarding.favoriteAuthor() == null || onboarding.favoriteAuthor().isBlank()) ? "없음" : onboarding.favoriteAuthor(), | |
| (onboarding.favoriteBook() == null || onboarding.favoriteBook().isBlank()) ? "없음" : onboarding.favoriteBook()); |
| Book book = bookService.saveBooksParallel(searchResponse.getItem()).get(0); | ||
| return Optional.of(book); | ||
| } catch (Exception e) { | ||
| log.error("책 검색 중 오류 발생: {}, {}", e, bookTitle); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
로깅 포맷이 잘못 사용되었습니다. log.error("..., {}, {}", e, bookTitle) 형식은 스택 트레이스를 출력하지 않고 예외 객체의 toString() 값만 로깅하게 됩니다. 정확한 오류 분석을 위해 스택 트레이스가 로깅되도록 예외 객체는 항상 마지막 인자로 전달해야 합니다. 또한, 메시지에 사용된 인수의 순서도 실제 의도와 다른 것 같습니다.
| log.error("책 검색 중 오류 발생: {}, {}", e, bookTitle); | |
| log.error("책 검색 중 오류 발생: {}", bookTitle, e); |
🌻 테스트 커버리지 리포트
|

History
🚀 Major Changes & Explanations
📷 Test Image
💡 ETC